| | |
| | | import { visit } from "unist-util-visit" |
| | | import { Root, Element, ElementContent } from "hast" |
| | | import { QuartzPluginData } from "../plugins/vfile" |
| | | import { GlobalConfiguration } from "../cfg" |
| | | import { i18n } from "../i18n" |
| | | |
| | | interface RenderComponents { |
| | | head: QuartzComponent |
| | |
| | | staticResources: StaticResources, |
| | | ): StaticResources { |
| | | const contentIndexPath = joinSegments(baseDir, "static/contentIndex.json") |
| | | const contentIndexScript = `const fetchData = fetch(\`${contentIndexPath}\`).then(data => data.json())` |
| | | const contentIndexScript = `const fetchData = fetch("${contentIndexPath}").then(data => data.json())` |
| | | |
| | | return { |
| | | css: [joinSegments(baseDir, "index.css"), ...staticResources.css], |
| | |
| | | } |
| | | |
| | | export function renderPage( |
| | | cfg: GlobalConfiguration, |
| | | slug: FullSlug, |
| | | componentData: QuartzComponentProps, |
| | | components: RenderComponents, |
| | |
| | | { |
| | | type: "element", |
| | | tagName: "a", |
| | | properties: { href: inner.properties?.href, class: ["internal"] }, |
| | | children: [{ type: "text", value: `Link to original` }], |
| | | properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, |
| | | children: [ |
| | | { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, |
| | | ], |
| | | }, |
| | | ] |
| | | } |
| | |
| | | { |
| | | type: "element", |
| | | tagName: "a", |
| | | properties: { href: inner.properties?.href, class: ["internal"] }, |
| | | children: [{ type: "text", value: `Link to original` }], |
| | | properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, |
| | | children: [ |
| | | { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, |
| | | ], |
| | | }, |
| | | ] |
| | | } else if (page.htmlAst) { |
| | |
| | | tagName: "h1", |
| | | properties: {}, |
| | | children: [ |
| | | { type: "text", value: page.frontmatter?.title ?? `Transclude of ${page.slug}` }, |
| | | { |
| | | type: "text", |
| | | value: |
| | | page.frontmatter?.title ?? |
| | | i18n(cfg.locale).components.transcludes.transcludeOf({ |
| | | targetSlug: page.slug!, |
| | | }), |
| | | }, |
| | | ], |
| | | }, |
| | | ...(page.htmlAst.children as ElementContent[]).map((child) => |
| | |
| | | { |
| | | type: "element", |
| | | tagName: "a", |
| | | properties: { href: inner.properties?.href, class: ["internal"] }, |
| | | children: [{ type: "text", value: `Link to original` }], |
| | | properties: { href: inner.properties?.href, class: ["internal", "transclude-src"] }, |
| | | children: [ |
| | | { type: "text", value: i18n(cfg.locale).components.transcludes.linkToOriginal }, |
| | | ], |
| | | }, |
| | | ] |
| | | } |
| | |
| | | </div> |
| | | ) |
| | | |
| | | const lang = componentData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en" |
| | | const doc = ( |
| | | <html> |
| | | <html lang={lang}> |
| | | <Head {...componentData} /> |
| | | <body data-slug={slug}> |
| | | <div id="quartz-root" class="page"> |