Merge pull request #12 from MatthiesenXYZ/dev

update
This commit is contained in:
Adam Matthiesen 2024-02-24 09:07:06 -08:00 committed by GitHub
commit 4375a0f1fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 119 additions and 9 deletions

View File

@ -0,0 +1,5 @@
---
"@matthiesenxyz/astro-gists": patch
---
Added new <GetGistGroup> Component to get entire collections of gists (See Readme for more info)

View File

@ -73,9 +73,9 @@ GITHUB_PERSONAL_TOKEN=ghp_YOURPERSONALTOKENHERE
### Usage
#### `<GetGist>`
#### `<GetGist>` 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"
/>
```
#### `<GetGistGroup>` 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"
<GetGistGroup
gistId="your-gist-id-here"
/>
```
## Contributing
This package is structured as a monorepo:

View File

@ -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 && (
<div class="gist">
{ filed.map((file) => (
<div class="gist">
<GetGist
gistId={gistId}
filename={file}
showLineNumbers={SHOWLINENUMBERS}
wrap={WRAP}
/>
</div>
))}
</div>
) }
<style>
.gist {
padding-top: 1rem;
padding-bottom: 1rem;
}
</style>

View File

@ -1 +1,2 @@
export { default as GetGist} from "./GetGist.astro"
export { default as GetGist} from "./GetGist.astro"
export { default as GetGistGroup} from "./GetGistGroup.astro"

View File

@ -2,26 +2,50 @@ import { defineIntegration, createResolver } from "astro-integration-kit"
import { corePlugins } from "astro-integration-kit/plugins"
import { astroGistsExpressiveCode } from "./integrations/expressive-code"
/** Astro-Gist - Astro Integration
* - There is currently no configuration for this integration. Just add it to your astro Integration list.
* @example
* import astroGist from "@matthiesenxyz/astro-gists";
* export default defineConfig({
* integrations: [astroGist()]
* });
*/
export default defineIntegration({
name: "@matthiesenxyz/astro-gists",
plugins: [...corePlugins],
setup() {
const { resolve } = createResolver(import.meta.url);
return {
"astro:config:setup": ({ watchIntegration, config, updateConfig, logger }) => {
watchIntegration(resolve())
return {
"astro:config:setup": ({
watchIntegration,
config,
updateConfig,
logger
}) => {
// WATCH INTEGRATION FOR CHANGES
watchIntegration(resolve())
// IMPORT INTEGRATIONS & INTEGRATION ROUTES
const integrations = [...config.integrations];
// ADD ASTRO-EXPRESSIVE-CODE INTEGRATION
if (!integrations.find(({ name }) => name === "astro-expressive-code")) {
logger.info("Adding astro-expressive-code integration")
updateConfig({
integrations: [...integrations, ...astroGistsExpressiveCode()]
})
}
// UPDATE ASTRO-EXPRESSIVE-CODE INTEGRATION
try {
updateConfig({
integrations: [...astroGistsExpressiveCode()]
})
} catch (e) {
logger.error(e as string);
throw e;
}
}
}
}

View File

@ -1,15 +1,19 @@
import { Octokit } from "octokit";
import { loadEnv } from "vite";
// Load environment variables
const { GITHUB_PERSONAL_TOKEN } = loadEnv("all", process.cwd(), "GITHUB_");
// Create an Octokit instance
export const octokit = new Octokit({ auth: GITHUB_PERSONAL_TOKEN });
// Get a Gist by ID
export const getGist = async (gistId: string) => {
const { data } = await octokit.request('GET /gists/{gist_id}', { gist_id: gistId });
return data;
};
// Get a file from a Gist by ID and filename
export const getGistFile = async (
gistId: string,
filename: string
@ -22,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;
};

View File

@ -1,7 +1,6 @@
import { defineConfig } from "astro/config";
import astroGist from "@matthiesenxyz/astro-gists";
// https://astro.build/config
export default defineConfig({
integrations: [astroGist()]

View File

@ -1,9 +1,13 @@
---
import { GetGist } from "@matthiesenxyz/astro-gists/components"
import { GetGist, GetGistGroup } from "@matthiesenxyz/astro-gists/components"
---
<h1>Dev: Playground</h1>
<GetGist
gistId="cce7f3f1d9322710be8196aa344186ba"
filename="hello.md"
/>
<GetGistGroup
gistId="84243fa11bf96a59bfb237152eb52fa7"
/>