Skip to content

slug

const EPISODIC_PREFIX_LENGTH: 9 = 9;

The YYYYMMDD- prefix an episodic filename carries. Time is part of an episodic entry’s identity and it never receives a correction in place, so the date belongs in the name; every other type is timeless and correctable, so it gets a bare slug.


const SLUG_FALLBACK: "untitled" = "untitled";

The stem used when a title reduces to nothing sluggable, such as an all-punctuation or non-Latin title. A placeholder beats an empty filename, and memhtml doctor can find these by name.


const SLUG_MAX_LENGTH: 80 = 80;

Maximum slug length in characters, before any collision suffix.


const SLUG_MIN_WORD_CUT: 60 = 60;

The fewest characters a word-boundary cut may leave. A slug cut at its last word boundary inside the budget keeps at least this many, else it is cut at the budget itself: a boundary further back would drop most of a title whose last word inside the budget is long.

function datePrefix(at): string;

Format an instant as the YYYYMMDD stamp of an episodic filename, in UTC.

Date

string


function filenameFor(input): string;

The filename for a memory: 20260802-slug.html for episodic, slug.html otherwise. The date prefix sits outside the slug’s length budget, because it is identity, not title.

Date

boolean

string

string


function hasDatePrefix(filename): boolean;

True when a filename carries the YYYYMMDD- episodic prefix.

string

boolean


function isSlug(value): boolean;

True when a string is already a valid slug, the fixed point of slugify and slugifyStem.

string

boolean


function slugify(title): string;

Kebab-case a title into [a-z0-9-], at most SLUG_MAX_LENGTH characters.

Diacritics are folded to their base letters (déployé ⇒ deploye) rather than dropped, so a title stays recognizable. Runs of separators collapse to one hyphen and the result carries no leading or trailing hyphen, which makes the function idempotent: a slug fed back in comes out unchanged.

Truncation cuts at SLUG_MAX_LENGTH and then trims any hyphen the cut exposed, so a truncated slug is still a valid slug rather than one ending mid-separator.

This is the slug of every name that is recomputed each time it is used: a workspace’s projects/<slug>/ folder, a tag’s resources/<slug>/, and the names the curator matches against them. Its cut never changes, so a long workspace or tag stays one folder. A new record’s filename stem, computed once when the record is minted, is slugifyStem’s.

string

string


function slugifyStem(title): string;

The filename stem a new record takes from its title: slugify’s kebab-case, with a longer title cut at its last word boundary inside SLUG_MAX_LENGTH when that keeps at least SLUG_MIN_WORD_CUT characters, else at SLUG_MAX_LENGTH itself. A cut stem is still a valid slug and, when it can be, ends on a whole word rather than a fragment of one. Equal to slugify for every title whose slug fits the budget.

Only a filename stem takes this cut, because a stem is computed once, when a record is minted, and the path is the record’s id from then on: the rule decides new filenames and never moves an existing file. A folder name is recomputed on every write and keeps slugify’s cut.

string

string


function withCollisionOrdinal(slug, ordinal): string;

Append a collision suffix. ordinal is a 1-based ordinal for display in the filename; ordinal 1 is the unsuffixed slug, 2 becomes -2, and so on, matching the -2/-3 convention. The suffix is added inside the length budget, so a maximum-length slug is shortened rather than overflowed, and the stem is cut by the rule slugifyStem cuts with: at its last word boundary inside the room left when that keeps SLUG_MIN_WORD_CUT characters, else at the room itself.

The result never equals the input, at any slug length. That is what makes the store’s collision loop (packages/store/src/store.ts, pathFor) terminate rather than re-propose the name that collided. It is not free near the length cap: for a slug whose own tail IS the suffix, cutting to make room and appending the suffix can rebuild the slug — and because the cut also trims any hyphen it exposes, the rebuild can recur at MORE than one cut width. The stem is therefore re-cut from its own post-trim length until appending the suffix no longer reproduces the input; each re-cut strictly shortens the stem, so the loop terminates and the result stays inside the budget.

string

number

string