mirror of
https://github.com/sern-handler/website
synced 2026-06-24 00:32:24 +00:00
feat: migrate to starlight
This commit is contained in:
1
node_modules/astro-expressive-code/dist/hast.d.ts
generated
vendored
Normal file
1
node_modules/astro-expressive-code/dist/hast.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from 'rehype-expressive-code/hast';
|
||||
3
node_modules/astro-expressive-code/dist/hast.js
generated
vendored
Normal file
3
node_modules/astro-expressive-code/dist/hast.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/hast.ts
|
||||
export * from "rehype-expressive-code/hast";
|
||||
//# sourceMappingURL=hast.js.map
|
||||
1
node_modules/astro-expressive-code/dist/hast.js.map
generated
vendored
Normal file
1
node_modules/astro-expressive-code/dist/hast.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/hast.ts"],"sourcesContent":["export * from 'rehype-expressive-code/hast'\n"],"mappings":";AAAA,cAAc;","names":[]}
|
||||
128
node_modules/astro-expressive-code/dist/index.d.ts
generated
vendored
Normal file
128
node_modules/astro-expressive-code/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
import { AstroIntegration } from 'astro';
|
||||
import { RehypeExpressiveCodeRenderer, RehypeExpressiveCodeOptions } from 'rehype-expressive-code';
|
||||
export * from 'rehype-expressive-code';
|
||||
|
||||
type ConfigSetupHookArgs = Parameters<NonNullable<AstroIntegration['hooks']['astro:config:setup']>>[0];
|
||||
type AstroConfig = ConfigSetupHookArgs['config'];
|
||||
/**
|
||||
* Contains the parts of the Astro config that are used by this integration.
|
||||
*/
|
||||
type PartialAstroConfig = Pick<AstroConfig, 'base' | 'root' | 'srcDir'> & {
|
||||
build?: Partial<Pick<AstroConfig['build'], 'assets' | 'assetsPrefix'>> | undefined;
|
||||
markdown?: Partial<{
|
||||
shikiConfig: Partial<Pick<AstroConfig['markdown']['shikiConfig'], 'langs'>>;
|
||||
}> | undefined;
|
||||
};
|
||||
|
||||
type CreateAstroRendererArgs = {
|
||||
ecConfig: AstroExpressiveCodeOptions;
|
||||
astroConfig: PartialAstroConfig;
|
||||
logger?: ConfigSetupHookArgs['logger'] | undefined;
|
||||
};
|
||||
type AstroExpressiveCodeRenderer = RehypeExpressiveCodeRenderer & {
|
||||
hashedStyles: [string, string][];
|
||||
hashedScripts: [string, string][];
|
||||
};
|
||||
declare function createAstroRenderer({ ecConfig, astroConfig, logger }: CreateAstroRendererArgs): Promise<AstroExpressiveCodeRenderer>;
|
||||
|
||||
type AstroExpressiveCodeOptions = RehypeExpressiveCodeOptions & {
|
||||
/**
|
||||
* Determines if the styles required to display code blocks should be emitted into a separate
|
||||
* CSS file rather than being inlined into the rendered HTML of the first code block per page.
|
||||
*
|
||||
* This is recommended for sites containing multiple pages with code blocks, as it will reduce
|
||||
* the overall footprint of the site when navigating between pages.
|
||||
*
|
||||
* The generated URL is located inside Astro's assets directory and includes a content hash
|
||||
* so it can be cached indefinitely by browsers. If you are using the default values for the
|
||||
* Astro config options `base`, `build.assets`, `build.assetsPrefix`, the resulting URL
|
||||
* will be `/_astro/ec.{hash}.css`.
|
||||
*
|
||||
* **Important**: To actually benefit from caching, please ensure that your hosting provider
|
||||
* serves the contents of the assets directory as immutable files with a long cache lifetime,
|
||||
* e.g. `Cache-Control: public,max-age=31536000,immutable`.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
emitExternalStylesheet?: boolean | undefined;
|
||||
/**
|
||||
* This advanced option allows you to influence the rendering process by creating
|
||||
* your own `AstroExpressiveCodeRenderer` or processing the base styles and JS modules
|
||||
* added to every page.
|
||||
*
|
||||
* The return value will be cached and used for all code blocks on the site.
|
||||
*/
|
||||
customCreateAstroRenderer?: ((args: CreateAstroRendererArgs) => Promise<AstroExpressiveCodeRenderer> | AstroExpressiveCodeRenderer) | undefined;
|
||||
/**
|
||||
* This advanced option allows you to preprocess the Expressive Code configuration
|
||||
* before it is used by the Astro integration or its exported `<Code>` component.
|
||||
*
|
||||
* For example, Starlight uses this option to provide different default settings
|
||||
* and additional theme options.
|
||||
*/
|
||||
customConfigPreprocessors?: CustomConfigPreprocessors | undefined;
|
||||
};
|
||||
type CustomConfigPreprocessors = {
|
||||
/**
|
||||
* To perform preprocessing on the Expressive Code configuration before it is used
|
||||
* by the Astro integration, set this property to a function. It will be called with
|
||||
* an object argument that contains the following properties:
|
||||
* - `ecConfig`: an Expressive Code config object merged from the optional EC config file
|
||||
* `ec.config.mjs` and any options passed directly to the integration
|
||||
* - `astroConfig`: an object containing commonly used settings from the Astro configuration
|
||||
*
|
||||
* The return value must be a valid Expressive Code configuration object.
|
||||
*/
|
||||
preprocessAstroIntegrationConfig: ConfigPreprocessorFn;
|
||||
/**
|
||||
* If you set `preprocessAstroIntegrationConfig` to a function, you must also set this property
|
||||
* to the JS source code of a Vite virtual module that exports the same function as its
|
||||
* default export.
|
||||
*
|
||||
* This is necessary to allow the `<Code>` component to access the same preprocessed config
|
||||
* as the Astro integration. The Astro integration cannot share the function directly with
|
||||
* the `<Code>` component because it runs in a separate Vite instance.
|
||||
*/
|
||||
preprocessComponentConfig: string;
|
||||
};
|
||||
type ConfigPreprocessorFn = (args: {
|
||||
ecConfig: unknown;
|
||||
astroConfig: PartialAstroConfig;
|
||||
}) => Promise<AstroExpressiveCodeOptions> | AstroExpressiveCodeOptions;
|
||||
|
||||
/**
|
||||
* Astro integration that adds Expressive Code support to code blocks in Markdown & MDX documents.
|
||||
*/
|
||||
declare function astroExpressiveCode(integrationOptions?: AstroExpressiveCodeOptions): {
|
||||
name: string;
|
||||
hooks: {
|
||||
'astro:config:setup': (args: unknown) => Promise<void>;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* A utility function that helps you define an Expressive Code configuration object. It is meant
|
||||
* to be used inside the optional config file `ec.config.mjs` located in the root directory
|
||||
* of your Astro project, and its return value to be exported as the default export.
|
||||
*
|
||||
* Expressive Code will automatically detect this file and use the exported configuration object
|
||||
* to override its own default settings.
|
||||
*
|
||||
* Using this function is recommended, but not required. It just passes through the given object,
|
||||
* but it also provides type information for your editor's auto-completion and type checking.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* // ec.config.mjs
|
||||
* import { defineEcConfig } from 'astro-expressive-code'
|
||||
*
|
||||
* export default defineEcConfig({
|
||||
* themes: ['dracula', 'github-light'],
|
||||
* styleOverrides: {
|
||||
* borderRadius: '0.5rem',
|
||||
* },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
declare function defineEcConfig(config: AstroExpressiveCodeOptions): AstroExpressiveCodeOptions;
|
||||
|
||||
export { AstroExpressiveCodeOptions, AstroExpressiveCodeRenderer, ConfigPreprocessorFn, CreateAstroRendererArgs, CustomConfigPreprocessors, PartialAstroConfig, astroExpressiveCode, createAstroRenderer, astroExpressiveCode as default, defineEcConfig };
|
||||
319
node_modules/astro-expressive-code/dist/index.js
generated
vendored
Normal file
319
node_modules/astro-expressive-code/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
// src/index.ts
|
||||
import rehypeExpressiveCode from "rehype-expressive-code";
|
||||
|
||||
// src/ec-config.ts
|
||||
function getEcConfigFileUrl(projectRootUrl) {
|
||||
return new URL("./ec.config.mjs", projectRootUrl);
|
||||
}
|
||||
async function loadEcConfigFile(projectRootUrl) {
|
||||
const pathsToTry = [
|
||||
// This path works in most scenarios, but not when the integration is processed by Vite
|
||||
// due to a Vite bug affecting import URLs using the "file:" protocol
|
||||
new URL(`./ec.config.mjs?t=${Date.now()}`, projectRootUrl).href
|
||||
];
|
||||
if (import.meta.env?.BASE_URL?.length) {
|
||||
pathsToTry.push(`/ec.config.mjs?t=${Date.now()}`);
|
||||
}
|
||||
function coerceError(error) {
|
||||
if (typeof error === "object" && error !== null && "message" in error) {
|
||||
return error;
|
||||
}
|
||||
return { message: error };
|
||||
}
|
||||
for (const path of pathsToTry) {
|
||||
try {
|
||||
const module = await import(
|
||||
/* @vite-ignore */
|
||||
path
|
||||
);
|
||||
if (!module.default) {
|
||||
throw new Error(`Missing or invalid default export. Please export your Expressive Code config object as the default export.`);
|
||||
}
|
||||
return module.default;
|
||||
} catch (error) {
|
||||
const { message, code } = coerceError(error);
|
||||
if (code === "ERR_MODULE_NOT_FOUND" || code === "ERR_LOAD_URL") {
|
||||
if (message.replace(/(imported )?from .*$/, "").includes("ec.config.mjs"))
|
||||
continue;
|
||||
}
|
||||
throw new Error(
|
||||
`Your project includes an Expressive Code config file ("ec.config.mjs")
|
||||
that could not be loaded due to ${code ? `the error ${code}` : "the following error"}: ${message}`.replace(/\s+/g, " "),
|
||||
error instanceof Error ? { cause: error } : void 0
|
||||
);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// src/renderer.ts
|
||||
import { createRenderer, getStableObjectHash } from "rehype-expressive-code";
|
||||
|
||||
// src/astro-config.ts
|
||||
function serializePartialAstroConfig(config) {
|
||||
const partialConfig = {
|
||||
base: config.base,
|
||||
root: config.root,
|
||||
srcDir: config.srcDir
|
||||
};
|
||||
if (config.build) {
|
||||
partialConfig.build = {};
|
||||
if (config.build.assets)
|
||||
partialConfig.build.assets = config.build.assets;
|
||||
if (config.build.assetsPrefix)
|
||||
partialConfig.build.assetsPrefix = config.build.assetsPrefix;
|
||||
}
|
||||
if (config.markdown?.shikiConfig?.langs) {
|
||||
partialConfig.markdown = { shikiConfig: { langs: config.markdown.shikiConfig.langs } };
|
||||
}
|
||||
return JSON.stringify(partialConfig);
|
||||
}
|
||||
function getAssetsPrefix(fileExtension, assetsPrefix) {
|
||||
if (!assetsPrefix)
|
||||
return "";
|
||||
if (typeof assetsPrefix === "string")
|
||||
return assetsPrefix;
|
||||
const dotLessFileExtension = fileExtension.slice(1);
|
||||
if (assetsPrefix[dotLessFileExtension]) {
|
||||
return assetsPrefix[dotLessFileExtension];
|
||||
}
|
||||
return assetsPrefix.fallback;
|
||||
}
|
||||
function getAssetsBaseHref(fileExtension, assetsPrefix, base) {
|
||||
return (getAssetsPrefix(fileExtension, assetsPrefix) || base || "").trim().replace(/\/+$/g, "");
|
||||
}
|
||||
|
||||
// src/renderer.ts
|
||||
async function createAstroRenderer({ ecConfig, astroConfig, logger }) {
|
||||
const { emitExternalStylesheet = true, customCreateRenderer, plugins = [], shiki = true, ...rest } = ecConfig ?? {};
|
||||
const assetsDir = astroConfig.build?.assets || "_astro";
|
||||
const hashedStyles = [];
|
||||
const hashedScripts = [];
|
||||
plugins.push({
|
||||
name: "astro-expressive-code",
|
||||
hooks: {
|
||||
postprocessRenderedBlockGroup: ({ renderData, renderedGroupContents }) => {
|
||||
const isFirstGroupInDocument = renderedGroupContents[0]?.codeBlock.parentDocument?.positionInDocument?.groupIndex === 0;
|
||||
if (!isFirstGroupInDocument)
|
||||
return;
|
||||
const extraElements = [];
|
||||
hashedStyles.forEach(([hashedRoute]) => {
|
||||
extraElements.push({
|
||||
type: "element",
|
||||
tagName: "link",
|
||||
properties: { rel: "stylesheet", href: `${getAssetsBaseHref(".css", astroConfig.build?.assetsPrefix, astroConfig.base)}${hashedRoute}` },
|
||||
children: []
|
||||
});
|
||||
});
|
||||
hashedScripts.forEach(([hashedRoute]) => {
|
||||
extraElements.push({
|
||||
type: "element",
|
||||
tagName: "script",
|
||||
properties: { type: "module", src: `${getAssetsBaseHref(".js", astroConfig.build?.assetsPrefix, astroConfig.base)}${hashedRoute}` },
|
||||
children: []
|
||||
});
|
||||
});
|
||||
if (!extraElements.length)
|
||||
return;
|
||||
renderData.groupAst.children.unshift(...extraElements);
|
||||
}
|
||||
}
|
||||
});
|
||||
const mergedShikiConfig = shiki === true ? {} : shiki;
|
||||
if (mergedShikiConfig && !mergedShikiConfig.langs && astroConfig.markdown?.shikiConfig?.langs) {
|
||||
mergedShikiConfig.langs = astroConfig.markdown.shikiConfig.langs;
|
||||
}
|
||||
const renderer = await (customCreateRenderer ?? createRenderer)({
|
||||
plugins,
|
||||
logger,
|
||||
shiki: mergedShikiConfig,
|
||||
...rest
|
||||
});
|
||||
renderer.hashedStyles = hashedStyles;
|
||||
renderer.hashedScripts = hashedScripts;
|
||||
if (emitExternalStylesheet) {
|
||||
const combinedStyles = `${renderer.baseStyles}${renderer.themeStyles}`;
|
||||
hashedStyles.push(getHashedRouteWithContent(combinedStyles, `/${assetsDir}/ec.{hash}.css`));
|
||||
renderer.baseStyles = "";
|
||||
renderer.themeStyles = "";
|
||||
}
|
||||
const uniqueJsModules = [...new Set(renderer.jsModules)];
|
||||
const mergedJsCode = uniqueJsModules.join("\n");
|
||||
renderer.jsModules = [];
|
||||
hashedScripts.push(getHashedRouteWithContent(mergedJsCode, `/${assetsDir}/ec.{hash}.js`));
|
||||
return renderer;
|
||||
}
|
||||
function getHashedRouteWithContent(content, routeTemplate) {
|
||||
const contentHash = getStableObjectHash(content, { hashLength: 5 });
|
||||
return [routeTemplate.replace("{hash}", contentHash), content];
|
||||
}
|
||||
|
||||
// src/vite-plugin.ts
|
||||
import { stableStringify } from "rehype-expressive-code";
|
||||
function vitePluginAstroExpressiveCode({
|
||||
styles,
|
||||
scripts,
|
||||
ecIntegrationOptions,
|
||||
astroConfig,
|
||||
command
|
||||
}) {
|
||||
const modules = {};
|
||||
const configModuleContents = [];
|
||||
configModuleContents.push(`export const astroConfig = ${serializePartialAstroConfig(astroConfig)}`);
|
||||
const { customConfigPreprocessors, ...otherEcIntegrationOptions } = ecIntegrationOptions;
|
||||
configModuleContents.push(`export const ecIntegrationOptions = ${stableStringify(otherEcIntegrationOptions)}`);
|
||||
const strEcConfigFileUrlHref = JSON.stringify(getEcConfigFileUrl(astroConfig.root).href);
|
||||
configModuleContents.push(
|
||||
`let ecConfigFileOptions = {}`,
|
||||
`try {`,
|
||||
` ecConfigFileOptions = (await import('virtual:astro-expressive-code/ec-config')).default`,
|
||||
`} catch (e) {`,
|
||||
` console.error('*** Failed to load Expressive Code config file ${strEcConfigFileUrlHref}. You can ignore this message if you just renamed/removed the file.\\n\\n(Full error message: "' + (e?.message || e) + '")\\n')`,
|
||||
`}`,
|
||||
`export { ecConfigFileOptions }`
|
||||
);
|
||||
modules["virtual:astro-expressive-code/config"] = configModuleContents.join("\n");
|
||||
modules["virtual:astro-expressive-code/ec-config"] = "export default {}";
|
||||
modules["virtual:astro-expressive-code/preprocess-config"] = customConfigPreprocessors?.preprocessComponentConfig || `export default ({ ecConfig }) => ecConfig`;
|
||||
const noQuery = (source) => source.split("?")[0];
|
||||
const getVirtualModuleContents = (source) => {
|
||||
if (command === "dev") {
|
||||
for (const file of [...styles, ...scripts]) {
|
||||
const [fileName, contents] = file;
|
||||
if (noQuery(fileName) === noQuery(source))
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
return source in modules ? modules[source] : void 0;
|
||||
};
|
||||
return {
|
||||
name: "vite-plugin-astro-expressive-code",
|
||||
async resolveId(source, importer) {
|
||||
if (source === "virtual:astro-expressive-code/api") {
|
||||
const resolved = await this.resolve("astro-expressive-code", importer);
|
||||
if (resolved)
|
||||
return resolved;
|
||||
return await this.resolve("astro-expressive-code");
|
||||
}
|
||||
if (source === "virtual:astro-expressive-code/ec-config") {
|
||||
const resolved = await this.resolve("./ec.config.mjs");
|
||||
if (resolved)
|
||||
return resolved;
|
||||
}
|
||||
if (getVirtualModuleContents(source))
|
||||
return `\0${source}`;
|
||||
},
|
||||
load: (id) => id?.[0] === "\0" ? getVirtualModuleContents(id.slice(1)) : void 0,
|
||||
// If any file imported by the EC config file changes, restart the server
|
||||
async handleHotUpdate({ modules: modules2, server }) {
|
||||
if (!modules2 || !server)
|
||||
return;
|
||||
const isImportedByEcConfig = (module, depth = 0) => {
|
||||
if (!module || !module.importers || depth >= 6)
|
||||
return false;
|
||||
for (const importingModule of module.importers) {
|
||||
if (noQuery(module.url).endsWith("/ec.config.mjs")) {
|
||||
return true;
|
||||
}
|
||||
if (isImportedByEcConfig(importingModule, depth + 1))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (modules2.some((module) => isImportedByEcConfig(module))) {
|
||||
await server.restart();
|
||||
}
|
||||
},
|
||||
buildEnd() {
|
||||
if (command === "build") {
|
||||
for (const file of [...styles, ...scripts]) {
|
||||
const [fileName, source] = file;
|
||||
this.emitFile({
|
||||
type: "asset",
|
||||
// Remove leading slash and any query params
|
||||
fileName: noQuery(fileName.slice(1)),
|
||||
source
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
export * from "rehype-expressive-code";
|
||||
function astroExpressiveCode(integrationOptions = {}) {
|
||||
const integration = {
|
||||
name: "astro-expressive-code",
|
||||
hooks: {
|
||||
"astro:config:setup": async (args) => {
|
||||
const { command, config: astroConfig, updateConfig, logger, addWatchFile } = args;
|
||||
const ownPosition = astroConfig.integrations.findIndex((integration2) => integration2.name === "astro-expressive-code");
|
||||
const mdxPosition = astroConfig.integrations.findIndex((integration2) => integration2.name === "@astrojs/mdx");
|
||||
if (ownPosition > -1 && mdxPosition > -1 && mdxPosition < ownPosition) {
|
||||
throw new Error(
|
||||
`Incorrect integration order: To allow code blocks on MDX pages to use
|
||||
astro-expressive-code, please move astroExpressiveCode() before mdx()
|
||||
in the "integrations" array of your Astro config file.`.replace(/\s+/g, " ")
|
||||
);
|
||||
}
|
||||
addWatchFile(getEcConfigFileUrl(astroConfig.root));
|
||||
const ecConfigFileOptions = await loadEcConfigFile(astroConfig.root);
|
||||
const mergedOptions = { ...ecConfigFileOptions, ...integrationOptions };
|
||||
const forwardedIntegrationOptions = { ...integrationOptions };
|
||||
delete forwardedIntegrationOptions.customConfigPreprocessors;
|
||||
if (Object.keys(ecConfigFileOptions).length > 0 && Object.keys(forwardedIntegrationOptions).length > 0) {
|
||||
logger.warn(
|
||||
`Your project includes an Expressive Code config file ("ec.config.mjs"),
|
||||
but your Astro config file also contains Expressive Code options.
|
||||
To avoid unexpected results from merging multiple config sources,
|
||||
move all Expressive Code options into its config file.
|
||||
Found options: ${Object.keys(forwardedIntegrationOptions).join(", ")}`.replace(/\s+/g, " ")
|
||||
);
|
||||
}
|
||||
const processedEcConfig = await mergedOptions.customConfigPreprocessors?.preprocessAstroIntegrationConfig({ ecConfig: mergedOptions, astroConfig }) || mergedOptions;
|
||||
const { customCreateAstroRenderer } = processedEcConfig;
|
||||
delete processedEcConfig.customCreateAstroRenderer;
|
||||
delete processedEcConfig.customConfigPreprocessors;
|
||||
const { hashedStyles, hashedScripts, ...renderer } = await (customCreateAstroRenderer ?? createAstroRenderer)({ astroConfig, ecConfig: processedEcConfig, logger });
|
||||
const rehypeExpressiveCodeOptions = {
|
||||
// Even though we have created a custom renderer, some options are used
|
||||
// by the rehype integration itself (e.g. `tabWidth`, `getBlockLocale`),
|
||||
// so we pass all of them through just to be safe
|
||||
...processedEcConfig,
|
||||
// Pass our custom renderer to the rehype integration
|
||||
customCreateRenderer: () => renderer
|
||||
};
|
||||
updateConfig({
|
||||
vite: {
|
||||
plugins: [
|
||||
vitePluginAstroExpressiveCode({
|
||||
styles: hashedStyles,
|
||||
scripts: hashedScripts,
|
||||
ecIntegrationOptions: integrationOptions,
|
||||
astroConfig,
|
||||
command
|
||||
})
|
||||
]
|
||||
},
|
||||
markdown: {
|
||||
syntaxHighlight: false,
|
||||
rehypePlugins: [[rehypeExpressiveCode, rehypeExpressiveCodeOptions]]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
return integration;
|
||||
}
|
||||
function defineEcConfig(config) {
|
||||
return config;
|
||||
}
|
||||
var src_default = astroExpressiveCode;
|
||||
export {
|
||||
astroExpressiveCode,
|
||||
createAstroRenderer,
|
||||
src_default as default,
|
||||
defineEcConfig
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/astro-expressive-code/dist/index.js.map
generated
vendored
Normal file
1
node_modules/astro-expressive-code/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user