From e3b879741b6d32f56e1d1bfd0bac57f0d68c1113 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 13 Sep 2023 04:44:03 +0000
Subject: [PATCH] feat: rich html rss (closes #460)

---
 quartz/plugins/emitters/contentIndex.ts |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts
index bcb1e30..102394c 100644
--- a/quartz/plugins/emitters/contentIndex.ts
+++ b/quartz/plugins/emitters/contentIndex.ts
@@ -1,8 +1,10 @@
+import { Root } from "hast"
 import { GlobalConfiguration } from "../../cfg"
 import { getDate } from "../../components/Date"
 import { escapeHTML } from "../../util/escape"
 import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path"
 import { QuartzEmitterPlugin } from "../types"
+import { toHtml } from "hast-util-to-html"
 import path from "path"
 
 export type ContentIndex = Map<FullSlug, ContentDetails>
@@ -19,6 +21,7 @@
   enableSiteMap: boolean
   enableRSS: boolean
   rssLimit?: number
+  rssFullHtml: boolean
   includeEmptyFiles: boolean
 }
 
@@ -26,6 +29,7 @@
   enableSiteMap: true,
   enableRSS: true,
   rssLimit: 10,
+  rssFullHtml: false,
   includeEmptyFiles: true,
 }
 
@@ -49,7 +53,7 @@
     <title>${escapeHTML(content.title)}</title>
     <link>${root}/${encodeURI(slug)}</link>
     <guid>${root}/${encodeURI(slug)}</guid>
-    <description>${content.description}</description>
+    <description>${content.content}</description>
     <pubDate>${content.date?.toUTCString()}</pubDate>
   </item>`
 
@@ -80,7 +84,7 @@
       const cfg = ctx.cfg.configuration
       const emitted: FilePath[] = []
       const linkIndex: ContentIndex = new Map()
-      for (const [_tree, file] of content) {
+      for (const [tree, file] of content) {
         const slug = file.data.slug!
         const date = getDate(ctx.cfg.configuration, file.data) ?? new Date()
         if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
@@ -88,7 +92,9 @@
             title: file.data.frontmatter?.title!,
             links: file.data.links ?? [],
             tags: file.data.frontmatter?.tags ?? [],
-            content: file.data.text ?? "",
+            content: opts?.rssFullHtml
+              ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
+              : file.data.description ?? "",
             date: date,
             description: file.data.description ?? "",
           })

--
Gitblit v1.10.0