Remove the default date formatting

This commit is contained in:
2026-08-09 14:28:17 -04:00
parent 87d27f2f4c
commit e4117a3d28
7 changed files with 20 additions and 20 deletions

View File

@@ -1083,7 +1083,7 @@ Co-Authored-By: Claude"
- Create: `src/publish.ts`, `src/publish.test.ts`
**Interfaces:**
- Consumes: `parseNote`, `Pair` (frontmatter); `findImageRefs`, `planImages`, `Strategy` (images); `buildPost`; `postFilename` (slug); `GitClient`, `GitFile` (git); `JekyllPublishSettings`.
- Consumes: `parseNote`, `Pair` (frontmatter); `findImageRefs`, `planImages`, `Strategy` (images); `buildPost`; `pageFilename` (slug); `GitClient`, `GitFile` (git); `JekyllPublishSettings`.
- Produces:
- `interface PublishInput { noteText: string; frontmatterPairs: Pair[]; slug: string; date: string; strategy: Strategy; commitMessage: string }`
- `interface ImageResolver { (linktext: string): Promise<Buffer | null> }`

View File

@@ -7,7 +7,7 @@ import { deriveDate, deriveSlug } from "./slug";
export interface ModalResult {
frontmatterPairs: Pair[];
slug: string;
date: string;
date?: string;
strategy: Strategy;
commitMessage: string;
}
@@ -38,7 +38,7 @@ export class PublishModal extends Modal {
this.result = {
frontmatterPairs: [],
slug: deriveSlug({ title, filename }),
date: deriveDate({ frontmatterDate: frontmatter.date, now: new Date() }),
date: deriveDate({ frontmatterDate: frontmatter.date }),
strategy: settings.defaultImageStrategy,
commitMessage: settings.commitMessageTemplate.replace("{{title}}", title || filename),
};
@@ -57,8 +57,9 @@ export class PublishModal extends Modal {
t.setValue(this.result.slug).onChange((v) => (this.result.slug = v))
);
new Setting(contentEl).setName("Date").addText((t) =>
t.setValue(this.result.date).onChange((v) => (this.result.date = v))
);
t.setValue(this.result.date ?? "").onChange((v) => (this.result.date = v))
).setDesc("The date to prepend to the filename. Useful for blog posts.");
new Setting(contentEl).setName("Image strategy").addDropdown((d) =>
d.addOption("flat-slug", "Flat, renamed to slug")
.addOption("per-post-folder", "Per-post subfolder")

View File

@@ -17,7 +17,7 @@ export class JekyllPublishSettingTab extends PluginSettingTab {
new Setting(containerEl).setName("Branch")
.addText((t) => t.setValue(s.branch).onChange((v) => { s.branch = v; save(); }));
new Setting(containerEl).setName("Posts directory")
.addText((t) => t.setValue(s.defaultPublishDir).onChange((v) => { s.defaultPublishDir = v; save(); }));
.addText((t) => t.setValue(s.publishDir).onChange((v) => { s.publishDir = v; save(); }));
new Setting(containerEl).setName("Images directory")
.addText((t) => t.setValue(s.imagesDir).onChange((v) => { s.imagesDir = v; save(); }));
new Setting(containerEl).setName("Default image strategy")

View File

@@ -1,6 +1,6 @@
import { parseNote, Pair } from "./frontmatter";
import { buildPost } from "./buildPost";
import { postFilename } from "./slug";
import { pageFilename } from "./slug";
import { findImageRefs, planImages, Strategy } from "./images";
import { GitClient, GitFile } from "./git";
import { JekyllPublishSettings } from "./settings";
@@ -9,7 +9,7 @@ export interface PublishInput {
noteText: string;
frontmatterPairs: Pair[];
slug: string;
date: string;
date?: string;
strategy: Strategy;
commitMessage: string;
}
@@ -51,7 +51,7 @@ export async function publish(
});
const postText = buildPost({ frontmatterPairs: input.frontmatterPairs, body: rewrittenBody });
const notePath = `${settings.defaultPublishDir}/${postFilename({ date: input.date, slug: input.slug })}`;
const notePath = `${settings.publishDir}/${pageFilename({ date: input.date, slug: input.slug })}`;
const files: GitFile[] = [{ repoPath: notePath, data: postText }];
for (const item of plan) {

View File

@@ -4,7 +4,7 @@ import { Pair } from "./frontmatter";
export interface JekyllPublishSettings {
remoteUrl: string;
branch: string;
defaultPublishDir: string;
publishDir: string;
imagesDir: string;
defaultImageStrategy: Strategy;
presetFrontmatter: Pair[];
@@ -16,7 +16,7 @@ export interface JekyllPublishSettings {
export const DEFAULT_SETTINGS: JekyllPublishSettings = {
remoteUrl: "",
branch: "main",
defaultPublishDir: "_posts",
publishDir: "_posts",
imagesDir: "assets/img",
defaultImageStrategy: "flat-slug",
presetFrontmatter: [],

View File

@@ -1,5 +1,5 @@
import { describe, expect, test } from "vitest";
import { slugify, deriveSlug, deriveDate, postFilename } from "./slug";
import { slugify, deriveSlug, deriveDate, pageFilename } from "./slug";
describe("slugify", () => {
test("lowercases, drops apostrophes, hyphenates", () => {
@@ -19,18 +19,18 @@ describe("deriveSlug", () => {
describe("deriveDate", () => {
const now = new Date("2026-06-19T12:00:00Z");
test("uses frontmatter Date or string, else now", () => {
expect(deriveDate({ frontmatterDate: new Date("2026-02-06T00:00:00Z"), now })).toBe("2026-02-06");
expect(deriveDate({ frontmatterDate: "2026-02-18 09:00", now })).toBe("2026-02-18");
expect(deriveDate({ now })).toBe("2026-06-19");
expect(deriveDate({ frontmatterDate: new Date("2026-02-06T00:00:00Z"), })).toBe("2026-02-06");
expect(deriveDate({ frontmatterDate: "2026-02-18 09:00" })).toBe("2026-02-18");
expect(deriveDate({ frontmatterDate: "unparsable" })).toBeUndefined();
});
});
describe("postFilename", () => {
test("joins date and slug", () => {
expect(postFilename({ date: "2026-06-19", slug: "hello" })).toBe("2026-06-19-hello.md");
expect(pageFilename({ date: "2026-06-19", slug: "hello" })).toBe("2026-06-19-hello.md");
});
test("renders correctly without date", () => {
expect(postFilename({ slug: "hello-without-date" })).toBe("hello-without-date.md");
expect(pageFilename({ slug: "hello-without-date" })).toBe("hello-without-date.md");
});
});

View File

@@ -12,11 +12,10 @@ export function deriveSlug(o: { title?: string; filename: string }): string {
return slugify(base);
}
export function deriveDate(o: { frontmatterDate?: unknown; now: Date }): string {
export function deriveDate(o: { frontmatterDate?: unknown }): string | undefined {
const d = o.frontmatterDate;
if (d instanceof Date && !isNaN(d.getTime())) return fmt(d);
if (typeof d === "string" && /^\d{4}-\d{2}-\d{2}/.test(d)) return d.slice(0, 10);
return fmt(o.now);
}
function fmt(d: Date): string {
@@ -24,7 +23,7 @@ function fmt(d: Date): string {
return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}`;
}
export function postFilename(o: { date?: string; slug: string }): string {
export function pageFilename(o: { date?: string; slug: string }): string {
if (o.date) {
return `${o.date}-${o.slug}.md`;
}