api #

blog software from scratch with SvelteKit

12 modules ยท 35 declarations

Modules
#

blog_feed_context
#

blog.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.js';

BlogConfig
#

blog.ts view source

BlogConfig import type {BlogConfig} from '@fuzdev/fuz_blog/blog.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 and no leading or trailing slash. Post pathnames derive from it.

type string

feed

Feed-level metadata. Post ids and urls derive from home_page_url, so set it to the blog's index page.

type BlogFeedMetadata

slug_routes?

Generate a slug redirect route for each post. When false, post URLs are the integer id paths.

type boolean

default true

scaffold?

Customizes the post file gro post 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 ...; blog_post_id: number; }[]; atom: { ...; }; } import {BlogFeed} from '@fuzdev/fuz_blog/blog.js';

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[]; slug: string; pathname: string; blog_post_id: number; } 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[]

slug

type string

pathname

type string

blog_post_id

type number

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; }; atom: { feed_url: string; }; } import {BlogFeedMetadata} from '@fuzdev/fuz_blog/blog.js';

A feed's metadata, without its items.

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; }

atom

type { feed_url: string; }

BlogPost
#

BlogPost.svelte view source

accepts children

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

post

item?

The resolved feed item. Defaults to looking post.slug up in blog_feed_context; pass it explicitly to skip the context.

optional

attrs?

type HTMLAttributes<HTMLElement>
optional

meta?

Renders after BlogPostHeader, e.g. for post provenance.

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

footer?

type Snippet<[]>
optional

comments?

Renders after footer, for a post's comments.

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

children

type Snippet<[]>

BlogPostHeader
#

BlogPostId
#

blog.ts view source

BlogPostId

type number & Flavor<"BlogPostId">

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

external types

Flavored<number, 'BlogPostId'>

BlogPostList
#

BlogPostMetadata
#

blog.ts view source

value + type

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

type { title: string; date_published: string; date_modified: string; summary: string; slug: 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).

title

type string

date_published

type string

date_modified

type string

summary

type string

slug

type string

tags?

type string[]

[key: string]

type unknown

BlogPostModule
#

BlogPostScaffoldOptions
#

blog.ts view source

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

The options gro post passes to a BlogConfig scaffold.

title

type string

slug

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.ts view source

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

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

blogs

type BlogConfig[]

collect_blog_post_ids
#

blog_helpers.ts view source

(blog_dir: string): BlogPostId[] import {collect_blog_post_ids} from '@fuzdev/fuz_blog/blog_helpers.js';

Returns an array of all of the sequential blog post ids starting with 1. When it fails to find the next id, the sequence ends.

blog_dir

type string

returns

BlogPostId[]

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';

data

type Feed

returns

string

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, returning its id, path, and slug. Does not run gen - callers invoke that afterward (see post.task.ts).

options

returns

Promise<CreatedBlogPost>

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; the slug is derived from it.

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

routes_path?

type string

default 'src/routes'

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';

This is designed to extend JSON Feed 1.1 with namespaced data for other specs like Atom. It's still a work in progress, and I'll add features as I need them, and eventually this will be extracted to a standalone library. 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
#

FeedUrl
#

feed.ts view source

PipeSchema<string, PipeSchema<string, Schema<string, string, "string", undefined>>>

type PipeSchema<string, PipeSchema<string, Schema<string, string, "string", undefined>>>

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.

format_date
#

util.ts view source

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

date

type string | number | Date

returns

string

HashLink
#

load_blog_post_modules
#

blog_helpers.ts view source

(blog_dir: string, blog_post_ids: BlogPostId[]): Promise<BlogPostModule[]> import {load_blog_post_modules} from '@fuzdev/fuz_blog/blog_helpers.js';

blog_dir

type string

blog_post_ids

type BlogPostId[]

returns

Promise<BlogPostModule[]>

load_blogs_module
#

blog_helpers.ts view source

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

Loads the consumer's src/routes/blogs.ts registry.

dir

type string

returns

Promise<BlogsModule>

resolve_blog_config
#

blog.ts view source

(blogs: BlogConfig[], dirname: string | undefined): BlogConfig import {resolve_blog_config} from '@fuzdev/fuz_blog/blog.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

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

Derives a BlogFeedItem (the feed entry) from a post 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.

blog_post_id

the post's incrementing 1-based id

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

options?

slug_routes: false makes url the integer-id id

type { slug_routes?: boolean | undefined; }
optional

returns

BlogFeedItem

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 post. Override per-blog with BlogConfig.scaffold.

options

returns

string

to_blog_post_path
#

blog_helpers.ts view source

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

blog_dir

type string

blog_post_id

returns

string

to_next_blog_post_id
#

update_blog_post
#

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

blog_post_id

The id of the post to update.

type BlogPostId

date

ISO date written to date_modified.

type string

routes_path?

type string

default 'src/routes'

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