| | |
| | | import { PluggableList } from "unified" |
| | | import fs from "fs" |
| | | import path from 'path' |
| | | import { Repository } from "@napi-rs/simple-git" |
| | |
| | | priority: ['frontmatter', 'git', 'filesystem'] |
| | | } |
| | | |
| | | export class CreatedModifiedDate extends QuartzTransformerPlugin { |
| | | name = "CreatedModifiedDate" |
| | | opts: Options |
| | | |
| | | constructor(opts?: Partial<Options>) { |
| | | super() |
| | | this.opts = { |
| | | ...defaultOptions, |
| | | ...opts, |
| | | } |
| | | } |
| | | |
| | | markdownPlugins(): PluggableList { |
| | | export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options> | undefined> = (userOpts) => { |
| | | const opts = { ...defaultOptions, ...userOpts } |
| | | return { |
| | | name: "CreatedModifiedDate", |
| | | markdownPlugins() { |
| | | return [ |
| | | () => { |
| | | let repo: Repository | undefined = undefined |
| | |
| | | let published: undefined | Date = undefined |
| | | |
| | | const fp = path.join(file.cwd, file.data.filePath as string) |
| | | for (const source of this.opts.priority) { |
| | | for (const source of opts.priority) { |
| | | if (source === "filesystem") { |
| | | const st = await fs.promises.stat(fp) |
| | | created ||= new Date(st.birthtimeMs) |
| | |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | |
| | | htmlPlugins(): PluggableList { |
| | | }, |
| | | htmlPlugins() { |
| | | return [] |
| | | } |
| | | } |
| | | } |
| | | |
| | | declare module 'vfile' { |
| | | interface DataMap { |