full site update
This commit is contained in:
49
node_modules/astro/dist/vite-plugin-markdown/index.js
generated
vendored
49
node_modules/astro/dist/vite-plugin-markdown/index.js
generated
vendored
@@ -1,13 +1,13 @@
|
||||
import fs from "node:fs";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import {
|
||||
InvalidAstroDataError,
|
||||
createMarkdownProcessor
|
||||
createMarkdownProcessor,
|
||||
isFrontmatterValid
|
||||
} from "@astrojs/markdown-remark";
|
||||
import { normalizePath } from "vite";
|
||||
import { safeParseFrontmatter } from "../content/utils.js";
|
||||
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
||||
import { isMarkdownFile } from "../core/util.js";
|
||||
import { isMarkdownFile, isPage } from "../core/util.js";
|
||||
import { normalizePath } from "../core/viteUtils.js";
|
||||
import { shorthash } from "../runtime/server/shorthash.js";
|
||||
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
||||
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
||||
@@ -44,23 +44,32 @@ function markdown({ settings, logger }) {
|
||||
const raw = safeParseFrontmatter(rawFile, id);
|
||||
const fileURL = pathToFileURL(fileId);
|
||||
if (!processor) {
|
||||
processor = createMarkdownProcessor(settings.config.markdown);
|
||||
processor = createMarkdownProcessor({
|
||||
image: settings.config.image,
|
||||
experimentalHeadingIdCompat: settings.config.experimental.headingIdCompat,
|
||||
...settings.config.markdown
|
||||
});
|
||||
}
|
||||
const renderResult = await (await processor).render(raw.content, {
|
||||
// @ts-expect-error passing internal prop
|
||||
fileURL,
|
||||
frontmatter: raw.data
|
||||
}).catch((err) => {
|
||||
if (err instanceof InvalidAstroDataError) {
|
||||
throw new AstroError(AstroErrorData.InvalidFrontmatterInjectionError);
|
||||
}
|
||||
throw err;
|
||||
frontmatter: raw.frontmatter
|
||||
});
|
||||
if (!isFrontmatterValid(renderResult.metadata.frontmatter)) {
|
||||
throw new AstroError(AstroErrorData.InvalidFrontmatterInjectionError);
|
||||
}
|
||||
let html = renderResult.code;
|
||||
const { headings, imagePaths: rawImagePaths, frontmatter } = renderResult.metadata;
|
||||
const imagePaths = [];
|
||||
for (const imagePath of rawImagePaths.values()) {
|
||||
imagePaths.push({
|
||||
const {
|
||||
headings,
|
||||
localImagePaths: rawLocalImagePaths,
|
||||
remoteImagePaths,
|
||||
frontmatter
|
||||
} = renderResult.metadata;
|
||||
const isMarkdownPage = isPage(fileURL, settings);
|
||||
const charset = isMarkdownPage ? '<meta charset="utf-8">' : "";
|
||||
const localImagePaths = [];
|
||||
for (const imagePath of rawLocalImagePaths) {
|
||||
localImagePaths.push({
|
||||
raw: imagePath,
|
||||
safeName: shorthash(imagePath)
|
||||
});
|
||||
@@ -80,7 +89,7 @@ function markdown({ settings, logger }) {
|
||||
${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
|
||||
|
||||
${// Only include the code relevant to `astro:assets` if there's images in the file
|
||||
imagePaths.length > 0 ? getMarkdownCodeForImages(imagePaths, html) : `const html = ${JSON.stringify(html)};`}
|
||||
localImagePaths.length > 0 || remoteImagePaths.length > 0 ? getMarkdownCodeForImages(localImagePaths, remoteImagePaths, html) : `const html = () => ${JSON.stringify(html)};`}
|
||||
|
||||
export const frontmatter = ${JSON.stringify(frontmatter)};
|
||||
export const file = ${JSON.stringify(fileId)};
|
||||
@@ -88,8 +97,8 @@ function markdown({ settings, logger }) {
|
||||
export function rawContent() {
|
||||
return ${JSON.stringify(raw.content)};
|
||||
}
|
||||
export function compiledContent() {
|
||||
return html;
|
||||
export async function compiledContent() {
|
||||
return await html();
|
||||
}
|
||||
export function getHeadings() {
|
||||
return ${JSON.stringify(headings)};
|
||||
@@ -110,8 +119,8 @@ function markdown({ settings, logger }) {
|
||||
compiledContent,
|
||||
'server:root': true,
|
||||
}, {
|
||||
'default': () => render\`\${unescapeHTML(html)}\`
|
||||
})}\`;` : `render\`\${maybeRenderHead(result)}\${unescapeHTML(html)}\`;`}
|
||||
'default': () => render\`\${unescapeHTML(html())}\`
|
||||
})}\`;` : `render\`${charset}\${maybeRenderHead(result)}\${unescapeHTML(html())}\`;`}
|
||||
});
|
||||
export default Content;
|
||||
`;
|
||||
|
Reference in New Issue
Block a user