blog_init.ts

Plans wiring fuz_blog into a SvelteKit project, for init.task.ts: from the project's state, the files to create, the existing files to leave alone, and the edits to existing files to suggest. Pure and free of node, gro, and Svelte imports - load_blog_init_state reads the state and write_blog_init_files writes the planned files.

view source

Declarations
#

11 declarations

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

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

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

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

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

Depends on
#

Imported by
#