Update package.json and component files

This commit is contained in:
Adam Matthiesen 2024-03-22 03:47:41 -07:00
parent 0be102e2d0
commit 22a790a4c6
No known key found for this signature in database
GPG Key ID: 1A080F6B1E4AF38E
8 changed files with 72 additions and 33 deletions

View File

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

View File

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

View File

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

View File

@ -28,11 +28,16 @@ const SLN = showLineNumbers ? showLineNumbers : showLineNumbers === undefined ?
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>
)
}

View File

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

4
package/src/index.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import type { AstroIntegration } from "astro";
import type { astroGistsUserConfig} from "./UserConfigSchema";
export default function astroGists(options?: astroGistsUserConfig): AstroIntegration;

View File

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

View File

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