Rename postsPath to defaultPath, remove date requirement from postFilename
This commit is contained in:
@@ -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.postsDir).onChange((v) => { s.postsDir = v; save(); }));
|
||||
.addText((t) => t.setValue(s.defaultPublishDir).onChange((v) => { s.defaultPublishDir = 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")
|
||||
|
||||
@@ -51,9 +51,9 @@ export async function publish(
|
||||
});
|
||||
|
||||
const postText = buildPost({ frontmatterPairs: input.frontmatterPairs, body: rewrittenBody });
|
||||
const postPath = `${settings.postsDir}/${postFilename({ date: input.date, slug: input.slug })}`;
|
||||
const notePath = `${settings.defaultPublishDir}/${postFilename({ date: input.date, slug: input.slug })}`;
|
||||
|
||||
const files: GitFile[] = [{ repoPath: postPath, data: postText }];
|
||||
const files: GitFile[] = [{ repoPath: notePath, data: postText }];
|
||||
for (const item of plan) {
|
||||
const r = resolved.find((x) => x.linktext === item.linktext)!;
|
||||
files.push({ repoPath: item.repoPath, data: r.data });
|
||||
@@ -68,5 +68,5 @@ export async function publish(
|
||||
authorEmail: settings.authorEmail || undefined,
|
||||
});
|
||||
|
||||
return { postPath, imageCount: plan.length, unresolved };
|
||||
return { postPath: notePath, imageCount: plan.length, unresolved };
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Pair } from "./frontmatter";
|
||||
export interface JekyllPublishSettings {
|
||||
remoteUrl: string;
|
||||
branch: string;
|
||||
postsDir: string;
|
||||
defaultPublishDir: string;
|
||||
imagesDir: string;
|
||||
defaultImageStrategy: Strategy;
|
||||
presetFrontmatter: Pair[];
|
||||
@@ -16,7 +16,7 @@ export interface JekyllPublishSettings {
|
||||
export const DEFAULT_SETTINGS: JekyllPublishSettings = {
|
||||
remoteUrl: "",
|
||||
branch: "main",
|
||||
postsDir: "_posts",
|
||||
defaultPublishDir: "_posts",
|
||||
imagesDir: "assets/img",
|
||||
defaultImageStrategy: "flat-slug",
|
||||
presetFrontmatter: [],
|
||||
|
||||
@@ -29,4 +29,8 @@ describe("postFilename", () => {
|
||||
test("joins date and slug", () => {
|
||||
expect(postFilename({ 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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,6 +24,9 @@ function fmt(d: Date): string {
|
||||
return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())}`;
|
||||
}
|
||||
|
||||
export function postFilename(o: { date: string; slug: string }): string {
|
||||
return `${o.date}-${o.slug}.md`;
|
||||
export function postFilename(o: { date?: string; slug: string }): string {
|
||||
if (o.date) {
|
||||
return `${o.date}-${o.slug}.md`;
|
||||
}
|
||||
return `${o.slug}.md`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user