blog_config.ts

The blogs registry, the consumer's src/routes/blogs.ts: each blog's BlogConfig, the registry's validation, and resolving a blog by its dirname. Free of node, gro, and Svelte imports, so gen, the tasks, and routes share it.

view source

Declarations
#

5 declarations

BlogConfig
#

blog_config.ts view source

BlogConfig import type {BlogConfig} from '@fuzdev/fuz_blog/blog_config.js';

A single blog's configuration in the consumer's src/routes/blogs.ts registry.

dirname

Route directory under src/routes, and the blog's base path segment - so it equals the URL path, with no route groups or params, no leading or trailing slash, and no characters a URL would change (see validate_blog_configs). Post pathnames derive from it.

type string

feed

Feed-level metadata. Post ids and urls and the feed's own URL derive from home_page_url, so set it to the blog's index page - its pathname must end with /<dirname>, after any deploy base path.

type BlogFeedMetadata

scaffold?

Customizes the post file gro task src/lib/post.task.ts scaffolds for this blog. Defaults to scaffold_blog_post.

type (options: BlogPostScaffoldOptions): string

options

returns string

BlogPostScaffoldOptions
#

blog_config.ts view source

BlogPostScaffoldOptions import type {BlogPostScaffoldOptions} from '@fuzdev/fuz_blog/blog_config.js';

The options gro task src/lib/post.task.ts passes to a BlogConfig scaffold.

title

type string

blog_post_id

The new post's id, the first part of its <id>-<slug> directory name.

type BlogPostId

slug

The new post's slug, the second part of its <id>-<slug> directory name. Not post metadata - available for scaffolds that reference it in content.

type string

date

Used for both date_published and date_modified.

type string

fuz_blog_import_path

Import specifier for fuz_blog modules - #lib inside fuz_blog itself, @fuzdev/fuz_blog in consumers.

type string

BlogsModule
#

blog_config.ts view source

BlogsModule import type {BlogsModule} from '@fuzdev/fuz_blog/blog_config.js';

The shape of the consumer's src/routes/blogs.ts module.

blogs

type BlogConfig[]

resolve_blog_config
#

blog_config.ts view source

(blogs: BlogConfig[], dirname: string | undefined): BlogConfig import {resolve_blog_config} from '@fuzdev/fuz_blog/blog_config.js';

Resolves a BlogConfig from the registry by its dirname, defaulting to the first registered blog when dirname is omitted. Throws when dirname matches no registered blog.

blogs

type BlogConfig[]

dirname

type string | undefined

returns

BlogConfig

validate_blog_configs
#

blog_config.ts view source

(blogs: unknown[]): asserts blogs is BlogConfig[] import {validate_blog_configs} from '@fuzdev/fuz_blog/blog_config.js';

Validates the blogs registry, called by load_blogs_module so gro gen and the post tasks check it before touching any post file: each config is an object with only BlogConfig keys and a function or omitted scaffold, each dirname is a well-formed and unique string, each feed is a strict BlogFeedMetadata (so a leftover atom, now derived, fails), and each home_page_url has no query or fragment and a pathname (trailing slash ignored) ending with /<dirname>, optionally after a deploy base path (e.g. https://user.github.io/repo/blog). Post urls and the feed URL derive from home_page_url while the posts are routes under src/routes/<dirname>, so a mismatch would publish broken links.

blogs

the registry's blogs export, unvalidated

type unknown[]

returns

void

throws

  • Error - naming the first invalid blog

Depends on
#

Imported by
#