rss + sitemap

This commit is contained in:
Jacky Zhao 2023-07-01 13:35:27 -07:00
parent ba9f243728
commit 4c904d88ab
11 changed files with 131 additions and 491 deletions
quartz/plugins/transformers

View file

@ -10,6 +10,10 @@ const defaultOptions: Options = {
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 @@ export const Description: QuartzTransformerPlugin<Partial<Options> | undefined>
() => {
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('.')