From 4c904d88aba14d0d153bfac364630ad61832a73d Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sat, 01 Jul 2023 20:35:27 +0000
Subject: [PATCH] rss + sitemap

---
 quartz/plugins/transformers/description.ts |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/quartz/plugins/transformers/description.ts b/quartz/plugins/transformers/description.ts
index 0e41c5b..cc20769 100644
--- a/quartz/plugins/transformers/description.ts
+++ b/quartz/plugins/transformers/description.ts
@@ -10,6 +10,10 @@
   descriptionLength: 150
 }
 
+const escapeHTML = (unsafe: string) => {
+  return unsafe.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
+}
+
 export const Description: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
   const opts = { ...defaultOptions, ...userOpts }
   return {
@@ -19,7 +23,7 @@
         () => {
           return async (tree: HTMLRoot, file) => {
             const frontMatterDescription = file.data.frontmatter?.description
-            const text = toString(tree)
+            const text = escapeHTML(toString(tree))
 
             const desc = frontMatterDescription ?? text
             const sentences = desc.replace(/\s+/g, ' ').split('.')

--
Gitblit v1.10.0