44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
---
|
|
import { getGistFile } from "../lib"
|
|
import { Code } from "../ExpressiveCode"
|
|
|
|
export interface Props {
|
|
/** REQUIRED: Used to define the desired GitHub Gist ID */
|
|
gistId: string;
|
|
/** REQUIRED: Used to define the desired file from the Gist */
|
|
filename: 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;
|
|
}
|
|
|
|
// Extracting the Props
|
|
const { gistId, filename, wrap, showLineNumbers } = Astro.props as Props;
|
|
|
|
// Setting the Defaults
|
|
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 );
|
|
|
|
---
|
|
{ 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>
|
|
)
|
|
|
|
}
|