blog_helpers.ts

view source

Declarations
#

26 declarations

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.

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

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

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

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

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

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

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

Depends on
#

Imported by
#