RegExp import {BLOG_POST_SLUG_PATTERN} from '@fuzdev/fuz_blog/blog_post_dir.js'; Matches a post slug: lowercase ASCII letters and digits in hyphen-separated runs.
A blog's post directories, src/routes/<dirname>/<id>-<slug>: their name grammar,
parsing and formatting, validation of a blog's directory listing, lookup by a
query, and the next id. Pure, so the build helpers and tests share it.
7 declarations
RegExp import {BLOG_POST_SLUG_PATTERN} from '@fuzdev/fuz_blog/blog_post_dir.js'; Matches a post slug: lowercase ASCII letters and digits in hyphen-separated runs.
BlogPostDir import type {BlogPostDir} from '@fuzdev/fuz_blog/blog_post_dir.js'; A post directory's identity, parsed from its <id>-<slug> name by parse_blog_post_dirname.
blog_post_idtype BlogPostId
slugtype string
(post_dirs: BlogPostDir[], query: string, blog_dirname: string): BlogPostDir import {find_blog_post_dir} from '@fuzdev/fuz_blog/blog_post_dir.js'; Finds a blog's post by a query naming it: a bare id like 1 matches by id,
an <id>-<slug> directory name like 1-hello-world matches that directory
exactly, and anything else matching BLOG_POST_SLUG_PATTERN matches by slug.
A directory name that matches no post falls back to matching by slug, since
a slug may itself look like <id>-<slug> (5-1-x has the slug 1-x).
An existing directory name wins over an equal slug of another post.
Slugs are not unique across ids, so a slug matching more than one post throws -
query by id or directory name instead.
post_dirsthe blog's posts, from resolve_blog_post_dirs
BlogPostDir[]querythe post's id, directory name, or slug
stringblog_dirnamethe blog's dirname, for error messages
stringBlogPostDir Error - when `query` is none of the three forms or matches no post or
more than one(name: string): BlogPostDir | null import {parse_blog_post_dirname} from '@fuzdev/fuz_blog/blog_post_dir.js'; Parses a post directory name like 1-hello-world into its id and slug.
The slug may itself start with digits (1-2024-recap is id 1, slug 2024-recap).
namestringBlogPostDir | null
the id and slug, or null when name is not a valid post directory name
or its id is beyond the safe integer range
(names: string[], blog_dirname: string): BlogPostDir[] import {resolve_blog_post_dirs} from '@fuzdev/fuz_blog/blog_post_dir.js'; Validates a blog's post directory names, returning the posts sorted by id.
A name starting with a digit claims to be a post and must parse with
parse_blog_post_dirname; other names ([post=blog_post_id], a consumer's own routes)
are skipped.
namesthe names of the subdirectories of a blog's route directory
string[]blog_dirnamethe blog's dirname, for error messages
stringError - on an invalid post directory name or a duplicate id(post_dir: BlogPostDir): string import {to_blog_post_dirname} from '@fuzdev/fuz_blog/blog_post_dir.js'; Formats a post's directory name, <id>-<slug> - the inverse of parse_blog_post_dirname.
post_dirstring (post_dirs: BlogPostDir[]): BlogPostId import {to_next_blog_post_id} from '@fuzdev/fuz_blog/blog_post_dir.js'; The id for a new post, one more than the highest existing id, so a deleted post's id is not reused unless it was the highest.
post_dirsBlogPostDir[]