feat(exporter): add auto-generated description to frontmatter

This commit is contained in:
gameloader
2026-01-19 15:10:15 +08:00
parent 6638f40fc9
commit b0c925c104
2 changed files with 8 additions and 6 deletions

10
main.js
View File

@@ -173,19 +173,21 @@ class AstroPostExporter extends Plugin {
const modified = file.stat && file.stat.mtime ? file.stat.mtime : Date.now(); const modified = file.stat && file.stat.mtime ? file.stat.mtime : Date.now();
const title = file.basename; const title = file.basename;
const includePubDate = !hasFrontmatterKey(content, "pubDate"); const includeDescription = !hasFrontmatterKey(content, "description");
const pubDate = moment(created).format(this.settings.dateFormat); const pubDate = moment(created).format(this.settings.dateFormat);
const modifiedDate = moment(modified).format(this.settings.dateFormat); const modifiedDate = moment(modified).format(this.settings.dateFormat);
const frontmatterLines = [ const frontmatterLines = [
`title: "${escapeYamlString(title)}"`, `title: "${escapeYamlString(title)}"`,
...(includePubDate ? [`pubDate: "${pubDate}"`] : []), ...(includeDescription ? [`description: "${escapeYamlString(title)}"`] : []),
`${this.settings.modifiedDateKey}: "${modifiedDate}"` `pubDate: ${pubDate}`,
`${this.settings.modifiedDateKey}: ${modifiedDate}`
]; ];
const keysToReplace = [ const keysToReplace = [
"title", "title",
...(includePubDate ? ["pubDate"] : []), ...(includeDescription ? ["description"] : []),
"pubDate",
this.settings.modifiedDateKey this.settings.modifiedDateKey
]; ];
return upsertFrontmatter(content, frontmatterLines, keysToReplace); return upsertFrontmatter(content, frontmatterLines, keysToReplace);

View File

@@ -1,9 +1,9 @@
{ {
"id": "astro-post-exporter", "id": "astro-post-exporter",
"name": "Astro Post Exporter", "name": "Astro Post Exporter",
"version": "0.1.0", "version": "0.1.1",
"minAppVersion": "1.4.0", "minAppVersion": "1.4.0",
"description": "Export Obsidian notes to an Astro posts folder with frontmatter.", "description": "Export Obsidian notes to an Astro posts folder with frontmatter.",
"author": "astro-chiri", "author": "Logic",
"isDesktopOnly": true "isDesktopOnly": true
} }