Compare commits

...

1 Commits

Author SHA1 Message Date
Aaron
a86c981e05
feat(preview): manual disabled given files
Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
2024-02-11 09:55:06 -05:00
3 changed files with 16 additions and 2 deletions

View File

@ -213,7 +213,10 @@ export function renderPage(
const doc = ( const doc = (
<html lang={lang}> <html lang={lang}>
<Head {...componentData} /> <Head {...componentData} />
<body data-slug={slug}> <body
data-slug={slug}
data-enable-preview={componentData.fileData.frontmatter?.preview ?? true}
>
<div id="quartz-root" class="page"> <div id="quartz-root" class="page">
<Body {...componentData}> <Body {...componentData}>
{LeftComponent} {LeftComponent}

View File

@ -51,7 +51,13 @@ async function mouseEnterHandler(
if (!contents) return if (!contents) return
const html = p.parseFromString(contents, "text/html") const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, targetUrl) normalizeRelativeURLs(html, targetUrl)
const elts = [...html.getElementsByClassName("popover-hint")] let elts: Element[]
if (html.body.dataset.enablePreview === "false") {
const noPreview = document.createElement("div")
noPreview.innerHTML = `<p>Preview is disabled for this page.</p>`
elts = [noPreview]
} else elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return if (elts.length === 0) return
const popoverElement = document.createElement("div") const popoverElement = document.createElement("div")

View File

@ -371,6 +371,11 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
throw new Error(`Could not fetch ${targetUrl}`) throw new Error(`Could not fetch ${targetUrl}`)
} }
const html = p.parseFromString(contents ?? "", "text/html") const html = p.parseFromString(contents ?? "", "text/html")
if (html.body.dataset.enablePreview === "false") {
const noPreview = document.createElement("div")
noPreview.innerHTML = `<p>Preview is disabled for this page.</p>`
return [noPreview]
}
normalizeRelativeURLs(html, targetUrl) normalizeRelativeURLs(html, targetUrl)
return [...html.getElementsByClassName("popover-hint")] return [...html.getElementsByClassName("popover-hint")]
}) })