From 7ebf2f5d48e3dd8710d21d84ebdf0e7039c096dc Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:23:28 +0100 Subject: [PATCH] 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 --- src/Publisher.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Publisher.ts b/src/Publisher.ts index bea73b6..2fe8b16 100644 --- a/src/Publisher.ts +++ b/src/Publisher.ts @@ -48,7 +48,7 @@ export class Publisher { await this.processImages(body); // Build Micropub properties - const properties = this.buildProperties(frontmatter, processedBody, uploadedUrls); + const properties = this.buildProperties(frontmatter, processedBody, uploadedUrls, file.basename); let result: PublishResult; @@ -78,6 +78,7 @@ export class Publisher { fm: Record, body: string, uploadedUrls: string[], + basename: string, ): Record { const props: Record = {}; @@ -107,9 +108,20 @@ export class Publisher { // ── Standard properties ─────────────────────────────────────────────── - // Title (articles have titles; notes/micro-posts don't) - if (fm["title"]) { - props["name"] = [String(fm["title"])]; + // Post type — explicit `postType` field takes priority over auto-detection. + // Set this in your Obsidian template so the post type is declared up front: + // 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