feat: rich html rss (closes #460)
This commit is contained in:
		
							parent
							
								
									60a3c54339
								
							
						
					
					
						commit
						e3b879741b
					
				
					 2 changed files with 11 additions and 3 deletions
				
			
		| 
						 | 
					@ -3,3 +3,5 @@ Quartz creates an RSS feed for all the content on your site by generating an `in
 | 
				
			||||||
## Configuration
 | 
					## Configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Remove RSS feed: set the `enableRSS` field of `Plugin.ContentIndex` in `quartz.config.ts` to be `false`.
 | 
					- Remove RSS feed: set the `enableRSS` field of `Plugin.ContentIndex` in `quartz.config.ts` to be `false`.
 | 
				
			||||||
 | 
					- Change number of entries: set the `rssLimit` field of `Plugin.ContentIndex` to be the desired value. It defaults to latest 10 items.
 | 
				
			||||||
 | 
					- Use rich HTML output in RSS: set `rssFullHtml` field of `Plugin.ContentIndex` to be `true`.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,10 @@
 | 
				
			||||||
 | 
					import { Root } from "hast"
 | 
				
			||||||
import { GlobalConfiguration } from "../../cfg"
 | 
					import { GlobalConfiguration } from "../../cfg"
 | 
				
			||||||
import { getDate } from "../../components/Date"
 | 
					import { getDate } from "../../components/Date"
 | 
				
			||||||
import { escapeHTML } from "../../util/escape"
 | 
					import { escapeHTML } from "../../util/escape"
 | 
				
			||||||
import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path"
 | 
					import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path"
 | 
				
			||||||
import { QuartzEmitterPlugin } from "../types"
 | 
					import { QuartzEmitterPlugin } from "../types"
 | 
				
			||||||
 | 
					import { toHtml } from "hast-util-to-html"
 | 
				
			||||||
import path from "path"
 | 
					import path from "path"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ContentIndex = Map<FullSlug, ContentDetails>
 | 
					export type ContentIndex = Map<FullSlug, ContentDetails>
 | 
				
			||||||
| 
						 | 
					@ -19,6 +21,7 @@ interface Options {
 | 
				
			||||||
  enableSiteMap: boolean
 | 
					  enableSiteMap: boolean
 | 
				
			||||||
  enableRSS: boolean
 | 
					  enableRSS: boolean
 | 
				
			||||||
  rssLimit?: number
 | 
					  rssLimit?: number
 | 
				
			||||||
 | 
					  rssFullHtml: boolean
 | 
				
			||||||
  includeEmptyFiles: boolean
 | 
					  includeEmptyFiles: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +29,7 @@ const defaultOptions: Options = {
 | 
				
			||||||
  enableSiteMap: true,
 | 
					  enableSiteMap: true,
 | 
				
			||||||
  enableRSS: true,
 | 
					  enableRSS: true,
 | 
				
			||||||
  rssLimit: 10,
 | 
					  rssLimit: 10,
 | 
				
			||||||
 | 
					  rssFullHtml: false,
 | 
				
			||||||
  includeEmptyFiles: true,
 | 
					  includeEmptyFiles: true,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,7 +53,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
 | 
				
			||||||
    <title>${escapeHTML(content.title)}</title>
 | 
					    <title>${escapeHTML(content.title)}</title>
 | 
				
			||||||
    <link>${root}/${encodeURI(slug)}</link>
 | 
					    <link>${root}/${encodeURI(slug)}</link>
 | 
				
			||||||
    <guid>${root}/${encodeURI(slug)}</guid>
 | 
					    <guid>${root}/${encodeURI(slug)}</guid>
 | 
				
			||||||
    <description>${content.description}</description>
 | 
					    <description>${content.content}</description>
 | 
				
			||||||
    <pubDate>${content.date?.toUTCString()}</pubDate>
 | 
					    <pubDate>${content.date?.toUTCString()}</pubDate>
 | 
				
			||||||
  </item>`
 | 
					  </item>`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,7 +84,7 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
				
			||||||
      const cfg = ctx.cfg.configuration
 | 
					      const cfg = ctx.cfg.configuration
 | 
				
			||||||
      const emitted: FilePath[] = []
 | 
					      const emitted: FilePath[] = []
 | 
				
			||||||
      const linkIndex: ContentIndex = new Map()
 | 
					      const linkIndex: ContentIndex = new Map()
 | 
				
			||||||
      for (const [_tree, file] of content) {
 | 
					      for (const [tree, file] of content) {
 | 
				
			||||||
        const slug = file.data.slug!
 | 
					        const slug = file.data.slug!
 | 
				
			||||||
        const date = getDate(ctx.cfg.configuration, file.data) ?? new Date()
 | 
					        const date = getDate(ctx.cfg.configuration, file.data) ?? new Date()
 | 
				
			||||||
        if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
 | 
					        if (opts?.includeEmptyFiles || (file.data.text && file.data.text !== "")) {
 | 
				
			||||||
| 
						 | 
					@ -88,7 +92,9 @@ export const ContentIndex: QuartzEmitterPlugin<Partial<Options>> = (opts) => {
 | 
				
			||||||
            title: file.data.frontmatter?.title!,
 | 
					            title: file.data.frontmatter?.title!,
 | 
				
			||||||
            links: file.data.links ?? [],
 | 
					            links: file.data.links ?? [],
 | 
				
			||||||
            tags: file.data.frontmatter?.tags ?? [],
 | 
					            tags: file.data.frontmatter?.tags ?? [],
 | 
				
			||||||
            content: file.data.text ?? "",
 | 
					            content: opts?.rssFullHtml
 | 
				
			||||||
 | 
					              ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true }))
 | 
				
			||||||
 | 
					              : file.data.description ?? "",
 | 
				
			||||||
            date: date,
 | 
					            date: date,
 | 
				
			||||||
            description: file.data.description ?? "",
 | 
					            description: file.data.description ?? "",
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue