@lvl99dotcom/edaha.md 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +258 -2
  3. package/dist/cli/bin.d.ts +2 -0
  4. package/dist/cli/bin.js +9 -0
  5. package/dist/cli/index.d.ts +41 -0
  6. package/dist/cli/index.js +110 -0
  7. package/dist/client/assets/index-BbKEbPS8.css +1 -0
  8. package/dist/client/assets/index-DtG7vi1d.js +559 -0
  9. package/dist/client/index.html +13 -0
  10. package/dist/editor/index.d.ts +62 -0
  11. package/dist/editor/index.js +102 -0
  12. package/dist/embeds/bandcamp/index.d.ts +9 -0
  13. package/dist/embeds/bandcamp/index.js +28 -0
  14. package/dist/embeds/index.d.ts +40 -0
  15. package/dist/embeds/index.js +71 -0
  16. package/dist/embeds/types/index.d.ts +14 -0
  17. package/dist/embeds/types/index.js +1 -0
  18. package/dist/embeds/youtube/index.d.ts +17 -0
  19. package/dist/embeds/youtube/index.js +48 -0
  20. package/dist/generator/article/index.d.ts +111 -0
  21. package/dist/generator/article/index.js +257 -0
  22. package/dist/generator/build/index.d.ts +77 -0
  23. package/dist/generator/build/index.js +293 -0
  24. package/dist/generator/config/index.d.ts +59 -0
  25. package/dist/generator/config/index.js +176 -0
  26. package/dist/generator/format/index.d.ts +52 -0
  27. package/dist/generator/format/index.js +102 -0
  28. package/dist/generator/lists/index.d.ts +63 -0
  29. package/dist/generator/lists/index.js +132 -0
  30. package/dist/generator/markdown/index.d.ts +20 -0
  31. package/dist/generator/markdown/index.js +55 -0
  32. package/dist/generator/slug/index.d.ts +26 -0
  33. package/dist/generator/slug/index.js +57 -0
  34. package/dist/generator/templates/index.d.ts +56 -0
  35. package/dist/generator/templates/index.js +109 -0
  36. package/dist/generator/types/index.d.ts +161 -0
  37. package/dist/generator/types/index.js +1 -0
  38. package/dist/generator/urls/index.d.ts +40 -0
  39. package/dist/generator/urls/index.js +67 -0
  40. package/dist/index.d.ts +10 -0
  41. package/dist/index.js +10 -0
  42. package/dist/server/app/index.d.ts +39 -0
  43. package/dist/server/app/index.js +138 -0
  44. package/dist/server/convert/index.d.ts +25 -0
  45. package/dist/server/convert/index.js +125 -0
  46. package/dist/server/store/index.d.ts +148 -0
  47. package/dist/server/store/index.js +411 -0
  48. package/dist/server/types/index.d.ts +76 -0
  49. package/dist/server/types/index.js +1 -0
  50. package/dist/theme/index.d.ts +8 -0
  51. package/dist/theme/index.js +9 -0
  52. package/package.json +93 -3
  53. package/theme/static/site.css +220 -0
  54. package/theme/templates/article/list.njk +69 -0
  55. package/theme/templates/article/single.njk +58 -0
  56. package/theme/templates/layouts/html.njk +50 -0
  57. package/theme/templates/layouts/rssfeed.njk +28 -0
  58. package/theme/templates/page/home.njk +21 -0
  59. package/theme/templates/page/single.njk +18 -0
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Article editor | edaha.md</title>
7
+ <script type="module" crossorigin src="/_editor/assets/index-DtG7vi1d.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/_editor/assets/index-BbKEbPS8.css">
9
+ </head>
10
+ <body>
11
+ <blog-editor></blog-editor>
12
+ </body>
13
+ </html>
@@ -0,0 +1,62 @@
1
+ import { Hono } from "hono";
2
+ /** The editor only listens on this computer's own address, so nothing else on the network can reach it */
3
+ export declare const EDITOR_HOST = "127.0.0.1";
4
+ /** The editor's default port */
5
+ export declare const EDITOR_PORT = 5180;
6
+ /** The URL path the editor page's own files (scripts, styles) are served under, apart from the site's static files */
7
+ export declare const EDITOR_BASE = "/_editor/";
8
+ /** The editor page's built files (`dist/client`, bundled by Vite). The path is the same from `dist/editor`. */
9
+ export declare const CLIENT_DIR: string;
10
+ /** Options for the article editor's server */
11
+ export interface EditorServerOptions {
12
+ /** The site folder (holds config.yml and articles/) */
13
+ siteDir: string;
14
+ /** The default theme folder that the site's templates and static files override. Default: THEME_DIR */
15
+ themeDir?: string;
16
+ /** The port to listen on. Default: EDITOR_PORT */
17
+ port?: number;
18
+ /** The editor page's built files. Default: CLIENT_DIR */
19
+ clientDir?: string;
20
+ /** Fetches extra data for embed previews (defaults to the global fetch) */
21
+ fetch?: typeof fetch;
22
+ }
23
+ /** A running editor server */
24
+ export interface EditorServer {
25
+ /** The editor's address, e.g. "http://127.0.0.1:5180" */
26
+ url: string;
27
+ /** Stop the server */
28
+ close: () => Promise<void>;
29
+ }
30
+ /**
31
+ * The editor's address for a port.
32
+ *
33
+ * @example
34
+ * editorUrl(5180); // "http://127.0.0.1:5180"
35
+ */
36
+ export declare const editorUrl: (port: number) => string;
37
+ /**
38
+ * The port an editor listens on: the given one, or EDITOR_PORT.
39
+ *
40
+ * @example
41
+ * editorPort({ siteDir: "my-site" }); // 5180
42
+ */
43
+ export declare const editorPort: (options: EditorServerOptions) => number;
44
+ /**
45
+ * Create the article editor's web app: the editor page at `/`, its files under `EDITOR_BASE`, and the editor API,
46
+ * previews and the site's static files (see createEditorApp) everywhere else.
47
+ *
48
+ * @example
49
+ * const app = createEditorServer({ siteDir: "my-site" });
50
+ * await app.request("/"); // the editor page
51
+ */
52
+ export declare const createEditorServer: (options: EditorServerOptions) => Hono;
53
+ /**
54
+ * Start the article editor on this computer only (`EDITOR_HOST`). Never deploy it: it reads and writes the site's
55
+ * files.
56
+ *
57
+ * @example
58
+ * const editor = await startEditor({ siteDir: "my-site" });
59
+ * console.log(`Open ${editor.url}`);
60
+ * await editor.close();
61
+ */
62
+ export declare const startEditor: (options: EditorServerOptions) => Promise<EditorServer>;
@@ -0,0 +1,102 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { serve } from "@hono/node-server";
5
+ import { Hono } from "hono";
6
+ import mime from "mime-types";
7
+ import { createEditorApp } from "../server/app/index.js";
8
+ import { ArticleStore } from "../server/store/index.js";
9
+ /** The editor only listens on this computer's own address, so nothing else on the network can reach it */
10
+ export const EDITOR_HOST = "127.0.0.1";
11
+ /** The editor's default port */
12
+ export const EDITOR_PORT = 5180;
13
+ /** The URL path the editor page's own files (scripts, styles) are served under, apart from the site's static files */
14
+ export const EDITOR_BASE = "/_editor/";
15
+ /** The editor page's built files (`dist/client`, bundled by Vite). The path is the same from `dist/editor`. */
16
+ export const CLIENT_DIR = fileURLToPath(new URL("../client", import.meta.url));
17
+ /**
18
+ * The editor's address for a port.
19
+ *
20
+ * @example
21
+ * editorUrl(5180); // "http://127.0.0.1:5180"
22
+ */
23
+ export const editorUrl = (port) => `http://${EDITOR_HOST}:${port}`;
24
+ /**
25
+ * The port an editor listens on: the given one, or EDITOR_PORT.
26
+ *
27
+ * @example
28
+ * editorPort({ siteDir: "my-site" }); // 5180
29
+ */
30
+ export const editorPort = (options) => options.port ?? EDITOR_PORT;
31
+ /**
32
+ * Read one of the editor page's built files, or undefined if there is no such file or the path leaves the folder.
33
+ */
34
+ const clientFile = async (clientDir, path) => {
35
+ const parts = path.split("/");
36
+ if (parts.some((part) => part === "" || part.startsWith(".")))
37
+ return undefined;
38
+ try {
39
+ return (await readFile(join(clientDir, ...parts)));
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ };
45
+ /**
46
+ * Create the article editor's web app: the editor page at `/`, its files under `EDITOR_BASE`, and the editor API,
47
+ * previews and the site's static files (see createEditorApp) everywhere else.
48
+ *
49
+ * @example
50
+ * const app = createEditorServer({ siteDir: "my-site" });
51
+ * await app.request("/"); // the editor page
52
+ */
53
+ export const createEditorServer = (options) => {
54
+ const port = editorPort(options);
55
+ const clientDir = options.clientDir ?? CLIENT_DIR;
56
+ const store = new ArticleStore(options.siteDir, options.themeDir);
57
+ const editorApp = createEditorApp(store, {
58
+ allowedOrigins: [editorUrl(port)],
59
+ fetch: options.fetch,
60
+ });
61
+ const app = new Hono();
62
+ app.get("/", async (c) => {
63
+ const html = await clientFile(clientDir, "index.html");
64
+ if (!html)
65
+ return c.text("The editor page is missing; build edaha.md with `pnpm build`", 500);
66
+ return c.body(html, 200, {
67
+ "Content-Type": "text/html; charset=utf-8",
68
+ "Cache-Control": "no-store",
69
+ });
70
+ });
71
+ app.get(`${EDITOR_BASE}*`, async (c) => {
72
+ const path = decodeURIComponent(c.req.path.slice(EDITOR_BASE.length));
73
+ const contents = await clientFile(clientDir, path);
74
+ if (!contents)
75
+ return c.json({ error: "File not found" }, 404);
76
+ return c.body(contents, 200, {
77
+ "Content-Type": mime.lookup(path) || "application/octet-stream",
78
+ });
79
+ });
80
+ app.route("/", editorApp);
81
+ return app;
82
+ };
83
+ /**
84
+ * Start the article editor on this computer only (`EDITOR_HOST`). Never deploy it: it reads and writes the site's
85
+ * files.
86
+ *
87
+ * @example
88
+ * const editor = await startEditor({ siteDir: "my-site" });
89
+ * console.log(`Open ${editor.url}`);
90
+ * await editor.close();
91
+ */
92
+ export const startEditor = (options) => {
93
+ const port = editorPort(options);
94
+ const app = createEditorServer(options);
95
+ return new Promise((resolve, reject) => {
96
+ const server = serve({ fetch: app.fetch, hostname: EDITOR_HOST, port }, () => resolve({
97
+ url: editorUrl(port),
98
+ close: () => new Promise((done, fail) => server.close((error) => (error ? fail(error) : done()))),
99
+ }));
100
+ server.once("error", reject);
101
+ });
102
+ };
@@ -0,0 +1,9 @@
1
+ import type { EmbedRenderer } from "../types/index.ts";
2
+ /**
3
+ * Embeds Bandcamp albums and tracks. Bandcamp URLs don't contain the album/track ID, so the page is fetched to find it.
4
+ *
5
+ * @example
6
+ * await bandcamp.render(new URL("https://artist.bandcamp.com/album/name"), { fetch });
7
+ */
8
+ export declare const bandcamp: EmbedRenderer;
9
+ export default bandcamp;
@@ -0,0 +1,28 @@
1
+ /** Album or track pages, e.g. /album/<name> */
2
+ const ITEM_PATH = /^\/(album|track)\/[^/]+/;
3
+ /** The embedded player URL in a Bandcamp page's `og:video` meta tag, e.g. ".../EmbeddedPlayer/v=2/album=123/..." */
4
+ const PLAYER_ITEM = /EmbeddedPlayer\/(?:v=\d+\/)?(album|track)=(\d+)/;
5
+ /**
6
+ * Embeds Bandcamp albums and tracks. Bandcamp URLs don't contain the album/track ID, so the page is fetched to find it.
7
+ *
8
+ * @example
9
+ * await bandcamp.render(new URL("https://artist.bandcamp.com/album/name"), { fetch });
10
+ */
11
+ export const bandcamp = {
12
+ name: "Bandcamp",
13
+ match: (url) => url.hostname.endsWith(".bandcamp.com") && ITEM_PATH.test(url.pathname),
14
+ render: async (url, { fetch }) => {
15
+ const response = await fetch(url);
16
+ if (!response.ok)
17
+ throw new Error(`Fetching ${url} failed with ${response.status}`);
18
+ const item = PLAYER_ITEM.exec(await response.text());
19
+ if (!item)
20
+ throw new Error(`No Bandcamp player found on ${url}`);
21
+ const [, kind, id] = item;
22
+ const size = kind === "album"
23
+ ? 'width="350" height="470"'
24
+ : 'width="350" height="442"';
25
+ return `<iframe ${size} src="https://bandcamp.com/EmbeddedPlayer/${kind}=${id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/transparent=true/" title="Bandcamp player" loading="lazy" seamless></iframe>`;
26
+ },
27
+ };
28
+ export default bandcamp;
@@ -0,0 +1,40 @@
1
+ import type { Logger } from "../generator/types/index.ts";
2
+ import type { EmbedContext, EmbedRenderer } from "./types/index.ts";
3
+ export type { EmbedContext, EmbedRenderer } from "./types/index.ts";
4
+ /** All embed renderers, tried in order */
5
+ export declare const EMBED_RENDERERS: readonly EmbedRenderer[];
6
+ /** `<!-- embed -->URL<!-- /embed -->` blocks in article markdown */
7
+ export declare const EMBED_BLOCK: RegExp;
8
+ /** Options for resolving embeds */
9
+ export interface EmbedOptions extends EmbedContext {
10
+ /** Renderers to try (defaults to all) */
11
+ renderers?: readonly EmbedRenderer[];
12
+ /** Where to report embeds that can't be rendered */
13
+ logger: Logger;
14
+ }
15
+ /**
16
+ * Renders embed URLs to HTML, rendering each URL only once.
17
+ *
18
+ * @example
19
+ * const embeds = new EmbedResolver({ fetch, logger: console });
20
+ * const markdown = await embeds.replaceBlocks(source, "article/hello");
21
+ */
22
+ export declare class EmbedResolver {
23
+ private readonly options;
24
+ private readonly cache;
25
+ constructor(options: EmbedOptions);
26
+ /**
27
+ * Render one URL to embed HTML wrapped in `<div class="embed">`. If no renderer matches, or it fails,
28
+ * warn and render a plain link instead.
29
+ *
30
+ * @param source - where the embed is, for warnings
31
+ */
32
+ render(rawUrl: string, source: string): Promise<string>;
33
+ /**
34
+ * Replace every `<!-- embed -->URL<!-- /embed -->` block in markdown with its rendered HTML, as its own block.
35
+ *
36
+ * @param source - where the markdown is from, for warnings
37
+ */
38
+ replaceBlocks(markdown: string, source: string): Promise<string>;
39
+ private renderUncached;
40
+ }
@@ -0,0 +1,71 @@
1
+ import { escapeHtml } from "../generator/format/index.js";
2
+ import { bandcamp } from "./bandcamp/index.js";
3
+ import { youtube } from "./youtube/index.js";
4
+ /** All embed renderers, tried in order */
5
+ export const EMBED_RENDERERS = [youtube, bandcamp];
6
+ /** `<!-- embed -->URL<!-- /embed -->` blocks in article markdown */
7
+ export const EMBED_BLOCK = /<!--\s*embed\s*-->([\s\S]*?)<!--\s*\/embed\s*-->/g;
8
+ /**
9
+ * Renders embed URLs to HTML, rendering each URL only once.
10
+ *
11
+ * @example
12
+ * const embeds = new EmbedResolver({ fetch, logger: console });
13
+ * const markdown = await embeds.replaceBlocks(source, "article/hello");
14
+ */
15
+ export class EmbedResolver {
16
+ options;
17
+ cache = new Map();
18
+ constructor(options) {
19
+ this.options = options;
20
+ }
21
+ /**
22
+ * Render one URL to embed HTML wrapped in `<div class="embed">`. If no renderer matches, or it fails,
23
+ * warn and render a plain link instead.
24
+ *
25
+ * @param source - where the embed is, for warnings
26
+ */
27
+ render(rawUrl, source) {
28
+ const cached = this.cache.get(rawUrl);
29
+ if (cached)
30
+ return cached;
31
+ const result = this.renderUncached(rawUrl, source);
32
+ this.cache.set(rawUrl, result);
33
+ return result;
34
+ }
35
+ /**
36
+ * Replace every `<!-- embed -->URL<!-- /embed -->` block in markdown with its rendered HTML, as its own block.
37
+ *
38
+ * @param source - where the markdown is from, for warnings
39
+ */
40
+ async replaceBlocks(markdown, source) {
41
+ const urls = [...markdown.matchAll(EMBED_BLOCK)].map(([, url]) => url.trim());
42
+ const html = await Promise.all(urls.map((url) => this.render(url, source)));
43
+ let index = 0;
44
+ return markdown.replace(EMBED_BLOCK, () => `\n\n${html[index++]}\n\n`);
45
+ }
46
+ async renderUncached(rawUrl, source) {
47
+ const { renderers = EMBED_RENDERERS, logger } = this.options;
48
+ const fallback = () => `<p class="embed-link"><a href="${escapeHtml(rawUrl)}">${escapeHtml(rawUrl)}</a></p>`;
49
+ let url;
50
+ try {
51
+ url = new URL(rawUrl);
52
+ }
53
+ catch {
54
+ logger.warn(`${source}: embed "${rawUrl}" is not a valid URL`);
55
+ return fallback();
56
+ }
57
+ const renderer = renderers.find((r) => r.match(url));
58
+ if (!renderer) {
59
+ logger.warn(`${source}: no embed renderer for ${rawUrl}; rendered as a link`);
60
+ return fallback();
61
+ }
62
+ try {
63
+ const html = await renderer.render(url, this.options);
64
+ return `<div class="embed embed-${renderer.name.toLowerCase()}">${html}</div>`;
65
+ }
66
+ catch (error) {
67
+ logger.warn(`${source}: ${renderer.name} embed failed for ${rawUrl} (${error.message}); rendered as a link`);
68
+ return fallback();
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,14 @@
1
+ /** What embed renderers may use while rendering */
2
+ export interface EmbedContext {
3
+ /** Fetches extra data, e.g. oEmbed JSON (replaceable for tests) */
4
+ fetch: typeof fetch;
5
+ }
6
+ /** Turns a URL into embed HTML */
7
+ export interface EmbedRenderer {
8
+ /** Name shown in warnings */
9
+ name: string;
10
+ /** Whether this renderer handles the URL */
11
+ match(url: URL): boolean;
12
+ /** Render the embed's HTML. Throws if the URL can't be embedded. */
13
+ render(url: URL, context: EmbedContext): Promise<string>;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { EmbedRenderer } from "../types/index.ts";
2
+ /**
3
+ * Get the video ID from any form of YouTube URL. Throws if there is none.
4
+ *
5
+ * @example
6
+ * extractYouTubeId(new URL("https://youtu.be/aju_UB5VIf8")); // "aju_UB5VIf8"
7
+ * extractYouTubeId(new URL("https://www.youtube.com/watch?v=aju_UB5VIf8")); // "aju_UB5VIf8"
8
+ */
9
+ export declare const extractYouTubeId: (url: URL) => string;
10
+ /**
11
+ * Embeds YouTube videos. Always uses youtube-nocookie.com, whatever form of YouTube URL is given.
12
+ *
13
+ * @example
14
+ * await youtube.render(new URL("https://youtu.be/aju_UB5VIf8"), context); // '<iframe ... src="https://www.youtube-nocookie.com/embed/aju_UB5VIf8" ...>'
15
+ */
16
+ export declare const youtube: EmbedRenderer;
17
+ export default youtube;
@@ -0,0 +1,48 @@
1
+ import { escapeHtml } from "../../generator/format/index.js";
2
+ const HOSTS = new Set([
3
+ "youtu.be",
4
+ "youtube.com",
5
+ "www.youtube.com",
6
+ "m.youtube.com",
7
+ "youtube-nocookie.com",
8
+ "www.youtube-nocookie.com",
9
+ ]);
10
+ /** YouTube video IDs are 11 URL-safe base64 characters */
11
+ const VIDEO_ID = /^[A-Za-z0-9_-]{11}$/;
12
+ /** Paths where the video ID follows the first segment, e.g. /embed/<id> */
13
+ const ID_PATHS = new Set(["embed", "shorts", "live", "v"]);
14
+ /**
15
+ * Get the video ID from any form of YouTube URL. Throws if there is none.
16
+ *
17
+ * @example
18
+ * extractYouTubeId(new URL("https://youtu.be/aju_UB5VIf8")); // "aju_UB5VIf8"
19
+ * extractYouTubeId(new URL("https://www.youtube.com/watch?v=aju_UB5VIf8")); // "aju_UB5VIf8"
20
+ */
21
+ export const extractYouTubeId = (url) => {
22
+ const [first = "", second = ""] = url.pathname.split("/").filter(Boolean);
23
+ const id = url.hostname === "youtu.be"
24
+ ? first
25
+ : first === "watch"
26
+ ? (url.searchParams.get("v") ?? "")
27
+ : ID_PATHS.has(first)
28
+ ? second
29
+ : "";
30
+ if (!VIDEO_ID.test(id))
31
+ throw new Error(`No YouTube video ID in ${url}`);
32
+ return id;
33
+ };
34
+ /**
35
+ * Embeds YouTube videos. Always uses youtube-nocookie.com, whatever form of YouTube URL is given.
36
+ *
37
+ * @example
38
+ * await youtube.render(new URL("https://youtu.be/aju_UB5VIf8"), context); // '<iframe ... src="https://www.youtube-nocookie.com/embed/aju_UB5VIf8" ...>'
39
+ */
40
+ export const youtube = {
41
+ name: "YouTube",
42
+ match: (url) => HOSTS.has(url.hostname),
43
+ render: async (url) => {
44
+ const src = `https://www.youtube-nocookie.com/embed/${extractYouTubeId(url)}`;
45
+ return `<iframe width="560" height="315" src="${escapeHtml(src)}" title="YouTube video player" loading="lazy" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>`;
46
+ },
47
+ };
48
+ export default youtube;
@@ -0,0 +1,111 @@
1
+ import type { ArticleStatus, TemplateDataArticle, TemplateDataAuthor, TemplateDataBlog, TemplateDataTag } from "../types/index.ts";
2
+ /** The `<!-- readmore -->` shortcode */
3
+ export declare const READMORE: RegExp;
4
+ /** Excerpts without a readmore shortcode or config are cropped to this many characters */
5
+ export declare const EXCERPT_LENGTH = 200;
6
+ /** An attachment as written in an article's config */
7
+ export interface AttachmentConfig {
8
+ url: string;
9
+ thumbnail?: string | undefined;
10
+ mimeType?: string | undefined;
11
+ name?: string | undefined;
12
+ }
13
+ /** An author as written in an article's config */
14
+ export interface AuthorConfig {
15
+ name: string;
16
+ email?: string | undefined;
17
+ url?: string | undefined;
18
+ }
19
+ /** An article's validated config header */
20
+ export interface ArticleConfig {
21
+ type: string;
22
+ status: ArticleStatus;
23
+ date: string;
24
+ author?: AuthorConfig | undefined;
25
+ title?: string | undefined;
26
+ template?: string | undefined;
27
+ excerpt?: string | undefined;
28
+ thumbnail?: string | undefined;
29
+ attachments: AttachmentConfig[];
30
+ tags: string[];
31
+ }
32
+ /**
33
+ * Split an article's source into its parsed YAML config header (empty if there is none) and its markdown content.
34
+ *
35
+ * @example
36
+ * splitArticle("<!--yaml\ndate: 2026-10-19\n-->\n# Hi"); // { header: { date: "2026-10-19" }, content: "\n# Hi" }
37
+ */
38
+ export declare const splitArticle: (source: string) => {
39
+ header: unknown;
40
+ content: string;
41
+ };
42
+ /**
43
+ * Validate an article's config header and fill in defaults.
44
+ *
45
+ * @param folderType - the type folder the article is in
46
+ * @param source - where the article is, for errors
47
+ *
48
+ * @example
49
+ * parseArticleConfig({ date: "2026-10-19T09:54:00Z" }, "article", "article/hello");
50
+ */
51
+ export declare const parseArticleConfig: (header: unknown, folderType: string, source: string) => ArticleConfig;
52
+ /** The article's content split into its parts */
53
+ export interface ArticleContent {
54
+ /** The title from the first H1, if any */
55
+ heading: string | undefined;
56
+ /** The body markdown, without a leading H1 or the readmore shortcode */
57
+ body: string;
58
+ /** The markdown before the readmore shortcode, if there is one */
59
+ beforeReadmore: string | undefined;
60
+ }
61
+ /**
62
+ * Split article markdown into its title heading, body and the part before `<!-- readmore -->`.
63
+ *
64
+ * @example
65
+ * splitContent("# Hi\n\nIntro <!-- readmore -->rest"); // { heading: "Hi", body: "\nIntro rest", beforeReadmore: "\nIntro" }
66
+ */
67
+ export declare const splitContent: (content: string) => ArticleContent;
68
+ /** Where an article is and how to render its parts */
69
+ export interface ArticleContext {
70
+ /** The blog the article belongs to */
71
+ blog: TemplateDataBlog;
72
+ /** The article's folder on disk */
73
+ dir: string;
74
+ /** The article's slug (its folder name) */
75
+ slug: string;
76
+ /** The article's URL, e.g. "/news/hello/" */
77
+ url: string;
78
+ /** The URL of the article type's front page, which its tag and author lists are under, e.g. "/news/" */
79
+ typeUrl: string;
80
+ /** Where the article is, for errors and warnings */
81
+ source: string;
82
+ /** Replace embed blocks in markdown with HTML */
83
+ replaceEmbeds(markdown: string): Promise<string>;
84
+ /** Render markdown to HTML, resolving relative URLs against a folder URL */
85
+ renderMarkdown(markdown: string, baseUrl: string): string;
86
+ }
87
+ /**
88
+ * Build an author's template data. Authors without a config are the website itself (the blog's name).
89
+ *
90
+ * @param typeUrl - the URL of the article type, which its author lists are under
91
+ *
92
+ * @example
93
+ * authorData({ name: "Matt Scheurich" }, "LiveCanvas", "/news/"); // { name: "Matt Scheurich", slug: "matt-scheurich", listUrl: "/news/authors/matt-scheurich/" }
94
+ */
95
+ export declare const authorData: (author: AuthorConfig | undefined, blogName: string, typeUrl: string) => TemplateDataAuthor;
96
+ /**
97
+ * Build a tag's template data.
98
+ *
99
+ * @param typeUrl - the URL of the article type, which its tag lists are under
100
+ *
101
+ * @example
102
+ * tagData("Release Notes", "/news/"); // { name: "Release Notes", slug: "release-notes", url: "/news/tags/release-notes/" }
103
+ */
104
+ export declare const tagData: (name: string, typeUrl: string) => TemplateDataTag;
105
+ /**
106
+ * Build an article's template data from its source. Returns undefined for drafts, which are not built.
107
+ *
108
+ * @example
109
+ * await loadArticle(source, "article", context);
110
+ */
111
+ export declare const loadArticle: (source: string, type: string, context: ArticleContext) => Promise<TemplateDataArticle | undefined>;