feat: remove html from description

This commit is contained in:
Ben Schlegel 2023-09-29 12:49:28 +02:00
parent a6711364f2
commit 2cdf880e59
No known key found for this signature in database
GPG Key ID: 8BDB8891C1575E22
2 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import { ImageOptions, getSatoriFont } from "../util/imageHelper"
import sharp from "sharp"
import { defaultImage } from "../util/defaultImage"
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
@ -37,7 +38,7 @@ async function generateSocialImage(opts: ImageOptions) {
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
// Social image defaults
const ogHeight = 1200
@ -57,7 +58,11 @@ export default (() => {
const title = fileData.frontmatter?.title ?? "Untitled"
// 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) {
description = fileData.frontmatter.socialDescription
}

View File

@ -6,3 +6,12 @@ export const escapeHTML = (unsafe: string) => {
.replaceAll('"', """)
.replaceAll("'", "'")
}
export const unescapeHTML = (html: string) => {
return html
.replaceAll("&", "&")
.replaceAll("&lt;", "<")
.replaceAll("&gt;", ">")
.replaceAll("&quot;", '"')
.replaceAll("&#039;", "'")
}