Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
14
node_modules/astro/dist/vite-plugin-astro/compile.d.ts
generated
vendored
Normal file
14
node_modules/astro/dist/vite-plugin-astro/compile.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { type ESBuildTransformResult } from 'vite';
|
||||
import { type CompileProps, type CompileResult } from '../core/compile/index.js';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
import type { CompileMetadata } from './types.js';
|
||||
interface CompileAstroOption {
|
||||
compileProps: CompileProps;
|
||||
astroFileToCompileMetadata: Map<string, CompileMetadata>;
|
||||
logger: Logger;
|
||||
}
|
||||
export interface CompileAstroResult extends Omit<CompileResult, 'map'> {
|
||||
map: ESBuildTransformResult['map'];
|
||||
}
|
||||
export declare function compileAstro({ compileProps, astroFileToCompileMetadata, logger, }: CompileAstroOption): Promise<CompileAstroResult>;
|
||||
export {};
|
95
node_modules/astro/dist/vite-plugin-astro/compile.js
generated
vendored
Normal file
95
node_modules/astro/dist/vite-plugin-astro/compile.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { transformWithEsbuild } from "vite";
|
||||
import { compile } from "../core/compile/index.js";
|
||||
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
||||
import { frontmatterRE } from "./utils.js";
|
||||
async function compileAstro({
|
||||
compileProps,
|
||||
astroFileToCompileMetadata,
|
||||
logger
|
||||
}) {
|
||||
let transformResult;
|
||||
let esbuildResult;
|
||||
try {
|
||||
transformResult = await compile(compileProps);
|
||||
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
|
||||
loader: "ts",
|
||||
target: "esnext",
|
||||
sourcemap: "external",
|
||||
tsconfigRaw: {
|
||||
compilerOptions: {
|
||||
// Ensure client:only imports are treeshaken
|
||||
verbatimModuleSyntax: false,
|
||||
importsNotUsedAsValues: "remove"
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
await enhanceCompileError({
|
||||
err,
|
||||
id: compileProps.filename,
|
||||
source: compileProps.source,
|
||||
config: compileProps.astroConfig,
|
||||
logger
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
const { fileId: file, fileUrl: url } = getFileInfo(
|
||||
compileProps.filename,
|
||||
compileProps.astroConfig
|
||||
);
|
||||
let SUFFIX = "";
|
||||
SUFFIX += `
|
||||
const $$file = ${JSON.stringify(file)};
|
||||
const $$url = ${JSON.stringify(
|
||||
url
|
||||
)};export { $$file as file, $$url as url };
|
||||
`;
|
||||
if (!compileProps.viteConfig.isProduction) {
|
||||
let i = 0;
|
||||
while (i < transformResult.scripts.length) {
|
||||
SUFFIX += `import "${compileProps.filename}?astro&type=script&index=${i}&lang.ts";`;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
astroFileToCompileMetadata.set(compileProps.filename, {
|
||||
originalCode: compileProps.source,
|
||||
css: transformResult.css,
|
||||
scripts: transformResult.scripts
|
||||
});
|
||||
return {
|
||||
...transformResult,
|
||||
code: esbuildResult.code + SUFFIX,
|
||||
map: esbuildResult.map
|
||||
};
|
||||
}
|
||||
async function enhanceCompileError({
|
||||
err,
|
||||
id,
|
||||
source
|
||||
}) {
|
||||
const lineText = err.loc?.lineText;
|
||||
const scannedFrontmatter = frontmatterRE.exec(source);
|
||||
if (scannedFrontmatter) {
|
||||
const frontmatter = scannedFrontmatter[1].replace(/\breturn\b/g, "throw");
|
||||
if (lineText && !frontmatter.includes(lineText)) throw err;
|
||||
try {
|
||||
await transformWithEsbuild(frontmatter, id, {
|
||||
loader: "ts",
|
||||
target: "esnext",
|
||||
sourcemap: false
|
||||
});
|
||||
} catch (frontmatterErr) {
|
||||
if (frontmatterErr?.message) {
|
||||
frontmatterErr.message = frontmatterErr.message.replace(
|
||||
"end of file",
|
||||
"end of frontmatter"
|
||||
);
|
||||
}
|
||||
throw frontmatterErr;
|
||||
}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
export {
|
||||
compileAstro
|
||||
};
|
9
node_modules/astro/dist/vite-plugin-astro/hmr.d.ts
generated
vendored
Normal file
9
node_modules/astro/dist/vite-plugin-astro/hmr.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { HmrContext } from 'vite';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
import type { CompileMetadata } from './types.js';
|
||||
export interface HandleHotUpdateOptions {
|
||||
logger: Logger;
|
||||
astroFileToCompileMetadata: Map<string, CompileMetadata>;
|
||||
}
|
||||
export declare function handleHotUpdate(ctx: HmrContext, { logger, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
|
||||
export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
|
53
node_modules/astro/dist/vite-plugin-astro/hmr.js
generated
vendored
Normal file
53
node_modules/astro/dist/vite-plugin-astro/hmr.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import { frontmatterRE } from "./utils.js";
|
||||
async function handleHotUpdate(ctx, { logger, astroFileToCompileMetadata }) {
|
||||
for (const [astroFile, compileData] of astroFileToCompileMetadata) {
|
||||
const isUpdatedFileCssDep = compileData.css.some((css) => css.dependencies?.includes(ctx.file));
|
||||
if (isUpdatedFileCssDep) {
|
||||
astroFileToCompileMetadata.delete(astroFile);
|
||||
}
|
||||
}
|
||||
const oldCode = astroFileToCompileMetadata.get(ctx.file)?.originalCode;
|
||||
if (oldCode == null) return;
|
||||
const newCode = await ctx.read();
|
||||
if (isStyleOnlyChanged(oldCode, newCode)) {
|
||||
logger.debug("watch", "style-only change");
|
||||
astroFileToCompileMetadata.delete(ctx.file);
|
||||
return ctx.modules.filter((mod) => mod.id?.includes("astro&type=style"));
|
||||
}
|
||||
}
|
||||
const scriptRE = /<script(?:\s.*?)?>.*?<\/script>/gs;
|
||||
const styleRE = /<style(?:\s.*?)?>.*?<\/style>/gs;
|
||||
function isStyleOnlyChanged(oldCode, newCode) {
|
||||
if (oldCode === newCode) return false;
|
||||
let oldFrontmatter = "";
|
||||
let newFrontmatter = "";
|
||||
oldCode = oldCode.replace(frontmatterRE, (m) => (oldFrontmatter = m, ""));
|
||||
newCode = newCode.replace(frontmatterRE, (m) => (newFrontmatter = m, ""));
|
||||
if (oldFrontmatter !== newFrontmatter) return false;
|
||||
const oldScripts = [];
|
||||
const newScripts = [];
|
||||
oldCode = oldCode.replace(scriptRE, (m) => (oldScripts.push(m), ""));
|
||||
newCode = newCode.replace(scriptRE, (m) => (newScripts.push(m), ""));
|
||||
if (!isArrayEqual(oldScripts, newScripts)) return false;
|
||||
const oldStyles = [];
|
||||
const newStyles = [];
|
||||
oldCode = oldCode.replace(styleRE, (m) => (oldStyles.push(m), ""));
|
||||
newCode = newCode.replace(styleRE, (m) => (newStyles.push(m), ""));
|
||||
if (oldCode !== newCode) return false;
|
||||
return oldStyles.length === newStyles.length && !isArrayEqual(oldStyles, newStyles);
|
||||
}
|
||||
function isArrayEqual(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
export {
|
||||
handleHotUpdate,
|
||||
isStyleOnlyChanged
|
||||
};
|
12
node_modules/astro/dist/vite-plugin-astro/index.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/vite-plugin-astro/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type * as vite from 'vite';
|
||||
import type { AstroSettings } from '../@types/astro.js';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
import type { PluginCssMetadata as AstroPluginCssMetadata, PluginMetadata as AstroPluginMetadata } from './types.js';
|
||||
export { getAstroMetadata } from './metadata.js';
|
||||
export type { AstroPluginMetadata, AstroPluginCssMetadata };
|
||||
interface AstroPluginOptions {
|
||||
settings: AstroSettings;
|
||||
logger: Logger;
|
||||
}
|
||||
/** Transform .astro files for Vite */
|
||||
export default function astro({ settings, logger }: AstroPluginOptions): vite.Plugin[];
|
207
node_modules/astro/dist/vite-plugin-astro/index.js
generated
vendored
Normal file
207
node_modules/astro/dist/vite-plugin-astro/index.js
generated
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
import { normalizePath } from "vite";
|
||||
import { hasSpecialQueries, normalizeFilename } from "../vite-plugin-utils/index.js";
|
||||
import { compileAstro } from "./compile.js";
|
||||
import { handleHotUpdate } from "./hmr.js";
|
||||
import { parseAstroRequest } from "./query.js";
|
||||
import { loadId } from "./utils.js";
|
||||
import { getAstroMetadata } from "./metadata.js";
|
||||
const astroFileToCompileMetadataWeakMap = /* @__PURE__ */ new WeakMap();
|
||||
function astro({ settings, logger }) {
|
||||
const { config } = settings;
|
||||
let server;
|
||||
let compile;
|
||||
let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
|
||||
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
||||
const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
|
||||
const prePlugin = {
|
||||
name: "astro:build",
|
||||
enforce: "pre",
|
||||
// run transforms before other plugins can
|
||||
configResolved(viteConfig) {
|
||||
compile = (code, filename) => {
|
||||
return compileAstro({
|
||||
compileProps: {
|
||||
astroConfig: config,
|
||||
viteConfig,
|
||||
preferences: settings.preferences,
|
||||
filename,
|
||||
source: code
|
||||
},
|
||||
astroFileToCompileMetadata,
|
||||
logger
|
||||
});
|
||||
};
|
||||
},
|
||||
configureServer(_server) {
|
||||
server = _server;
|
||||
server.watcher.on("unlink", (filename) => {
|
||||
astroFileToCompileMetadata.delete(filename);
|
||||
});
|
||||
},
|
||||
buildStart() {
|
||||
astroFileToCompileMetadata = /* @__PURE__ */ new Map();
|
||||
if (astroFileToCompileMetadataWeakMap.has(config)) {
|
||||
astroFileToCompileMetadata = astroFileToCompileMetadataWeakMap.get(config);
|
||||
} else {
|
||||
astroFileToCompileMetadataWeakMap.set(config, astroFileToCompileMetadata);
|
||||
}
|
||||
},
|
||||
async load(id, opts) {
|
||||
const parsedId = parseAstroRequest(id);
|
||||
const query = parsedId.query;
|
||||
if (!query.astro) {
|
||||
return null;
|
||||
}
|
||||
const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
|
||||
let compileMetadata = astroFileToCompileMetadata.get(filename);
|
||||
if (!compileMetadata) {
|
||||
if (server) {
|
||||
const code = await loadId(server.pluginContainer, filename);
|
||||
if (code != null) await compile(code, filename);
|
||||
} else if (config.experimental.contentCollectionCache) {
|
||||
await this.load({
|
||||
id: filename,
|
||||
resolveDependencies: false
|
||||
});
|
||||
}
|
||||
compileMetadata = astroFileToCompileMetadata.get(filename);
|
||||
}
|
||||
if (!compileMetadata) {
|
||||
throw new Error(
|
||||
`No cached compile metadata found for "${id}". The main Astro module "${filename}" should have compiled and filled the metadata first, before its virtual modules can be requested.`
|
||||
);
|
||||
}
|
||||
switch (query.type) {
|
||||
case "style": {
|
||||
if (typeof query.index === "undefined") {
|
||||
throw new Error(`Requests for Astro CSS must include an index.`);
|
||||
}
|
||||
const result = compileMetadata.css[query.index];
|
||||
if (!result) {
|
||||
throw new Error(`No Astro CSS at index ${query.index}`);
|
||||
}
|
||||
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
|
||||
return {
|
||||
code: result.code,
|
||||
// This metadata is used by `cssScopeToPlugin` to remove this module from the bundle
|
||||
// if the `filename` default export (the Astro component) is unused.
|
||||
meta: result.isGlobal ? void 0 : {
|
||||
astroCss: {
|
||||
cssScopeTo: {
|
||||
[filename]: ["default"]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
case "script": {
|
||||
if (typeof query.index === "undefined") {
|
||||
throw new Error(`Requests for hoisted scripts must include an index`);
|
||||
}
|
||||
if (opts?.ssr) {
|
||||
return {
|
||||
code: `/* client hoisted script, empty in SSR: ${id} */`
|
||||
};
|
||||
}
|
||||
const hoistedScript = compileMetadata.scripts[query.index];
|
||||
if (!hoistedScript) {
|
||||
throw new Error(`No hoisted script at index ${query.index}`);
|
||||
}
|
||||
if (hoistedScript.type === "external") {
|
||||
const src = hoistedScript.src;
|
||||
if (src.startsWith("/") && !isBrowserPath(src)) {
|
||||
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
|
||||
throw new Error(
|
||||
`
|
||||
|
||||
<script src="${src}"> references an asset in the "${publicDir}" directory. Please add the "is:inline" directive to keep this asset from being bundled.
|
||||
|
||||
File: ${id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
code: "",
|
||||
meta: {
|
||||
vite: {
|
||||
lang: "ts"
|
||||
}
|
||||
}
|
||||
};
|
||||
switch (hoistedScript.type) {
|
||||
case "inline": {
|
||||
const { code, map } = hoistedScript;
|
||||
result.code = appendSourceMap(code, map);
|
||||
break;
|
||||
}
|
||||
case "external": {
|
||||
const { src } = hoistedScript;
|
||||
result.code = `import "${src}"`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case "custom":
|
||||
case "template":
|
||||
case void 0:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
async transform(source, id) {
|
||||
if (hasSpecialQueries(id)) return;
|
||||
const parsedId = parseAstroRequest(id);
|
||||
if (!parsedId.filename.endsWith(".astro") || parsedId.query.astro) {
|
||||
return;
|
||||
}
|
||||
const filename = normalizePath(parsedId.filename);
|
||||
const transformResult = await compile(source, filename);
|
||||
const astroMetadata = {
|
||||
clientOnlyComponents: transformResult.clientOnlyComponents,
|
||||
hydratedComponents: transformResult.hydratedComponents,
|
||||
serverComponents: transformResult.serverComponents,
|
||||
scripts: transformResult.scripts,
|
||||
containsHead: transformResult.containsHead,
|
||||
propagation: transformResult.propagation ? "self" : "none",
|
||||
pageOptions: {}
|
||||
};
|
||||
return {
|
||||
code: transformResult.code,
|
||||
map: transformResult.map,
|
||||
meta: {
|
||||
astro: astroMetadata,
|
||||
vite: {
|
||||
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
||||
// extensions to .ts files.
|
||||
lang: "ts"
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
async handleHotUpdate(ctx) {
|
||||
return handleHotUpdate(ctx, { logger, astroFileToCompileMetadata });
|
||||
}
|
||||
};
|
||||
const normalPlugin = {
|
||||
name: "astro:build:normal",
|
||||
resolveId(id) {
|
||||
const parsedId = parseAstroRequest(id);
|
||||
if (parsedId.query.astro) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
};
|
||||
return [prePlugin, normalPlugin];
|
||||
}
|
||||
function appendSourceMap(content, map) {
|
||||
if (!map) return content;
|
||||
return `${content}
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(
|
||||
map
|
||||
).toString("base64")}`;
|
||||
}
|
||||
export {
|
||||
astro as default,
|
||||
getAstroMetadata
|
||||
};
|
4
node_modules/astro/dist/vite-plugin-astro/metadata.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/vite-plugin-astro/metadata.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { ModuleInfo } from '../core/module-loader/index.js';
|
||||
import type { PluginMetadata } from './types.js';
|
||||
export declare function getAstroMetadata(modInfo: ModuleInfo): PluginMetadata['astro'] | undefined;
|
||||
export declare function createDefaultAstroMetadata(): PluginMetadata['astro'];
|
21
node_modules/astro/dist/vite-plugin-astro/metadata.js
generated
vendored
Normal file
21
node_modules/astro/dist/vite-plugin-astro/metadata.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
function getAstroMetadata(modInfo) {
|
||||
if (modInfo.meta?.astro) {
|
||||
return modInfo.meta.astro;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
function createDefaultAstroMetadata() {
|
||||
return {
|
||||
hydratedComponents: [],
|
||||
clientOnlyComponents: [],
|
||||
serverComponents: [],
|
||||
scripts: [],
|
||||
propagation: "none",
|
||||
containsHead: false,
|
||||
pageOptions: {}
|
||||
};
|
||||
}
|
||||
export {
|
||||
createDefaultAstroMetadata,
|
||||
getAstroMetadata
|
||||
};
|
13
node_modules/astro/dist/vite-plugin-astro/query.d.ts
generated
vendored
Normal file
13
node_modules/astro/dist/vite-plugin-astro/query.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface AstroQuery {
|
||||
astro?: boolean;
|
||||
src?: boolean;
|
||||
type?: 'script' | 'template' | 'style' | 'custom';
|
||||
index?: number;
|
||||
lang?: string;
|
||||
raw?: boolean;
|
||||
}
|
||||
export interface ParsedRequestResult {
|
||||
filename: string;
|
||||
query: AstroQuery;
|
||||
}
|
||||
export declare function parseAstroRequest(id: string): ParsedRequestResult;
|
23
node_modules/astro/dist/vite-plugin-astro/query.js
generated
vendored
Normal file
23
node_modules/astro/dist/vite-plugin-astro/query.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function parseAstroRequest(id) {
|
||||
const [filename, rawQuery] = id.split(`?`, 2);
|
||||
const query = Object.fromEntries(new URLSearchParams(rawQuery).entries());
|
||||
if (query.astro != null) {
|
||||
query.astro = true;
|
||||
}
|
||||
if (query.src != null) {
|
||||
query.src = true;
|
||||
}
|
||||
if (query.index != null) {
|
||||
query.index = Number(query.index);
|
||||
}
|
||||
if (query.raw != null) {
|
||||
query.raw = true;
|
||||
}
|
||||
return {
|
||||
filename,
|
||||
query
|
||||
};
|
||||
}
|
||||
export {
|
||||
parseAstroRequest
|
||||
};
|
45
node_modules/astro/dist/vite-plugin-astro/types.d.ts
generated
vendored
Normal file
45
node_modules/astro/dist/vite-plugin-astro/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { HoistedScript, TransformResult } from '@astrojs/compiler';
|
||||
import type { PropagationHint } from '../@types/astro.js';
|
||||
import type { CompileCssResult } from '../core/compile/types.js';
|
||||
export interface PageOptions {
|
||||
prerender?: boolean;
|
||||
}
|
||||
export interface PluginMetadata {
|
||||
astro: {
|
||||
hydratedComponents: TransformResult['hydratedComponents'];
|
||||
clientOnlyComponents: TransformResult['clientOnlyComponents'];
|
||||
serverComponents: TransformResult['serverComponents'];
|
||||
scripts: TransformResult['scripts'];
|
||||
containsHead: TransformResult['containsHead'];
|
||||
propagation: PropagationHint;
|
||||
pageOptions: PageOptions;
|
||||
};
|
||||
}
|
||||
export interface PluginCssMetadata {
|
||||
astroCss: {
|
||||
/**
|
||||
* For Astro CSS virtual modules, it can scope to the main Astro module's default export
|
||||
* so that if those exports are treeshaken away, the CSS module will also be treeshaken.
|
||||
*
|
||||
* Example config if the CSS id is `/src/Foo.astro?astro&type=style&lang.css`:
|
||||
* ```js
|
||||
* cssScopeTo: {
|
||||
* '/src/Foo.astro': ['default']
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The above is the only config we use today, but we're exposing as a `Record` to follow the
|
||||
* upstream Vite implementation: https://github.com/vitejs/vite/pull/16058. When/If that lands,
|
||||
* we can also remove our custom implementation.
|
||||
*/
|
||||
cssScopeTo: Record<string, string[]>;
|
||||
};
|
||||
}
|
||||
export interface CompileMetadata {
|
||||
/** Used for HMR to compare code changes */
|
||||
originalCode: string;
|
||||
/** For Astro CSS virtual module */
|
||||
css: CompileCssResult[];
|
||||
/** For Astro hoisted scripts virtual module */
|
||||
scripts: HoistedScript[];
|
||||
}
|
0
node_modules/astro/dist/vite-plugin-astro/types.js
generated
vendored
Normal file
0
node_modules/astro/dist/vite-plugin-astro/types.js
generated
vendored
Normal file
3
node_modules/astro/dist/vite-plugin-astro/utils.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/vite-plugin-astro/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { PluginContainer } from 'vite';
|
||||
export declare const frontmatterRE: RegExp;
|
||||
export declare function loadId(pluginContainer: PluginContainer, id: string): Promise<string | undefined>;
|
20
node_modules/astro/dist/vite-plugin-astro/utils.js
generated
vendored
Normal file
20
node_modules/astro/dist/vite-plugin-astro/utils.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from "node:fs/promises";
|
||||
const frontmatterRE = /^---(.*?)^---/ms;
|
||||
async function loadId(pluginContainer, id) {
|
||||
const result = await pluginContainer.load(id, { ssr: true });
|
||||
if (result) {
|
||||
if (typeof result === "string") {
|
||||
return result;
|
||||
} else {
|
||||
return result.code;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return await fs.readFile(id, "utf-8");
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
export {
|
||||
frontmatterRE,
|
||||
loadId
|
||||
};
|
Reference in New Issue
Block a user