api #

blog software from scratch with SvelteKit

19 modules ยท 76 declarations

Modules
#

blog_feed_context
#

blog_feed_context.ts view source

{ get: (error_message?: string | undefined) => { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }; get_maybe: () => { ...; } | undefined; set: (va... import {blog_feed_context} from '@fuzdev/fuz_blog/blog_feed_context.js';

Provides a blog's generated BlogFeed to its subtree, read by BlogPost and set in the blog's own src/routes/<dirname>/+layout.svelte. Kept apart from blog.ts so the schemas, the registry, and the build helpers don't import fuz_ui and Svelte.

BLOG_INIT_BLOGS_PATH
#

blog_init.ts view source

"src/routes/blogs.ts" import {BLOG_INIT_BLOGS_PATH} from '@fuzdev/fuz_blog/blog_init.js';

BLOG_INIT_ROOT_LAYOUT_PATH
#

blog_init.ts view source

"src/routes/+layout.svelte" import {BLOG_INIT_ROOT_LAYOUT_PATH} from '@fuzdev/fuz_blog/blog_init.js';

blog_post_id_param
#

blog_post_id.ts view source

(param: string): string | undefined import {blog_post_id_param} from '@fuzdev/fuz_blog/blog_post_id.js';

The SvelteKit param matcher for the generated [post=blog_post_id] redirect route. Register it under the blog_post_id name in the app's src/params.ts, e.g. export const params = defineParams({blog_post_id: blog_post_id_param});. Without it, the route would match every /<dirname>/<segment> path, so client-side navigation to a static file under the blog path would hit the redirect.

param

type string

returns

string | undefined

BLOG_POST_ID_SOURCE
#

blog_post_id.ts view source

"[1-9]\\d*" import {BLOG_POST_ID_SOURCE} from '@fuzdev/fuz_blog/blog_post_id.js';

Regex source for a post id: a positive integer without leading zeros. Shared by the post directory name pattern and the param matcher so they can't drift.

blog_post_redirect
#

blog_post_redirect.ts view source

(feed: { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }, param: string): never import {blog_post_redirect} from '@fuzdev/fuz_blog/blog_post_redirect.js';

The load of the generated [post=blog_post_id] route: redirects a bare post id to the post's canonical path, or 404s. Prerendering writes the redirect as a page with a meta refresh.

feed

the blog's generated feed

param

the post route param

type string

returns

never

throws

  • Redirect - 308 to the post's `pathname` under the base path
  • HttpError - 404 when no post has the id

BLOG_POST_REDIRECT_ROUTE_DIRNAME
#

blog_helpers.ts view source

"[post=blog_post_id]" import {BLOG_POST_REDIRECT_ROUTE_DIRNAME} from '@fuzdev/fuz_blog/blog_helpers.js';

The directory name of the redirect route gro gen writes in each blog with posts. Its blog_post_id matcher is blog_post_id_param, registered in the app's src/params.ts.

BLOG_POST_SLUG_PATTERN
#

blog_post_dir.ts view source

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.

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

BlogFeed
#

blog.ts view source

value + type

{ id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { id: string; ... 8 more ...; slug: string; }[]; atom: { ...; }; } import {BlogFeed} from '@fuzdev/fuz_blog/blog.js';

A blog's complete feed, generated by gro gen into src/routes/<dirname>/feed.ts: the configured BlogFeedMetadata, the derived atom.feed_url, and the post entries.

id

type string

title

type string

home_page_url

type string

description

type string

icon

type string

favicon

type string

author

type { name: string; url?: string | undefined; email?: string | undefined; }

items

type BlogFeedItem[]

atom

type { feed_url: string; }

BlogFeedItem
#

blog.ts view source

value + type

{ id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags: string[]; pathname: string; blog_post_id: number; slug: string; } import {BlogFeedItem} from '@fuzdev/fuz_blog/blog.js';

A feed entry, derived from a BlogPostMetadata by resolve_blog_feed_item. Strict, so a leaked consumer field fails the generated feed's validation.

id

type string

title

type string

url

type string

date_published

type string

date_modified

type string

summary

type string

tags

type string[]

pathname

type string

blog_post_id

type number

slug

type string

BlogFeedMetadata
#

blog.ts view source

value + type

{ id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; } import {BlogFeedMetadata} from '@fuzdev/fuz_blog/blog.js';

A blog's configured feed metadata: the Feed fields without items, which come from the posts, and atom, which gro gen derives from home_page_url (see to_blog_feed_url).

id

type string

title

type string

home_page_url

type string

description

type string

icon

type string

favicon

type string

author

type { name: string; url?: string | undefined; email?: string | undefined; }

BlogGenInput
#

BlogGenOptions
#

blog_helpers.ts view source

BlogGenOptions import type {BlogGenOptions} from '@fuzdev/fuz_blog/blog_helpers.js';

dir

The project root.

type string

fuz_blog_import_path

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

type string

origin_path

The generator's path, written into the generated files' header comments.

type string

blogs

type BlogGenInput[]

BlogGenOutput
#

blog_helpers.ts view source

BlogGenOutput import type {BlogGenOutput} from '@fuzdev/fuz_blog/blog_helpers.js';

filename

type string

content

type string

BlogInitAction
#

blog_init.ts view source

BlogInitAction

type { kind: "create"; path: string; content: string; } | { kind: "exists"; path: string; } | { kind: "suggest"; path: string; message: string; snippet: string; }

import type {BlogInitAction} from '@fuzdev/fuz_blog/blog_init.js';

One planned step of plan_blog_init: create a missing file, leave an existing one alone, or suggest an edit the user makes by hand.

BlogInitOptions
#

blog_init.ts view source

BlogInitOptions import type {BlogInitOptions} from '@fuzdev/fuz_blog/blog_init.js';

The options of init.task.ts, before defaults from package.json.

dirname

The new blog's dirname.

type string

url?

The site URL including any deploy base path, defaulting to package.json homepage.

type string

title?

The feed title, defaulting to <package name> <dirname>.

type string

description?

The feed description, defaulting to package.json description, then the title.

type string

author?

The feed author as Name <email> (url), defaulting to package.json author.

type string

icon?

The feed's icon and favicon URL, defaulting to <url>/favicon.png.

type string

BlogInitPackageJson
#

blog_init.ts view source

BlogInitPackageJson import type {BlogInitPackageJson} from '@fuzdev/fuz_blog/blog_init.js';

The package.json fields plan_blog_init reads.

name?

type string

description?

type string

homepage?

type string

author?

type unknown

BlogInitPaths
#

blog_init.ts view source

BlogInitPaths import type {BlogInitPaths} from '@fuzdev/fuz_blog/blog_init.js';

blogs

type string

gen

type string

post_task

type string

update_post_task

type string

layout

type string

page

type string

BlogInitPlan
#

blog_init.ts view source

BlogInitPlan import type {BlogInitPlan} from '@fuzdev/fuz_blog/blog_init.js';

config

The new blog's config, validated, written to or suggested for blogs.ts.

type BlogConfig

actions

type BlogInitAction[]

blog_registered

Whether the registry includes the blog after the plan is applied, so gro gen can write its feed.ts - false when the entry is only suggested, in which case the blog's routes, which import that feed.ts, wait for the next run.

type boolean

warnings

Likely mistakes that don't stop the plan, like a repo URL as the site URL.

type string[]

BlogInitState
#

blog_init.ts view source

BlogInitState import type {BlogInitState} from '@fuzdev/fuz_blog/blog_init.js';

The project's state as plan_blog_init needs it, read by load_blog_init_state. Paths are relative to the project root.

package_json

type BlogInitPackageJson

routes_path

SvelteKit's files.routes, which fuz_blog requires to be src/routes.

type string

routes_dir_exists

type boolean

existing_paths

The paths from to_blog_init_paths that exist.

type ReadonlySet<string>

blogs

The existing src/routes/blogs.ts registry's blogs, validated, or null when missing.

type BlogConfig[] | null

params_path

The existing param matchers module, or the one to create, e.g. src/params.ts.

type string

params_content

The param matchers module's content, null when missing.

type string | null

root_layout_content

The root +layout.svelte's content, null when missing.

type string | null

BlogPost
#

BlogPost.svelte view source

accepts children

import BlogPost from '@fuzdev/fuz_blog/BlogPost.svelte';

post

The author-defined metadata the post exports from its <script module>, including any fields a consumer adds beyond BlogPostMetadata, like an autoblog's model. Sets the page title. Its type is the component's T, inferred from the value passed, so meta and comments receive the extra fields typed.

type T

item?

The resolved feed item. Defaults to the blog_feed_context item whose pathname is the current route; pass it explicitly to skip the context, e.g. when rendering a post outside its own route.

optional

attrs?

type HTMLAttributes<HTMLElement>
optional

meta?

Renders after BlogPostHeader, e.g. for post provenance from post's extra fields.

type Snippet<[item: BlogFeedItem, post: T]>
optional
snippet parameters
post T

footer?

type Snippet<[]>
optional

comments?

Renders after footer, for a post's comments.

type Snippet<[item: BlogFeedItem, post: T]>
optional
snippet parameters
post T

children

type Snippet<[]>

generics

BlogPost<T extends BlogPostMetadata>
T
constraint BlogPostMetadata

BlogPostDir
#

BlogPostHeader
#

BlogPostId
#

blog_post_id.ts view source

BlogPostId

type number & Flavor<"BlogPostId">

import type {BlogPostId} from '@fuzdev/fuz_blog/blog_post_id.js';

A post's positive integer id, the first part of its <id>-<slug> directory name. Ids are unique within a blog and may have gaps.

external types

Flavored<number, 'BlogPostId'>

BlogPostList
#

BlogPostList.svelte view source

import BlogPostList from '@fuzdev/fuz_blog/BlogPostList.svelte';

feed

CSS custom properties

--shadow_color
fallback var(--shadow_color_umbra)
--card_shadow
fallback var(--shadow_bottom_sm) color-mix( in hsl, var(--shadow_color, var(--shadow_color_umbra)) var(--shadow_alpha_40), transparent )

BlogPostMetadata
#

blog.ts view source

value + type

{ title: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; } & Record<string, unknown>

type { title: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; } & Record<string, unknown>

import {BlogPostMetadata} from '@fuzdev/fuz_blog/blog.js';

The author-defined metadata for each post. Loose so a consumer can add its own fields (e.g. an autoblog's model); the extras stay on the page's post and do not reach the generated BlogFeed (see resolve_blog_feed_item). The slug is not metadata - it comes from the post's <id>-<slug> directory name (see parse_blog_post_dirname).

title

type string

date_published

type string

date_modified

type string

summary

type string

tags?

type string[]

[key: string]

type unknown

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[]

collect_blog_post_dirs
#

blog_helpers.ts view source

(blog_dir: string, blog_dirname: string): Promise<BlogPostDir[]> import {collect_blog_post_dirs} from '@fuzdev/fuz_blog/blog_helpers.js';

Discovers a blog's posts, its <id>-<slug> subdirectories, sorted by id. Ids may have gaps. Throws on an invalid post directory name, a duplicate id, or a post directory without a +page.svelte.

blog_dir

absolute path to the blog's route directory

type string

blog_dirname

the blog's dirname, for error messages

type string

returns

Promise<BlogPostDir[]>

compare_feed_items
#

feed.ts view source

(a: { id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; }, b: { id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; }): number import {compare_feed_items} from '@fuzdev/fuz_blog/feed.js';

Compares feed items newest first: by date_published descending, then by id descending with numeric collation (so https://example.com/blog/10 sorts before https://example.com/blog/9), then by id code units. For valid FeedDatetime values it's a total order, so the sort is deterministic for any input order. create_atom_feed and BlogPostList both order items with it.

a

b

returns

number

create_atom_feed
#

feed.ts view source

(data: { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }): string import {create_atom_feed} from '@fuzdev/fuz_blog/feed.js';

Renders a feed as Atom XML, entries newest first (see compare_feed_items). The feed-level <updated> is the latest date_modified or date_published across the items. Atom requires the element, so a feed with no items gets the Unix epoch, 1970-01-01T00:00:00.000Z - a fixed value keeps the generated feed.xml deterministic, where the current time would change it on every gro gen. Expects parsed Feed data; an unparseable date throws.

data

type Feed

returns

string

create_blog_gen_outputs
#

blog_helpers.ts view source

(options: BlogGenOptions): BlogGenOutput[] import {create_blog_gen_outputs} from '@fuzdev/fuz_blog/blog_helpers.js';

Creates the gro gen outputs for each blog: its feed.xml, its feed.ts, and, when it has posts, its [post=blog_post_id] redirect route. A blog without posts gets no redirect route, because prerendering fails on a dynamic route with no entries. The feed's atom.feed_url is derived from home_page_url by to_blog_feed_url.

options

returns

BlogGenOutput[]

throws

  • Error - on an invalid blogs registry (see `validate_blog_configs`), invalid post metadata, a post whose `date_modified` precedes its `date_published`, a feed that fails validation, or a redirect route left on disk for a blog without posts (gen cannot delete it)

create_blog_post
#

blog_helpers.ts view source

(options: CreateBlogPostOptions): Promise<CreatedBlogPost> import {create_blog_post} from '@fuzdev/fuz_blog/blog_helpers.js';

Scaffolds and writes the next post file for config at <id>-<slug>/+page.svelte, returning its id, path, and slug. The id is one more than the highest existing id. Does not run gen - callers invoke that afterward (see post.task.ts).

options

returns

Promise<CreatedBlogPost>

throws

  • Error - when no slug is given and none derives from `title`, or the slug does not match `BLOG_POST_SLUG_PATTERN`

CreateBlogPostOptions
#

blog_helpers.ts view source

CreateBlogPostOptions import type {CreateBlogPostOptions} from '@fuzdev/fuz_blog/blog_helpers.js';

dir

The project root, usually process.cwd().

type string

config

The target blog, e.g. from resolve_blog_config.

type BlogConfig

title

The post title.

type string

slug?

The post slug. When omitted or empty, derived from title by to_blog_post_slug.

type string

date

ISO 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, @fuzdev/fuz_blog in consumers.

type string

scaffold?

Overrides the scaffold for this call, taking precedence over config.scaffold. Lets a consumer task close over its own args (e.g. a --model flag) without widening BlogPostScaffoldOptions.

type (options: BlogPostScaffoldOptions): string

options

returns string

CreatedBlogPost
#

blog_helpers.ts view source

CreatedBlogPost import type {CreatedBlogPost} from '@fuzdev/fuz_blog/blog_helpers.js';

blog_post_id

type BlogPostId

path

Absolute path to the written +page.svelte.

type string

slug

type string

Feed
#

feed.ts view source

value + type

{ id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { id: string; ... 5 more ...; tags?: string[] | undefined; }[]; atom: { ...; }; } import {Feed} from '@fuzdev/fuz_blog/feed.js';

A blog's feed data, rendered to Atom by create_atom_feed. Field names follow JSON Feed 1.1 where the two overlap, but the shape is not a conformant JSON Feed: it has a feed-level id (Atom's), a single author with email, the Atom feed_url under an unprefixed atom key, no version, and items with a summary but no content_html or content_text. Publishing feed.json means mapping to the spec, not serializing this as is. https://www.jsonfeed.org/version/1.1/

id

type string

title

type string

home_page_url

type string

description

type string

icon

type string

favicon

type string

author

type { name: string; url?: string | undefined; email?: string | undefined; }

items

type FeedItem[]

atom

type { feed_url: string; }

FeedDatetime
#

feed.ts view source

value + type

string import {FeedDatetime} from '@fuzdev/fuz_blog/feed.js';

An ISO 8601 UTC datetime string like 2024-07-15T00:00:00.000Z, the form Date.prototype.toISOString writes. The date must exist on the calendar, seconds are required, fractional seconds take any number of digits, and the offset must be Z. The output is the input unchanged.

FeedItem
#

feed.ts view source

value + type

{ id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; } import {FeedItem} from '@fuzdev/fuz_blog/feed.js';

id

type string

title

type string

url

type string

date_published

type string

date_modified

type string

summary

type string

tags?

type string[]

FeedItemDate
#

FeedItemDate.svelte view source

import FeedItemDate from '@fuzdev/fuz_blog/FeedItemDate.svelte';

item

A feed item or post metadata, anything with the two dates.

type Pick<FeedItem, "date_published" | "date_modified">

FeedUrl
#

feed.ts view source

value + type

string import {FeedUrl} from '@fuzdev/fuz_blog/feed.js';

An absolute URL as fuz_util's Url takes it, with no surrounding whitespace: the text is kept as written, so padding would reach the generated feed, where it fails here instead.

find_blog_feed_item_by_param
#

blog_post_redirect.ts view source

(feed: { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }, param: string): { ...; } | undefined import {find_blog_feed_item_by_param} from '@fuzdev/fuz_blog/blog_post_redirect.js';

Finds a feed's item by the param of the generated redirect route, which must be a bare post id like 1 - 01 and 1.0 find nothing.

feed

param

type string

returns

BlogFeedItem | undefined

find_blog_post_dir
#

blog_post_dir.ts view source

(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_dirs

the blog's posts, from resolve_blog_post_dirs

query

the post's id, directory name, or slug

type string

blog_dirname

the blog's dirname, for error messages

type string

returns

BlogPostDir

throws

  • Error - when `query` is none of the three forms or matches no post or more than one

format_date
#

util.ts view source

(date: string | number | Date): string import {format_date} from '@fuzdev/fuz_blog/util.js';

Formats a date as its UTC calendar date, like Jul 10, 2024, independent of the runtime's timezone.

date

type string | number | Date

returns

string

is_blog_post_id_param
#

blog_post_id.ts view source

(param: string): boolean import {is_blog_post_id_param} from '@fuzdev/fuz_blog/blog_post_id.js';

Checks if param is a bare post id like 1, within the safe integer range so it round-trips through Number.

param

type string

returns

boolean

load_blog_init_state
#

load_blog_posts
#

blog_helpers.ts view source

(blog_dir: string, post_dirs: BlogPostDir[]): Promise<unknown[]> import {load_blog_posts} from '@fuzdev/fuz_blog/blog_helpers.js';

Imports each post's +page.svelte and returns its post export, unvalidated - create_blog_gen_outputs parses them as BlogPostMetadata.

blog_dir

absolute path to the blog's route directory

type string

post_dirs

the blog's posts, from collect_blog_post_dirs

returns

Promise<unknown[]>

each post's post export, in post_dirs order

load_blogs_module
#

load_blogs_registry
#

blog_helpers.ts view source

(dir: string): Promise<BlogConfig[] | null> import {load_blogs_registry} from '@fuzdev/fuz_blog/blog_helpers.js';

Loads the consumer's src/routes/blogs.ts registry and validates it with validate_blog_configs, allowing an empty blogs array. load_blogs_module is the strict form gen and the post tasks use.

dir

type string

returns

Promise<BlogConfig[] | null>

the validated blogs, or null when the registry file is missing

throws

  • Error - when the module doesn't export a `blogs` array or a blog is invalid

load_fuz_blog_import_path
#

blog_helpers.ts view source

(dir: string): Promise<string> import {load_fuz_blog_import_path} from '@fuzdev/fuz_blog/blog_helpers.js';

Loads the import specifier for fuz_blog modules in the project at dir - #lib inside fuz_blog itself, @fuzdev/fuz_blog in consumers.

dir

type string

returns

Promise<string>

LoadBlogInitStateOptions
#

blog_helpers.ts view source

LoadBlogInitStateOptions import type {LoadBlogInitStateOptions} from '@fuzdev/fuz_blog/blog_helpers.js';

dir

The project root, usually process.cwd().

type string

dirname

The new blog's dirname.

type string

package_json

type BlogInitPackageJson

routes_path

SvelteKit's files.routes, relative to dir.

type string

params_path

SvelteKit's files.params relative to dir, resolved like SvelteKit does (see resolve_params_module_path).

type string

module_extensions?

SvelteKit's moduleExtensions, defaulting to .js and .ts.

type string[]

parse_blog_init_author
#

blog_init.ts view source

(author: unknown): { name: string; url?: string | undefined; email?: string | undefined; } | null import {parse_blog_init_author} from '@fuzdev/fuz_blog/blog_init.js';

Parses an npm author, a Name <email> (url) string or a {name, email, url} object, into feed author metadata. Returns null for a missing or nameless author.

author

type unknown

returns

{ name: string; url?: string | undefined; email?: string | undefined; } | null

parse_blog_post_dirname
#

blog_post_dir.ts view source

(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).

name

type string

returns

BlogPostDir | 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

plan_blog_init
#

blog_init.ts view source

(options: BlogInitOptions, state: BlogInitState): BlogInitPlan import {plan_blog_init} from '@fuzdev/fuz_blog/blog_init.js';

Plans init.task.ts: resolves the new blog's config from options and package.json, validates it with validate_blog_configs, and lists an action for each file - creating only missing files and suggesting edits to existing ones, so running it again changes nothing. Generated files import from @fuzdev/fuz_blog and are unformatted.

options

state

returns

BlogInitPlan

throws

  • Error - when run in fuz_blog itself, without a `src/routes` directory, without a site URL or author, or when the resolved config is invalid

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

resolve_blog_feed_item
#

blog.ts view source

(post_dir: BlogPostDir, dirname: string, home_page_url: string, post: { title: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; } & Record<...>): { ...; } import {resolve_blog_feed_item} from '@fuzdev/fuz_blog/blog.js';

Derives a BlogFeedItem (the feed entry) from a post, its directory's id and slug, and its blog's dirname and home_page_url. Emits only BlogFeedItem fields - a consumer's extra post metadata stays on the page's post for its component to render, and does not leak into the typed generated feed.

post_dir

the post's id and slug, from its directory name

dirname

the blog's route directory under src/routes, from its BlogConfig

type string

home_page_url

the blog's index url, from its feed.home_page_url

type string

post

the author-defined post metadata

returns

BlogFeedItem

resolve_blog_post_dirs
#

blog_post_dir.ts view source

(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.

names

the names of the subdirectories of a blog's route directory

type string[]

blog_dirname

the blog's dirname, for error messages

type string

returns

BlogPostDir[]

throws

  • Error - on an invalid post directory name or a duplicate id

resolve_blog_post_pathname
#

blog_post_pathname.ts view source

(pathname: string): string import {resolve_blog_post_pathname} from '@fuzdev/fuz_blog/blog_post_pathname.js';

Resolves a post's app-relative pathname (a BlogFeedItem field) to an href under the deploy base path, with kit's resolve. Imports $app/paths, so it runs only in SvelteKit.

pathname

type string

returns

string

resolve_params_module_path
#

blog_helpers.ts view source

(dir: string, params_path: string, extensions: string[]): string | null import {resolve_params_module_path} from '@fuzdev/fuz_blog/blog_helpers.js';

Resolves SvelteKit's files.params to its existing module the way SvelteKit's resolve_entry does: the path itself when it's a file, else its directory's index with one of extensions, else a sibling file named the path's basename plus one of extensions.

dir

the project root

type string

params_path

files.params, relative to dir

type string

extensions

SvelteKit's moduleExtensions

type string[]

returns

string | null

the module's path relative to dir, or null when there is none

scaffold_blog_post
#

blog_helpers.ts view source

(options: BlogPostScaffoldOptions): string import {scaffold_blog_post} from '@fuzdev/fuz_blog/blog_helpers.js';

The default post scaffold for gro task src/lib/post.task.ts. Override per-blog with BlogConfig.scaffold.

options

returns

string

sort_feed_items
#

feed.ts view source

<T extends FeedItem>(items: readonly T[]): T[] import {sort_feed_items} from '@fuzdev/fuz_blog/feed.js';

Returns a copy of items sorted newest first by compare_feed_items.

items

type readonly T[]

returns

T[]

generics

sort_feed_items<T extends FeedItem>
T
constraint FeedItem

to_blog_dir
#

blog_helpers.ts view source

(dir: string, dirname: string): string import {to_blog_dir} from '@fuzdev/fuz_blog/blog_helpers.js';

Absolute path to a blog's route directory, src/routes/<dirname> in the project at dir. The routes directory is always src/routes - a custom SvelteKit files.routes is unsupported.

dir

the project root

type string

dirname

the blog's dirname, from its BlogConfig

type string

returns

string

to_blog_feed_url
#

blog.ts view source

(home_page_url: string): string import {to_blog_feed_url} from '@fuzdev/fuz_blog/blog.js';

Derives a blog's Atom feed URL from its home_page_url. gro gen writes the feed to static/<dirname>/feed.xml, served beside the blog's index, so the URL is <home_page_url>/feed.xml (a trailing slash on home_page_url is ignored).

home_page_url

type string

returns

string

to_blog_init_paths
#

blog_init.ts view source

(dirname: string): BlogInitPaths import {to_blog_init_paths} from '@fuzdev/fuz_blog/blog_init.js';

The project files plan_blog_init creates when missing, by role.

dirname

type string

returns

BlogInitPaths

to_blog_post_dirname
#

to_blog_post_path
#

blog_helpers.ts view source

(blog_dir: string, post_dir: BlogPostDir): string import {to_blog_post_path} from '@fuzdev/fuz_blog/blog_helpers.js';

blog_dir

type string

post_dir

returns

string

to_blog_post_redirect_entries
#

blog_post_redirect.ts view source

(feed: { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }): { ...; }[] import {to_blog_post_redirect_entries} from '@fuzdev/fuz_blog/blog_post_redirect.js';

The entries of the generated [post=blog_post_id] route: every post's bare id, so prerendering writes a redirect page for each.

feed

returns

{ post: string; }[]

to_blog_post_redirect_route_path
#

blog_helpers.ts view source

(blog_dir: string): string import {to_blog_post_redirect_route_path} from '@fuzdev/fuz_blog/blog_helpers.js';

Absolute path to a blog's generated redirect route module.

blog_dir

type string

returns

string

to_blog_post_slug
#

blog_helpers.ts view source

(title: string): string import {to_blog_post_slug} from '@fuzdev/fuz_blog/blog_helpers.js';

Derives a post slug from its title with fuz_util's slugify, normalizing underscores to hyphens so it matches BLOG_POST_SLUG_PATTERN. May return an empty string, e.g. for a title of only punctuation.

title

type string

returns

string

to_next_blog_post_id
#

blog_post_dir.ts view source

(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_dirs

returns

BlogPostId

to_params_module_create_path
#

blog_helpers.ts view source

(params_path: string, extensions: string[]): string import {to_params_module_create_path} from '@fuzdev/fuz_blog/blog_helpers.js';

The params module path to create when resolve_params_module_path finds none, chosen so it then resolves it: params_path itself when it ends with .js, .ts, or one of extensions, else params_path plus .ts when that's an extension, else plus the first extension.

params_path

SvelteKit's files.params

type string

extensions

SvelteKit's moduleExtensions

type string[]

returns

string

update_blog_post
#

blog_helpers.ts view source

(options: UpdateBlogPostOptions): Promise<UpdatedBlogPost> import {update_blog_post} from '@fuzdev/fuz_blog/blog_helpers.js';

Rewrites the date_modified of an existing post file for config, returning its id, path, and slug. Does not run gen - callers invoke that afterward (see update_post.task.ts).

options

returns

Promise<UpdatedBlogPost>

throws

  • Error - when `query` finds no single post (see `find_blog_post_dir`), `date` is before the post's `date_published` (when the file has exactly one quoted value to read), or the file has other than exactly one quoted `date_modified` value to replace

UpdateBlogPostOptions
#

blog_helpers.ts view source

UpdateBlogPostOptions import type {UpdateBlogPostOptions} from '@fuzdev/fuz_blog/blog_helpers.js';

dir

The project root, usually process.cwd().

type string

config

The target blog, e.g. from resolve_blog_config.

type BlogConfig

query

The post to update: its id, its <id>-<slug> directory name, or its slug (see find_blog_post_dir).

type string

date

ISO date written to date_modified.

type string

UpdatedBlogPost
#

blog_helpers.ts view source

UpdatedBlogPost import type {UpdatedBlogPost} from '@fuzdev/fuz_blog/blog_helpers.js';

blog_post_id

type BlogPostId

path

Absolute path to the updated +page.svelte.

type string

slug

The post's slug, from its directory name.

type string

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

write_blog_init_file
#

blog_helpers.ts view source

(dir: string, action: { kind: "create"; path: string; content: string; }): Promise<void> import {write_blog_init_file} from '@fuzdev/fuz_blog/blog_helpers.js';

Writes a create action of a plan_blog_init plan under dir, formatted with gro's format_file. Never overwrites.

dir

the project root

type string

action

the file to create

type { kind: "create"; path: string; content: string; }

returns

Promise<void>

throws

  • Error - naming the file when it was created since the plan was made