fix: 404 page styling for nested pages (closes #458)
| | |
| | | import { joinSegments, pathToRoot } from "../util/path" |
| | | import { FullSlug, _stripSlashes, joinSegments, pathToRoot } from "../util/path" |
| | | import { JSResourceToScriptElement } from "../util/resources" |
| | | import { QuartzComponentConstructor, QuartzComponentProps } from "./types" |
| | | |
| | |
| | | const title = fileData.frontmatter?.title ?? "Untitled" |
| | | const description = fileData.description?.trim() ?? "No description provided" |
| | | const { css, js } = externalResources |
| | | const baseDir = pathToRoot(fileData.slug!) |
| | | |
| | | const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) |
| | | const path = url.pathname as FullSlug |
| | | const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!) |
| | | |
| | | const iconPath = joinSegments(baseDir, "static/icon.png") |
| | | const ogImagePath = `https://${cfg.baseUrl}/static/og-image.png` |
| | | |
| | |
| | | import HeaderConstructor from "./Header" |
| | | import BodyConstructor from "./Body" |
| | | import { JSResourceToScriptElement, StaticResources } from "../util/resources" |
| | | import { FullSlug, joinSegments, pathToRoot } from "../util/path" |
| | | import { FullSlug, RelativeURL, joinSegments } from "../util/path" |
| | | |
| | | interface RenderComponents { |
| | | head: QuartzComponent |
| | |
| | | footer: QuartzComponent |
| | | } |
| | | |
| | | export function pageResources(slug: FullSlug, staticResources: StaticResources): StaticResources { |
| | | const baseDir = pathToRoot(slug) |
| | | |
| | | export function pageResources( |
| | | baseDir: FullSlug | RelativeURL, |
| | | staticResources: StaticResources, |
| | | ): StaticResources { |
| | | const contentIndexPath = joinSegments(baseDir, "static/contentIndex.json") |
| | | const contentIndexScript = `const fetchData = fetch(\`${contentIndexPath}\`).then(data => data.json())` |
| | | |
| | |
| | | async emit(ctx, _content, resources, emit): Promise<FilePath[]> { |
| | | const cfg = ctx.cfg.configuration |
| | | const slug = "404" as FullSlug |
| | | const externalResources = pageResources(slug, resources) |
| | | |
| | | const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) |
| | | const path = url.pathname as FullSlug |
| | | const externalResources = pageResources(path, resources) |
| | | const [tree, vfile] = defaultProcessedContent({ |
| | | slug, |
| | | text: "Not Found", |
| | |
| | | import BodyConstructor from "../../components/Body" |
| | | import { pageResources, renderPage } from "../../components/renderPage" |
| | | import { FullPageLayout } from "../../cfg" |
| | | import { FilePath } from "../../util/path" |
| | | import { FilePath, pathToRoot } from "../../util/path" |
| | | import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout" |
| | | import { Content } from "../../components" |
| | | |
| | |
| | | const allFiles = content.map((c) => c[1].data) |
| | | for (const [tree, file] of content) { |
| | | const slug = file.data.slug! |
| | | const externalResources = pageResources(slug, resources) |
| | | const externalResources = pageResources(pathToRoot(slug), resources) |
| | | const componentData: QuartzComponentProps = { |
| | | fileData: file.data, |
| | | externalResources, |
| | |
| | | SimpleSlug, |
| | | _stripSlashes, |
| | | joinSegments, |
| | | pathToRoot, |
| | | simplifySlug, |
| | | } from "../../util/path" |
| | | import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout" |
| | |
| | | |
| | | for (const folder of folders) { |
| | | const slug = joinSegments(folder, "index") as FullSlug |
| | | const externalResources = pageResources(slug, resources) |
| | | const externalResources = pageResources(pathToRoot(slug), resources) |
| | | const [tree, file] = folderDescriptions[folder] |
| | | const componentData: QuartzComponentProps = { |
| | | fileData: file.data, |
| | |
| | | import { pageResources, renderPage } from "../../components/renderPage" |
| | | import { ProcessedContent, defaultProcessedContent } from "../vfile" |
| | | import { FullPageLayout } from "../../cfg" |
| | | import { FilePath, FullSlug, getAllSegmentPrefixes, joinSegments } from "../../util/path" |
| | | import { |
| | | FilePath, |
| | | FullSlug, |
| | | getAllSegmentPrefixes, |
| | | joinSegments, |
| | | pathToRoot, |
| | | } from "../../util/path" |
| | | import { defaultListPageLayout, sharedPageComponents } from "../../../quartz.layout" |
| | | import { TagContent } from "../../components" |
| | | |
| | |
| | | |
| | | for (const tag of tags) { |
| | | const slug = joinSegments("tags", tag) as FullSlug |
| | | const externalResources = pageResources(slug, resources) |
| | | const externalResources = pageResources(pathToRoot(slug), resources) |
| | | const [tree, file] = tagDescriptions[tag] |
| | | const componentData: QuartzComponentProps = { |
| | | fileData: file.data, |
| | |
| | | } |
| | | |
| | | export function joinSegments(...args: string[]): string { |
| | | return args.filter((segment) => segment !== "").join("/") |
| | | return args |
| | | .filter((segment) => segment !== "") |
| | | .join("/") |
| | | .replace(/\/\/+/g, "/") |
| | | } |
| | | |
| | | export function getAllSegmentPrefixes(tags: string): string[] { |