9c322802fa
* Adding PWA and chaching for offline aviability * renamed workbox config to fit Quartz' scheme * Documenting new configuration * Added missig umami documentation * Fixed formatting so the build passes, thank you prettier :) * specified caching strategies to improve performance * formatting... * fixing "404 manifest.json not found" on subdirectories by adding a / to manifestpath * turning it into a plugin * Removed Workbox-cli and updated @types/node * Added Serviceworkercode to offline.ts * formatting * Removing workbox from docs * applied suggestions * Removed path.join for sw path Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * Removed path.join for manifest path Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * Removing path module import * Added absolute path to manifests start_url and manifest "import" using baseUrl * Adding protocol to baseurl Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * Adding protocol to start_url too then * formatting... * Adding fallback page * Documenting offline plugin * formatting... * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * merge suggestion Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com> * formatting... * Fixing manifest path, all these nits hiding the actual issues .-. * Offline fallback page through plugins, most things taken from 404 Plugin * adding Offline Plugin to config * formatting... * Turned offline off as default and removed offline.md --------- Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import { FullSlug, _stripSlashes, joinSegments, pathToRoot } from "../util/path"
|
|
import { JSResourceToScriptElement } from "../util/resources"
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
|
|
|
export default (() => {
|
|
function Head({ cfg, fileData, externalResources }: QuartzComponentProps) {
|
|
const title = fileData.frontmatter?.title ?? "Untitled"
|
|
const description = fileData.description?.trim() ?? "No description provided"
|
|
const { css, js } = externalResources
|
|
|
|
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`
|
|
const manifest =
|
|
cfg.baseUrl == undefined ? "/manifest.json" : `https://${cfg.baseUrl}/manifest.json`
|
|
|
|
return (
|
|
<head>
|
|
<title>{title}</title>
|
|
<meta charSet="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta property="og:title" content={title} />
|
|
<meta property="og:description" content={description} />
|
|
{cfg.baseUrl && <meta property="og:image" content={ogImagePath} />}
|
|
<meta property="og:width" content="1200" />
|
|
<meta property="og:height" content="675" />
|
|
<meta name="theme-color" content="#faf8f8" />
|
|
<link rel="icon" href={iconPath} />
|
|
<link rel="manifest" href={manifest} />
|
|
<meta name="description" content={description} />
|
|
<meta name="generator" content="Quartz" />
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
|
{css.map((href) => (
|
|
<link key={href} href={href} rel="stylesheet" type="text/css" spa-preserve />
|
|
))}
|
|
{js
|
|
.filter((resource) => resource.loadTime === "beforeDOMReady")
|
|
.map((res) => JSResourceToScriptElement(res, true))}
|
|
</head>
|
|
)
|
|
}
|
|
|
|
return Head
|
|
}) satisfies QuartzComponentConstructor
|