commit
4375a0f1fb
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@matthiesenxyz/astro-gists": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added new <GetGistGroup> Component to get entire collections of gists (See Readme for more info)
|
|
@ -73,9 +73,9 @@ GITHUB_PERSONAL_TOKEN=ghp_YOURPERSONALTOKENHERE
|
||||||
|
|
||||||
### Usage
|
### 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
|
```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
|
## Contributing
|
||||||
|
|
||||||
This package is structured as a monorepo:
|
This package is structured as a monorepo:
|
||||||
|
|
|
@ -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>
|
|
@ -1 +1,2 @@
|
||||||
export { default as GetGist} from "./GetGist.astro"
|
export { default as GetGist} from "./GetGist.astro"
|
||||||
|
export { default as GetGistGroup} from "./GetGistGroup.astro"
|
|
@ -2,26 +2,50 @@ import { defineIntegration, createResolver } from "astro-integration-kit"
|
||||||
import { corePlugins } from "astro-integration-kit/plugins"
|
import { corePlugins } from "astro-integration-kit/plugins"
|
||||||
import { astroGistsExpressiveCode } from "./integrations/expressive-code"
|
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({
|
export default defineIntegration({
|
||||||
name: "@matthiesenxyz/astro-gists",
|
name: "@matthiesenxyz/astro-gists",
|
||||||
plugins: [...corePlugins],
|
plugins: [...corePlugins],
|
||||||
setup() {
|
setup() {
|
||||||
const { resolve } = createResolver(import.meta.url);
|
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
|
// IMPORT INTEGRATIONS & INTEGRATION ROUTES
|
||||||
const integrations = [...config.integrations];
|
const integrations = [...config.integrations];
|
||||||
|
|
||||||
|
// ADD ASTRO-EXPRESSIVE-CODE INTEGRATION
|
||||||
if (!integrations.find(({ name }) => name === "astro-expressive-code")) {
|
if (!integrations.find(({ name }) => name === "astro-expressive-code")) {
|
||||||
logger.info("Adding astro-expressive-code integration")
|
logger.info("Adding astro-expressive-code integration")
|
||||||
updateConfig({
|
updateConfig({
|
||||||
integrations: [...integrations, ...astroGistsExpressiveCode()]
|
integrations: [...integrations, ...astroGistsExpressiveCode()]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UPDATE ASTRO-EXPRESSIVE-CODE INTEGRATION
|
||||||
|
try {
|
||||||
|
updateConfig({
|
||||||
|
integrations: [...astroGistsExpressiveCode()]
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e as string);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import { Octokit } from "octokit";
|
import { Octokit } from "octokit";
|
||||||
import { loadEnv } from "vite";
|
import { loadEnv } from "vite";
|
||||||
|
|
||||||
|
// Load environment variables
|
||||||
const { GITHUB_PERSONAL_TOKEN } = loadEnv("all", process.cwd(), "GITHUB_");
|
const { GITHUB_PERSONAL_TOKEN } = loadEnv("all", process.cwd(), "GITHUB_");
|
||||||
|
|
||||||
|
// Create an Octokit instance
|
||||||
export const octokit = new Octokit({ auth: GITHUB_PERSONAL_TOKEN });
|
export const octokit = new Octokit({ auth: GITHUB_PERSONAL_TOKEN });
|
||||||
|
|
||||||
|
// Get a Gist by ID
|
||||||
export const getGist = async (gistId: string) => {
|
export const getGist = async (gistId: string) => {
|
||||||
const { data } = await octokit.request('GET /gists/{gist_id}', { gist_id: gistId });
|
const { data } = await octokit.request('GET /gists/{gist_id}', { gist_id: gistId });
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get a file from a Gist by ID and filename
|
||||||
export const getGistFile = async (
|
export const getGistFile = async (
|
||||||
gistId: string,
|
gistId: string,
|
||||||
filename: string
|
filename: string
|
||||||
|
@ -22,3 +26,12 @@ export const getGistFile = async (
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getGistGroup = async (
|
||||||
|
gistId: string
|
||||||
|
) => {
|
||||||
|
const gist = await getGist(gistId);
|
||||||
|
if (gist?.files) {
|
||||||
|
return gist ? gist : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
|
@ -1,7 +1,6 @@
|
||||||
import { defineConfig } from "astro/config";
|
import { defineConfig } from "astro/config";
|
||||||
import astroGist from "@matthiesenxyz/astro-gists";
|
import astroGist from "@matthiesenxyz/astro-gists";
|
||||||
|
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
integrations: [astroGist()]
|
integrations: [astroGist()]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
import { GetGist } from "@matthiesenxyz/astro-gists/components"
|
import { GetGist, GetGistGroup } from "@matthiesenxyz/astro-gists/components"
|
||||||
---
|
---
|
||||||
<h1>Dev: Playground</h1>
|
<h1>Dev: Playground</h1>
|
||||||
|
|
||||||
|
@ -7,3 +7,7 @@ import { GetGist } from "@matthiesenxyz/astro-gists/components"
|
||||||
gistId="cce7f3f1d9322710be8196aa344186ba"
|
gistId="cce7f3f1d9322710be8196aa344186ba"
|
||||||
filename="hello.md"
|
filename="hello.md"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<GetGistGroup
|
||||||
|
gistId="84243fa11bf96a59bfb237152eb52fa7"
|
||||||
|
/>
|
Loading…
Reference in New Issue