some progress. and prep to add new component

This commit is contained in:
Adam Matthiesen 2024-02-24 08:03:37 -08:00
parent 139875a99f
commit 1a9258463b
3 changed files with 32 additions and 5 deletions

View File

@ -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;
}
} }
} }
} }

View File

@ -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

View File

@ -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()]