feat: slug and date derivation
Co-Authored-By: Claude
This commit is contained in:
32
src/slug.test.ts
Normal file
32
src/slug.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { slugify, deriveSlug, deriveDate, postFilename } from "./slug";
|
||||
|
||||
describe("slugify", () => {
|
||||
test("lowercases, drops apostrophes, hyphenates", () => {
|
||||
expect(slugify("On Making a Game")).toBe("on-making-a-game");
|
||||
expect(slugify("It's a Test!")).toBe("its-a-test");
|
||||
expect(slugify(" Spaced out ")).toBe("spaced-out");
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveSlug", () => {
|
||||
test("prefers title, falls back to filename", () => {
|
||||
expect(deriveSlug({ title: "Hello World", filename: "note" })).toBe("hello-world");
|
||||
expect(deriveSlug({ title: " ", filename: "My Note" })).toBe("my-note");
|
||||
});
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
describe("postFilename", () => {
|
||||
test("joins date and slug", () => {
|
||||
expect(postFilename({ date: "2026-06-19", slug: "hello" })).toBe("2026-06-19-hello.md");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user