diff --git a/.changeset/lucky-candles-melt.md b/.changeset/lucky-candles-melt.md new file mode 100644 index 0000000..ef5f324 --- /dev/null +++ b/.changeset/lucky-candles-melt.md @@ -0,0 +1,5 @@ +--- +"@matthiesenxyz/astro-gists": patch +--- + +Added new Component to get entire collections of gists (See Readme for more info) diff --git a/package/README.md b/package/README.md index d58bb7b..7fd23d5 100644 --- a/package/README.md +++ b/package/README.md @@ -73,9 +73,9 @@ GITHUB_PERSONAL_TOKEN=ghp_YOURPERSONALTOKENHERE ### Usage -#### `` +#### `` Shows a SINGLE gist from a GistCollection -This Utility is meant to display Gists as Codeblocks using ExpressiveCode for Astro instead of Scripted Elements using the default Gist method +This Utility is meant to display a single Gist as Codeblocks using ExpressiveCode for Astro instead of Scripted Elements using the default Gist method by calling the ID and Filename ```astro --- @@ -87,6 +87,18 @@ import { GetGist } from "@matthiesenxyz/astro-gists/components" /> ``` +#### `` Shows all of the Gists from a GistCollection + +This Utility is meant to display an entire collection of Gists by ID + +```astro +import { GetGistGroup } from "@matthiesenxyz/astro-gists/components" + + +``` + ## Contributing This package is structured as a monorepo: diff --git a/package/src/components/GetGistGroup.astro b/package/src/components/GetGistGroup.astro new file mode 100644 index 0000000..1c9fe03 --- /dev/null +++ b/package/src/components/GetGistGroup.astro @@ -0,0 +1,52 @@ +--- +import { getGistGroup } from "../utils" +import { GetGist } from "./index" + +export interface Props { + /** REQUIRED: Used to define the desired GitHub Gist ID */ + gistId: string; + /** OPTIONAL: Allows the user to Enable and Disable LineNumbers + * @default true + */ + showLineNumbers?: boolean; + /** OPTIONAL: Allows the user to Enable and Disable LineWrapping + * @default true + */ + wrap?: boolean; +} + +const { gistId, showLineNumbers, wrap } = Astro.props as Props; + +const SHOWLINENUMBERS = showLineNumbers ? showLineNumbers : showLineNumbers == undefined ? true : false; +const WRAP = wrap ? wrap : wrap == undefined ? true : false; + +const Gist = await getGistGroup(gistId); +const files = Gist?.files; + +const filed = Object.keys(files as object); + + + +--- +{ Gist && ( +
+ { filed.map((file) => ( +
+ +
+ ))} +
+) } + + + \ No newline at end of file diff --git a/package/src/components/index.ts b/package/src/components/index.ts index 1e4414c..888b025 100644 --- a/package/src/components/index.ts +++ b/package/src/components/index.ts @@ -1 +1,2 @@ -export { default as GetGist} from "./GetGist.astro" \ No newline at end of file +export { default as GetGist} from "./GetGist.astro" +export { default as GetGistGroup} from "./GetGistGroup.astro" \ No newline at end of file diff --git a/package/src/utils.ts b/package/src/utils.ts index e2195f3..a9ebaa0 100644 --- a/package/src/utils.ts +++ b/package/src/utils.ts @@ -26,3 +26,12 @@ export const getGistFile = async ( return null; }; +export const getGistGroup = async ( + gistId: string + ) => { +const gist = await getGist(gistId); +if (gist?.files) { + return gist ? gist : null; +} +return null; +}; \ No newline at end of file diff --git a/playground/src/pages/index.astro b/playground/src/pages/index.astro index 1fedc46..945769e 100644 --- a/playground/src/pages/index.astro +++ b/playground/src/pages/index.astro @@ -1,9 +1,13 @@ --- -import { GetGist } from "@matthiesenxyz/astro-gists/components" +import { GetGist, GetGistGroup } from "@matthiesenxyz/astro-gists/components" ---

Dev: Playground

+ + \ No newline at end of file