Skip to content

Slug brand type-design follow-ups (unique symbol, IsoDate, dead conditional) #69

Description

@thiras

The `Slug` brand and `PostMeta` introduced in #61 work as designed — the brand sits at a real security boundary (raw interpolation into URLs and the sitemap XML) and `parseSlug` is the single safe constructor. Three low-cost follow-ups to harden it further:

1. Use a `unique symbol` instead of a structural brand

`lib/blog.ts:18` defines `Slug = string & { readonly __brand: "Slug" }`. This is structurally forgeable: anyone writing `"foo" as Slug` or constructing `{ __brand: "Slug" as const }` adjacent to a string compiles. The `unique symbol` brand pattern is unfakeable across modules.

2. Apply the same brand pattern to `date`

`lib/blog.ts:23-29` types `date: string` even though `parseEntry` already proves the value matches `ISO_DATE_RE`. Mirror `Slug` with `IsoDate` + `parseIsoDate` so future consumers (RSS feed, archive page) don't have to re-test the regex.

3. Delete dead `summary` conditional

`summary` is required + trimmed-non-empty at parse, so `{post.summary ? (…) : null}` at `app/blog/page.tsx:91` is dead defensive code. Delete the guard.

Found during PR review of #61.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions