Jacky Zhao
2023-06-12 352075ae81a3304a7bfa2512ef69b1cdacb26c12
quartz/plugins/transformers/description.ts
@@ -1,4 +1,3 @@
import { PluggableList } from "unified"
import { Root as HTMLRoot } from 'hast'
import { toString } from "hast-util-to-string"
import { QuartzTransformerPlugin } from "../types"
@@ -11,20 +10,14 @@
  descriptionLength: 150
}
export class Description extends QuartzTransformerPlugin {
  name = "Description"
  opts: Options
  constructor(opts?: Partial<Options>) {
    super()
    this.opts = { ...defaultOptions, ...opts }
  }
  markdownPlugins(): PluggableList {
export const Description: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => {
  const opts = { ...defaultOptions, ...userOpts }
  return {
    name: "Description",
    markdownPlugins() {
    return []
  }
  htmlPlugins(): PluggableList {
    },
    htmlPlugins() {
    return [
      () => {
        return async (tree: HTMLRoot, file) => {
@@ -35,7 +28,7 @@
          const sentences = desc.replace(/\s+/g, ' ').split('.')
          let finalDesc = ""
          let sentenceIdx = 0
          const len = this.opts.descriptionLength
            const len = opts.descriptionLength
          while (finalDesc.length < len) {
            finalDesc += sentences[sentenceIdx] + '.'
            sentenceIdx++
@@ -48,6 +41,7 @@
    ]
  }
}
}
declare module 'vfile' {
  interface DataMap {