mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-26 22:34:06 -06:00
Update Head.tsx
This commit is contained in:
parent
b8e5064460
commit
bfc3053664
@ -1,7 +1,7 @@
|
|||||||
import { i18n } from "../i18n"
|
import { i18n } from "../i18n"
|
||||||
import { FullSlug, joinSegments, pathToRoot } from "../util/path"
|
import { FullSlug, joinSegments, pathToRoot } from "../util/path"
|
||||||
import { CSSResourceToStyleElement, JSResourceToScriptElement } from "../util/resources"
|
import { CSSResourceToStyleElement, JSResourceToScriptElement } from "../util/resources"
|
||||||
import { getFontSpecificationName, googleFontHref } from "../util/theme"
|
import { getFontSpecificationName, googleFontHref } from "../util/theme"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import satori, { SatoriOptions } from "satori"
|
import satori, { SatoriOptions } from "satori"
|
||||||
import { loadEmoji, getIconCode } from "../util/emoji"
|
import { loadEmoji, getIconCode } from "../util/emoji"
|
||||||
@ -29,7 +29,7 @@ async function generateSocialImage(
|
|||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
fonts,
|
fonts,
|
||||||
loadAdditionalAsset: async (languageCode: string, segment: string) => {
|
loadAdditionalAsset: async (languageCode: string, segment: string) => {
|
||||||
if (languageCode === "emoji") {
|
if (languageCode === "emoji") {
|
||||||
return `data:image/svg+xml;base64,${btoa(await loadEmoji(getIconCode(segment)))}`
|
return `data:image/svg+xml;base64,${btoa(await loadEmoji(getIconCode(segment)))}`
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ export default (() => {
|
|||||||
fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description
|
fileData.description?.trim() ?? i18n(cfg.locale).propertyDefaults.description
|
||||||
const titleSuffix = cfg.pageTitleSuffix ?? ""
|
const titleSuffix = cfg.pageTitleSuffix ?? ""
|
||||||
const title =
|
const title =
|
||||||
(fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title) + titleSuffix
|
(fileData.frontmatter?.title ?? i18n(cfg.locale).propertyDefaults.title) + titleSuffix
|
||||||
let description = ""
|
let description = ""
|
||||||
if (fdDescription) {
|
if (fdDescription) {
|
||||||
description = unescapeHTML(fdDescription)
|
description = unescapeHTML(fdDescription)
|
||||||
@ -132,7 +132,7 @@ export default (() => {
|
|||||||
const { css, js, additionalHead } = externalResources
|
const { css, js, additionalHead } = externalResources
|
||||||
|
|
||||||
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
||||||
const path = url.pathname as FullSlug
|
const path = url.pathname as FullSlug
|
||||||
const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!)
|
const baseDir = fileData.slug === "404" ? path : pathToRoot(fileData.slug!)
|
||||||
|
|
||||||
const iconPath = joinSegments(baseDir, "static/icon.png")
|
const iconPath = joinSegments(baseDir, "static/icon.png")
|
||||||
@ -145,7 +145,7 @@ export default (() => {
|
|||||||
)}/${fileName}.${extension}`
|
)}/${fileName}.${extension}`
|
||||||
|
|
||||||
// Use default og image if filePath doesnt exist (for autogenerated paths with no .md file)
|
// Use default og image if filePath doesnt exist (for autogenerated paths with no .md file)
|
||||||
const useDefaultOgImage = fileName === undefined || !cfg.generateSocialImages
|
const useDefaultOgImage = fileName === undefined || !cfg.generateSocialImages
|
||||||
|
|
||||||
// Path to og/social image (priority: frontmatter > generated image (if enabled) > default image)
|
// Path to og/social image (priority: frontmatter > generated image (if enabled) > default image)
|
||||||
let ogImagePath = useDefaultOgImage ? ogImageDefaultPath : ogImageGeneratedPath
|
let ogImagePath = useDefaultOgImage ? ogImageDefaultPath : ogImageGeneratedPath
|
||||||
@ -155,30 +155,29 @@ export default (() => {
|
|||||||
const frontmatterImgUrl = fileData.frontmatter?.socialImage
|
const frontmatterImgUrl = fileData.frontmatter?.socialImage
|
||||||
|
|
||||||
// Override with default og image if config option is set
|
// Override with default og image if config option is set
|
||||||
if (fileData.slug === "index") {
|
if (fileData.slug === "index") {
|
||||||
ogImagePath = ogImageDefaultPath
|
ogImagePath = ogImageDefaultPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override with frontmatter url if existing
|
// Override with frontmatter url if existing
|
||||||
if (frontmatterImgUrl) {
|
if (frontmatterImgUrl) {
|
||||||
ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}`
|
ogImagePath = `https://${cfg.baseUrl}/static/${frontmatterImgUrl}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Url of current page
|
// Url of current page
|
||||||
const socialUrl =
|
const socialUrl =
|
||||||
fileData.slug === "404" ? url.toString() : joinSegments(url.toString(), fileData.slug!)
|
fileData.slug === "404" ? url.toString() : joinSegments(url.toString(), fileData.slug!)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<head>
|
<head>
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
<meta charSet="utf-8" />
|
<meta charSet="utf-8" />
|
||||||
{cfg.theme.cdnCaching && cfg.theme.fontOrigin === "local" && (
|
{cfg.theme.cdnCaching && cfg.theme.fontOrigin === "local" && (
|
||||||
<>
|
<>
|
||||||
<link rel="preconnect" href="https://cdn.jsdelivr.net" />
|
<link rel="preconnect" href="https://cdn.staticfile.org" />
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lxgw-wenkai-lite-webfont@1.1.0/style.css" />
|
<link rel="stylesheet" href="https://cdn.staticfile.org/lxgw-wenkai-webfont/1.7.0/style.css" />
|
||||||
</>
|
</>
|
||||||
)}
|
{cfg.theme.cdnCaching && cfg.theme.fontOrigin === "googleFonts" && (
|
||||||
{cfg.theme.cdnCaching && cfg.theme.fontOrigin === "googleFonts" && (
|
|
||||||
<>
|
<>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
||||||
@ -191,7 +190,7 @@ export default (() => {
|
|||||||
<meta name="og:site_name" content={cfg.pageTitle}></meta>
|
<meta name="og:site_name" content={cfg.pageTitle}></meta>
|
||||||
<meta property="og:title" content={title} />
|
<meta property="og:title" content={title} />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
<meta name="twitter:title" content={title} />
|
<meta name="twitter:title" content={title} />
|
||||||
<meta name="twitter:description" content={description} />
|
<meta name="twitter:description" content={description} />
|
||||||
<meta property="og:description" content={description} />
|
<meta property="og:description" content={description} />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user