Update package.json and component files
This commit is contained in:
parent
0be102e2d0
commit
22a790a4c6
|
@ -30,7 +30,10 @@
|
|||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
".": {
|
||||
"types": "./src/index.d.ts",
|
||||
"import": "./src/index.ts"
|
||||
},
|
||||
"./components": "./src/components/index.ts",
|
||||
"./GetGist": "./src/components/GetGist.astro",
|
||||
"./GetGistGroup": "./src/components/GetGistGroup.astro"
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Export the user config schema
|
||||
import { z } from "astro/zod";
|
||||
import type { BundledShikiTheme } from "expressive-code";
|
||||
|
||||
export const optionsSchema = z.object({
|
||||
/**
|
||||
* Optional: Allows the user to change the default theme for the code blocks.
|
||||
* @example ['github-dark']
|
||||
*
|
||||
* All available themes are listed in the [Shiki documentation](https://shiki.matsu.io/docs/themes).
|
||||
*/
|
||||
theme: z.custom<BundledShikiTheme>().optional(),
|
||||
/**
|
||||
* Optional: Allows the user to enable verbose logging.
|
||||
*/
|
||||
verbose: z.boolean().optional().default(false),
|
||||
}).optional().default({ verbose: false });
|
||||
|
||||
export type astroGistsUserConfig = z.infer<typeof optionsSchema>
|
|
@ -1,6 +1,6 @@
|
|||
import { defineIntegration, createResolver } from "astro-integration-kit"
|
||||
import { corePlugins } from "astro-integration-kit/plugins"
|
||||
import type { astroGistsUserConfig } from "./index"
|
||||
import type { astroGistsUserConfig } from "./UserConfigSchema"
|
||||
import { readFileSync } from "node:fs";
|
||||
import type { AstroIntegrationLogger } from "astro";
|
||||
import { loadEnv } from "vite";
|
|
@ -25,14 +25,19 @@ const WRAP = wrap ? wrap : wrap === undefined ? true : false;
|
|||
const SLN = showLineNumbers ? showLineNumbers : showLineNumbers === undefined ? true : false;
|
||||
|
||||
// Fetching the Gist
|
||||
const Gist = await getGistFile( gistId, filename);
|
||||
const Gist = await getGistFile( gistId, filename );
|
||||
|
||||
---
|
||||
{ Gist &&
|
||||
{ Gist ? (
|
||||
<Code
|
||||
wrap={WRAP} showLineNumbers={SLN}
|
||||
title={Gist.filename} raw_url={Gist.raw_url}
|
||||
code={ Gist.content ? Gist.content : "" }
|
||||
lang={Gist.language ? Gist.language.toLowerCase() : undefined }
|
||||
/>
|
||||
/> ) : (
|
||||
<div>
|
||||
<h1>Sorry, the Gist with ID: {gistId} was not found</h1>
|
||||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
@ -25,13 +25,41 @@ const SLN = showLineNumbers ? showLineNumbers : showLineNumbers === undefined ?
|
|||
// get the Gist
|
||||
const Gist = await getGistGroup(gistId);
|
||||
|
||||
// extract the files
|
||||
const files = Gist.files;
|
||||
// Define the GistResponse type
|
||||
type GistFile = {
|
||||
filename: string;
|
||||
type: string;
|
||||
language: string;
|
||||
raw_url: string;
|
||||
size: number;
|
||||
content: string;
|
||||
};
|
||||
|
||||
type GistFiles = {
|
||||
[key: string]: GistFile
|
||||
};
|
||||
|
||||
let files = {} as GistFiles;
|
||||
|
||||
let noGist: boolean
|
||||
|
||||
if (Gist) {
|
||||
noGist = false;
|
||||
files = Gist.files as GistFiles;
|
||||
} else {
|
||||
noGist = true;
|
||||
}
|
||||
|
||||
---
|
||||
{ Gist && (
|
||||
{ noGist && (
|
||||
<div>
|
||||
<h1>Sorry, the Gist with ID: {gistId} was not found</h1>
|
||||
</div>
|
||||
) }
|
||||
{ !noGist && (
|
||||
<div>
|
||||
{Object.keys(files).map((file) => {
|
||||
const { content, filename, language, raw_url } = files[file];
|
||||
const { content, filename, language, raw_url } = files[file] as GistFile;
|
||||
return (
|
||||
<Code
|
||||
title={filename} wrap={WRAP}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
import type { AstroIntegration } from "astro";
|
||||
import type { astroGistsUserConfig} from "./UserConfigSchema";
|
||||
|
||||
export default function astroGists(options?: astroGistsUserConfig): AstroIntegration;
|
|
@ -1,23 +1,3 @@
|
|||
// Export Integration
|
||||
import astroGist from "./integration";
|
||||
export default astroGist;
|
||||
|
||||
// Export the user config schema
|
||||
import { z } from "astro/zod";
|
||||
import type { BundledShikiTheme } from "expressive-code";
|
||||
|
||||
export const optionsSchema = z.object({
|
||||
/**
|
||||
* Optional: Allows the user to change the default theme for the code blocks.
|
||||
* @example ['github-dark']
|
||||
*
|
||||
* All available themes are listed in the [Shiki documentation](https://shiki.matsu.io/docs/themes).
|
||||
*/
|
||||
theme: z.custom<BundledShikiTheme>().optional(),
|
||||
/**
|
||||
* Optional: Allows the user to enable verbose logging.
|
||||
*/
|
||||
verbose: z.boolean().optional().default(false),
|
||||
}).optional().default({ verbose: false });
|
||||
|
||||
export type astroGistsUserConfig = z.infer<typeof optionsSchema>
|
||||
import astroGists from "./astro-gists";
|
||||
export default astroGists;
|
|
@ -1,9 +1,9 @@
|
|||
import { defineConfig } from "astro/config";
|
||||
import astroGist from "@matthiesenxyz/astro-gists";
|
||||
import astroGists from "@matthiesenxyz/astro-gists";
|
||||
import mdx from "@astrojs/mdx"
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [astroGist(), mdx()]
|
||||
integrations: [astroGists(), mdx()]
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue