• オプションで出力対象パスを指定できるように修正(2023-11-09)
    • quartz.config.tsでrssPathに’blog’を指定し、通常のノートはRSS出力しないように
  • Quartz v4.1.0のRSSフィードが古いコンテンツ順に出力されてしまうので、新しい順に出力するように修正

以下は現時点(2023-11-09)の本家最新版(ab5efac75fb0f20afe74bef33a2cf7e9ba0ba40f)との差分。

diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts
index 69d0d37..5acb246 100644
--- a/quartz/plugins/emitters/contentIndex.ts
+++ b/quartz/plugins/emitters/contentIndex.ts
@@ -22,6 +22,7 @@ interface Options {
   enableSiteMap: boolean
   enableRSS: boolean
   rssLimit?: number
+  rssPath?: string
   rssFullHtml: boolean
   includeEmptyFiles: boolean
 }
@@ -30,6 +31,7 @@ const defaultOptions: Options = {
   enableSiteMap: true,
   enableRSS: true,
   rssLimit: 10,
+  rssPath: undefined, 
   rssFullHtml: false,
   includeEmptyFiles: true,
 }
@@ -46,7 +48,7 @@ function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string {
   return `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${urls}</urlset>`
 }
 
-function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number): string {
+function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: number, rssPath?: string): string {
   const base = cfg.baseUrl ?? ""
   const root = `https://${base}`
 
@@ -58,7 +60,14 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
     <pubDate>${content.date?.toUTCString()}</pubDate>
   </item>`
 
-  const items = Array.from(idx)
+  const sortedEntries = Array.from(idx)
+    .sort(([, contentA], [, contentB]) => {
+      if (!contentA.date || !contentB.date) return 0;
+      return contentB.date.getTime() - contentA.date.getTime();  
+    });
+
+  const items = sortedEntries
+    .filter(([slug]) => !rssPath || slug.includes(rssPath + '/')) 
     .map(([slug, content]) => createURLEntry(simplifySlug(slug), content))
     .slice(0, limit ?? idx.size)
     .join("")
@@ -116,7 +125,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
       if (opts?.enableRSS) {
         emitted.push(
           await emit({
-            content: generateRSSFeed(cfg, linkIndex, opts.rssLimit),
+            content: generateRSSFeed(cfg, linkIndex, opts.rssLimit, opts.rssPath),
             slug: "index" as FullSlug,
             ext: ".xml",
           }),