mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-30 16:24:06 -06:00
feat: remove html from description
This commit is contained in:
parent
a6711364f2
commit
2cdf880e59
@ -7,6 +7,7 @@ import { ImageOptions, getSatoriFont } from "../util/imageHelper"
|
|||||||
import sharp from "sharp"
|
import sharp from "sharp"
|
||||||
import { defaultImage } from "../util/defaultImage"
|
import { defaultImage } from "../util/defaultImage"
|
||||||
import { JSXInternal } from "preact/src/jsx"
|
import { JSXInternal } from "preact/src/jsx"
|
||||||
|
import { unescapeHTML } from "../util/escape"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates social image (OG/twitter standard) and saves it as `.web` inside the public folder
|
* Generates social image (OG/twitter standard) and saves it as `.web` inside the public folder
|
||||||
@ -37,7 +38,7 @@ async function generateSocialImage(opts: ImageOptions) {
|
|||||||
fs.writeFileSync(`${imageDir}/${fileName}.${extension}`, compressed)
|
fs.writeFileSync(`${imageDir}/${fileName}.${extension}`, compressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove html from description
|
// TODO: mention `description` plugin in docs for max length
|
||||||
// TODO: add to config and use in generateSocialImage
|
// TODO: add to config and use in generateSocialImage
|
||||||
// Social image defaults
|
// Social image defaults
|
||||||
const ogHeight = 1200
|
const ogHeight = 1200
|
||||||
@ -57,7 +58,11 @@ export default (() => {
|
|||||||
const title = fileData.frontmatter?.title ?? "Untitled"
|
const title = fileData.frontmatter?.title ?? "Untitled"
|
||||||
|
|
||||||
// Get file description (priority: frontmatter > fileData > default)
|
// Get file description (priority: frontmatter > fileData > default)
|
||||||
let description = fileData.description?.trim() ?? "No description provided"
|
const fdDescription = fileData.description?.trim()
|
||||||
|
let description = ""
|
||||||
|
if (fdDescription) {
|
||||||
|
description = unescapeHTML(fdDescription)
|
||||||
|
}
|
||||||
if (fileData.frontmatter?.socialDescription) {
|
if (fileData.frontmatter?.socialDescription) {
|
||||||
description = fileData.frontmatter.socialDescription
|
description = fileData.frontmatter.socialDescription
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,3 +6,12 @@ export const escapeHTML = (unsafe: string) => {
|
|||||||
.replaceAll('"', """)
|
.replaceAll('"', """)
|
||||||
.replaceAll("'", "'")
|
.replaceAll("'", "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const unescapeHTML = (html: string) => {
|
||||||
|
return html
|
||||||
|
.replaceAll("&", "&")
|
||||||
|
.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">")
|
||||||
|
.replaceAll(""", '"')
|
||||||
|
.replaceAll("'", "'")
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user