This commit is contained in:
Amir Pourmand 2025-12-14 20:59:32 +07:00 committed by GitHub
commit 03c96ca31e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 1 deletions

View File

@ -5,15 +5,18 @@ import HeaderConstructor from "../../components/Header"
import BodyConstructor from "../../components/Body" import BodyConstructor from "../../components/Body"
import { pageResources, renderPage } from "../../components/renderPage" import { pageResources, renderPage } from "../../components/renderPage"
import { FullPageLayout } from "../../cfg" import { FullPageLayout } from "../../cfg"
import { pathToRoot } from "../../util/path" import { pathToRoot, resolveRelative } from "../../util/path"
import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout" import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout"
import { Content } from "../../components" import { Content } from "../../components"
import { styleText } from "util" import { styleText } from "util"
import { write } from "./helpers" import { write } from "./helpers"
import { BuildCtx } from "../../util/ctx" import { BuildCtx } from "../../util/ctx"
import { Node } from "unist" import { Node } from "unist"
import { Root } from "hast"
import { StaticResources } from "../../util/resources" import { StaticResources } from "../../util/resources"
import { QuartzPluginData } from "../vfile" import { QuartzPluginData } from "../vfile"
import { visit } from "unist-util-visit"
import { RelativeURL } from "../../util/path"
async function processContent( async function processContent(
ctx: BuildCtx, ctx: BuildCtx,
@ -25,6 +28,38 @@ async function processContent(
) { ) {
const slug = fileData.slug! const slug = fileData.slug!
const cfg = ctx.cfg.configuration const cfg = ctx.cfg.configuration
const allSlugs = allFiles.map((f) => (f.slug ? resolveRelative(slug, f.slug) : ""))
visit(tree as Root, "element", (elem) => {
if (elem.tagName === "a" && elem.properties.href) {
const href = elem.properties.href.toString()
if (href.startsWith("#")) {
return
}
if (!allSlugs.includes(href as RelativeURL)) {
if (elem.properties.className === undefined) {
elem.properties.className = "dead-link"
} else if (Array.isArray(elem.properties.className)) {
if (elem.properties.className.includes("external")) {
return
}
elem.properties.className.push("dead-link")
} else if (typeof elem.properties.className === "string") {
if (elem.properties.className.includes("external")) {
return
}
elem.properties.className += " dead-link"
} else {
return
}
elem.tagName = "span"
}
}
})
const externalResources = pageResources(pathToRoot(slug), resources) const externalResources = pageResources(pathToRoot(slug), resources)
const componentData: QuartzComponentProps = { const componentData: QuartzComponentProps = {
ctx, ctx,

View File

@ -1,3 +1,15 @@
@use "./base.scss"; @use "./base.scss";
// put your custom CSS here! // put your custom CSS here!
// Dead link styling - links to missing pages
.dead-link {
font-weight: 600;
text-decoration: none;
transition: color 0.2s ease;
color: #d97706;
background-color: var(--lightgray);
padding: 0 0.1rem;
border-radius: 5px;
line-height: 1.4rem;
cursor: default;
}