fix: postType property for explicit article detection, pass basename to buildProperties

- Add `postType` frontmatter field (article/note) so Obsidian templates
  can declare post type explicitly without relying on title presence
- Pass file.basename into buildProperties to use as title fallback
- Fix 'file is not defined' crash when postType: article but title is empty

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-03-14 18:23:28 +01:00
parent 21a398f1ad
commit 7ebf2f5d48
+16 -4
View File
@@ -48,7 +48,7 @@ export class Publisher {
await this.processImages(body); await this.processImages(body);
// Build Micropub properties // Build Micropub properties
const properties = this.buildProperties(frontmatter, processedBody, uploadedUrls); const properties = this.buildProperties(frontmatter, processedBody, uploadedUrls, file.basename);
let result: PublishResult; let result: PublishResult;
@@ -78,6 +78,7 @@ export class Publisher {
fm: Record<string, unknown>, fm: Record<string, unknown>,
body: string, body: string,
uploadedUrls: string[], uploadedUrls: string[],
basename: string,
): Record<string, unknown> { ): Record<string, unknown> {
const props: Record<string, unknown> = {}; const props: Record<string, unknown> = {};
@@ -107,9 +108,20 @@ export class Publisher {
// ── Standard properties ─────────────────────────────────────────────── // ── Standard properties ───────────────────────────────────────────────
// Title (articles have titles; notes/micro-posts don't) // Post type — explicit `postType` field takes priority over auto-detection.
if (fm["title"]) { // Set this in your Obsidian template so the post type is declared up front:
props["name"] = [String(fm["title"])]; // postType: article → always publishes as article (sets `name`)
// postType: note → always publishes as note (skips `name`)
// (absent) → auto-detect: has title → article, otherwise → note
const postType = fm["postType"] ?? fm["post-type"] ?? fm["type"];
const isArticle =
postType === "article" ||
(!postType && Boolean(fm["title"] ?? fm["name"]));
if (isArticle) {
// Use explicit title/name, or fall back to the note filename (without extension)
const titleValue = fm["title"] ?? fm["name"] ?? basename;
props["name"] = [String(titleValue)];
} }
// Summary / excerpt // Summary / excerpt