Jacky Zhao
2023-07-01 4c904d88aba14d0d153bfac364630ad61832a73d
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('.')