fix: escape for seo meta tags

close #1232
This commit is contained in:
Stephen Zhou 2024-10-30 11:20:38 +08:00
parent d4d43451de
commit 9564257564
No known key found for this signature in database
1 changed files with 19 additions and 1 deletions

View File

@ -1,3 +1,17 @@
function escapeHtml(unsafe?: string | null) {
if (!unsafe) {
return unsafe
}
return unsafe
.replaceAll("&", "&")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#x27;")
.replaceAll("/", "&#x2F;")
}
export function buildSeoMetaTags(configs: {
openGraph: {
title: string
@ -5,7 +19,11 @@ export function buildSeoMetaTags(configs: {
image?: string | null
}
}) {
const { openGraph } = configs
const openGraph = {
title: escapeHtml(configs.openGraph.title),
description: escapeHtml(configs.openGraph.description),
image: escapeHtml(configs.openGraph.image),
}
const title = `${openGraph.title} | Follow`
return [
`<meta property="og:title" content="${title}" />`,