@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,57 @@
1
+ /** Letters that don't split into a basic Latin letter plus diacritics */
2
+ const LATIN_EXTRA = {
3
+ ß: "ss",
4
+ æ: "ae",
5
+ œ: "oe",
6
+ ø: "o",
7
+ đ: "d",
8
+ ð: "d",
9
+ ł: "l",
10
+ þ: "th",
11
+ ı: "i",
12
+ };
13
+ /**
14
+ * Convert text to a lowercase, URL-safe `kebab-case` slug. Accented letters become basic Latin, quotes and
15
+ * apostrophes are removed, and any other runs of characters become a single `-`.
16
+ *
17
+ * @example
18
+ * slugify("What?! Who Is This?!? I don't think so..."); // "what-who-is-this-i-dont-think-so"
19
+ * slugify("Café Naïve"); // "cafe-naive"
20
+ */
21
+ export const slugify = (text) => text
22
+ .normalize("NFKD")
23
+ .replace(/\p{Diacritic}/gu, "")
24
+ .toLowerCase()
25
+ .replace(/[ßæœøđðłþı]/g, (letter) => LATIN_EXTRA[letter])
26
+ .replace(/['"‘’“”`´]/g, "")
27
+ .replace(/[^a-z0-9]+/g, "-")
28
+ .replace(/^-+|-+$/g, "");
29
+ /**
30
+ * Whether text is already a valid slug.
31
+ *
32
+ * @example
33
+ * isSlug("hello-world"); // true
34
+ * isSlug("Hello World"); // false
35
+ */
36
+ export const isSlug = (text) => text !== "" && slugify(text) === text;
37
+ /**
38
+ * IDs for a document's headings, from their text (as slugs): a repeated heading gets `-2`, `-3`… added, and a heading
39
+ * without letters or numbers gets none (an empty string).
40
+ *
41
+ * @example
42
+ * headingIds(["This?! Is an, example...", "Notes", "Notes", "!!!"]);
43
+ * // ["this-is-an-example", "notes", "notes-2", ""]
44
+ */
45
+ export const headingIds = (texts) => {
46
+ const used = new Set();
47
+ return texts.map((text) => {
48
+ const base = slugify(text);
49
+ if (!base)
50
+ return "";
51
+ let id = base;
52
+ for (let n = 2; used.has(id); n++)
53
+ id = `${base}-${n}`;
54
+ used.add(id);
55
+ return id;
56
+ });
57
+ };
@@ -0,0 +1,56 @@
1
+ import type { Logger, TemplateData } from "../types/index.ts";
2
+ /** Templates that must exist for the build to run */
3
+ export declare const REQUIRED_TEMPLATES: string[];
4
+ /**
5
+ * Make root-relative `href` and `src` URLs in HTML absolute, e.g. for RSS feeds read outside the website.
6
+ *
7
+ * @example
8
+ * absoluteUrls('<a href="/news/">', "https://example.com"); // '<a href="https://example.com/news/">'
9
+ */
10
+ export declare const absoluteUrls: (html: string, siteUrl: string) => string;
11
+ /**
12
+ * Loads and renders the blog's Nunjucks templates from one or more folders. A file in an earlier folder overrides the
13
+ * same file in later ones (e.g. a site's templates over the default theme's). Falls back to the `article` templates
14
+ * (with a warning) when an article type has none of its own.
15
+ *
16
+ * @example
17
+ * const templates = new Templates(["site/templates", join(THEME_DIR, "templates")], console);
18
+ * templates.render(templates.resolve("article", "single"), data);
19
+ */
20
+ export declare class Templates {
21
+ private readonly dirs;
22
+ private readonly logger;
23
+ private readonly env;
24
+ private readonly warned;
25
+ /**
26
+ * Throws if any of the required templates are missing.
27
+ */
28
+ constructor(dirs: string | string[], logger: Logger);
29
+ /**
30
+ * Whether a template file or folder exists in any of the template folders.
31
+ *
32
+ * @example
33
+ * templates.exists("page/home.njk"); // true
34
+ */
35
+ private exists;
36
+ /**
37
+ * The template file for an article type's template name (e.g. "single", "list" or "home"). Types without their own
38
+ * templates folder use `templates/article/`; a type folder without the template falls back to `templates/article/`
39
+ * with a warning (once per file). Throws if the template exists in neither.
40
+ *
41
+ * @example
42
+ * templates.resolve("page", "home"); // "page/home.njk" if it exists, otherwise "article/home.njk"
43
+ */
44
+ resolve(type: string, name: string): string;
45
+ /**
46
+ * The template names an article of a type can use (its own and the default ones, except "list"), sorted.
47
+ *
48
+ * @example
49
+ * templates.names("page"); // ["home", "single"]
50
+ */
51
+ names(type: string): string[];
52
+ /**
53
+ * Render a template with the given data.
54
+ */
55
+ render(file: string, data: TemplateData): string;
56
+ }
@@ -0,0 +1,109 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import nunjucks from "nunjucks";
4
+ import { formatDate, formatRfc822 } from "../format/index.js";
5
+ /** Templates that must exist for the build to run */
6
+ export const REQUIRED_TEMPLATES = [
7
+ "layouts/html.njk",
8
+ "layouts/rssfeed.njk",
9
+ "article/single.njk",
10
+ "article/list.njk",
11
+ ];
12
+ /**
13
+ * Make root-relative `href` and `src` URLs in HTML absolute, e.g. for RSS feeds read outside the website.
14
+ *
15
+ * @example
16
+ * absoluteUrls('<a href="/news/">', "https://example.com"); // '<a href="https://example.com/news/">'
17
+ */
18
+ export const absoluteUrls = (html, siteUrl) => html.replace(/(\s(?:href|src)=")\/(?!\/)/g, `$1${siteUrl}/`);
19
+ /**
20
+ * Loads and renders the blog's Nunjucks templates from one or more folders. A file in an earlier folder overrides the
21
+ * same file in later ones (e.g. a site's templates over the default theme's). Falls back to the `article` templates
22
+ * (with a warning) when an article type has none of its own.
23
+ *
24
+ * @example
25
+ * const templates = new Templates(["site/templates", join(THEME_DIR, "templates")], console);
26
+ * templates.render(templates.resolve("article", "single"), data);
27
+ */
28
+ export class Templates {
29
+ dirs;
30
+ logger;
31
+ env;
32
+ warned = new Set();
33
+ /**
34
+ * Throws if any of the required templates are missing.
35
+ */
36
+ constructor(dirs, logger) {
37
+ this.dirs = typeof dirs === "string" ? [dirs] : dirs;
38
+ const missing = REQUIRED_TEMPLATES.filter((file) => !this.exists(file));
39
+ if (missing.length)
40
+ throw new Error(`Missing required templates in ${this.dirs.join(", ")}: ${missing.join(", ")}`);
41
+ this.logger = logger;
42
+ this.env = new nunjucks.Environment(new nunjucks.FileSystemLoader(this.dirs), {
43
+ autoescape: true,
44
+ // Keep the generated HTML free of blank lines left by template tags
45
+ trimBlocks: true,
46
+ lstripBlocks: true,
47
+ });
48
+ this.env.addFilter("date", formatDate);
49
+ this.env.addFilter("rfc822", formatRfc822);
50
+ this.env.addFilter("absoluteUrls", absoluteUrls);
51
+ }
52
+ /**
53
+ * Whether a template file or folder exists in any of the template folders.
54
+ *
55
+ * @example
56
+ * templates.exists("page/home.njk"); // true
57
+ */
58
+ exists(file) {
59
+ return this.dirs.some((dir) => existsSync(join(dir, file)));
60
+ }
61
+ /**
62
+ * The template file for an article type's template name (e.g. "single", "list" or "home"). Types without their own
63
+ * templates folder use `templates/article/`; a type folder without the template falls back to `templates/article/`
64
+ * with a warning (once per file). Throws if the template exists in neither.
65
+ *
66
+ * @example
67
+ * templates.resolve("page", "home"); // "page/home.njk" if it exists, otherwise "article/home.njk"
68
+ */
69
+ resolve(type, name) {
70
+ const file = `${type}/${name}.njk`;
71
+ if (this.exists(file))
72
+ return file;
73
+ const fallback = `article/${name}.njk`;
74
+ if (!this.exists(fallback))
75
+ throw new Error(`Template "${name}" not found in templates/${type}/ or templates/article/`);
76
+ if (this.exists(type) && !this.warned.has(file)) {
77
+ this.warned.add(file);
78
+ this.logger.warn(`Template ${file} not found; using ${fallback}`);
79
+ }
80
+ return fallback;
81
+ }
82
+ /**
83
+ * The template names an article of a type can use (its own and the default ones, except "list"), sorted.
84
+ *
85
+ * @example
86
+ * templates.names("page"); // ["home", "single"]
87
+ */
88
+ names(type) {
89
+ const names = new Set();
90
+ for (const dir of this.dirs)
91
+ for (const folder of ["article", type]) {
92
+ try {
93
+ for (const file of readdirSync(join(dir, folder)))
94
+ if (file.endsWith(".njk") && file !== "list.njk")
95
+ names.add(file.slice(0, -4));
96
+ }
97
+ catch {
98
+ // A type without its own templates folder
99
+ }
100
+ }
101
+ return [...names].sort();
102
+ }
103
+ /**
104
+ * Render a template with the given data.
105
+ */
106
+ render(file, data) {
107
+ return this.env.render(file, data);
108
+ }
109
+ }
@@ -0,0 +1,161 @@
1
+ import type { ArticleTypeConfig, GenerateConfig } from "../config/index.ts";
2
+ /** Website data */
3
+ export interface TemplateDataSite {
4
+ /** The website's absolute URL, without a trailing slash, e.g. "https://livecanvas.lvl99.com" */
5
+ url: string;
6
+ }
7
+ /** What is built for an article type */
8
+ export type TemplateDataArticleTypeGenerationConfig = GenerateConfig;
9
+ /** An article type's settings */
10
+ export interface TemplateDataArticleType extends ArticleTypeConfig {
11
+ /** The URL of the type's front page (its list or index article), e.g. "/news/" */
12
+ url: string;
13
+ }
14
+ /** Blog data */
15
+ export interface TemplateDataBlog {
16
+ /** The name of the website */
17
+ name: string;
18
+ /** The website description */
19
+ description: string;
20
+ /** The blog's URL path prefix ("" for the website's root) */
21
+ path: string;
22
+ /** The URL of the blog's root, e.g. "/" */
23
+ url: string;
24
+ /** Article type settings (configured types, plus any other types articles use) */
25
+ types: Record<string, TemplateDataArticleType>;
26
+ }
27
+ /** An article's author */
28
+ export interface TemplateDataAuthor {
29
+ /** The author's name */
30
+ name: string;
31
+ /** The author's name converted to a slug */
32
+ slug: string;
33
+ /** The author's email address */
34
+ email?: string | undefined;
35
+ /** The author's homepage URL */
36
+ url?: string | undefined;
37
+ /** The URL to the author's list of articles */
38
+ listUrl: string;
39
+ }
40
+ /** A tag on an article */
41
+ export interface TemplateDataTag {
42
+ /** The tag's name */
43
+ name: string;
44
+ /** The tag's name converted to a slug */
45
+ slug: string;
46
+ /** The URL to the tag's list of articles */
47
+ url: string;
48
+ }
49
+ /** A downloadable attachment on an article */
50
+ export interface TemplateDataAttachment {
51
+ /** The attachment's name */
52
+ name: string;
53
+ /** The attachment's thumbnail URL */
54
+ thumbnail?: string | undefined;
55
+ /** The attachment's download URL */
56
+ url: string;
57
+ /** The attachment's mime type */
58
+ mimeType: string;
59
+ /** The attachment's file size in bytes (only for files in the article's subfolder) */
60
+ size?: number | undefined;
61
+ /** The attachment's file size in a human-readable form, e.g. "200 KB", "2.5 MB" */
62
+ sizeRelative?: string | undefined;
63
+ }
64
+ /** Article status: published articles are listed, unlisted ones only get their own page, drafts are not built */
65
+ export type ArticleStatus = "published" | "draft" | "unlisted";
66
+ /** A rendered article */
67
+ export interface TemplateDataArticle {
68
+ /** The article type */
69
+ type: string;
70
+ /** The article status (drafts are never rendered) */
71
+ status: Exclude<ArticleStatus, "draft">;
72
+ /** The article date (ISO 8601) */
73
+ date: string;
74
+ /** The article slug (i.e. the name of the article's subfolder) */
75
+ slug: string;
76
+ /** The template the article is rendered with, e.g. "single" */
77
+ template: string;
78
+ /** The article URL */
79
+ url: string;
80
+ /** The article title */
81
+ title: string;
82
+ /** The article author */
83
+ author: TemplateDataAuthor;
84
+ /** The article thumbnail URL */
85
+ thumbnail?: string | undefined;
86
+ /** The article tags */
87
+ tags: TemplateDataTag[];
88
+ /** The article excerpt (in markdown) */
89
+ excerpt: string;
90
+ /** The article excerpt (in plaintext, stripped of any formatting) */
91
+ excerptText: string;
92
+ /** The article excerpt (in HTML) */
93
+ excerptHtml: string;
94
+ /** The article body (in markdown) */
95
+ body: string;
96
+ /** The article body (in plaintext, stripped of any formatting) */
97
+ bodyText: string;
98
+ /** The article body (in HTML) */
99
+ bodyHtml: string;
100
+ /** Article attachments */
101
+ attachments: TemplateDataAttachment[];
102
+ }
103
+ /** One page of a paginated list */
104
+ export interface TemplateDataPaginationPage {
105
+ /** The page index (1, 2, ...) */
106
+ index: number;
107
+ /** The page URL, e.g. "/news/" for the first page, "/news/2" for the second */
108
+ url: string;
109
+ /** If the page is the current page or not */
110
+ isCurrent: boolean;
111
+ }
112
+ /** Pagination of a list */
113
+ export interface TemplateDataPagination {
114
+ /** The list of pages of articles */
115
+ pages: TemplateDataPaginationPage[];
116
+ /** The current page data */
117
+ page: TemplateDataPaginationPage;
118
+ /** The previous page data (only if not on first page) */
119
+ prevPage: TemplateDataPaginationPage | undefined;
120
+ /** The next page data (only if not on last page) */
121
+ nextPage: TemplateDataPaginationPage | undefined;
122
+ }
123
+ /** What a list groups articles by */
124
+ export type ListKind = "type" | "tag" | "author";
125
+ /** A paginated list of articles */
126
+ export interface TemplateDataList {
127
+ /** The list's name (the article type's plural label, the tag or the author name) */
128
+ name: string;
129
+ /** The slug of the article type/tag/author that was used for the list */
130
+ slug: string;
131
+ /** The article type the list belongs to */
132
+ type: string;
133
+ /** What the list groups articles by */
134
+ kind: ListKind;
135
+ /** The URL of the list's first page */
136
+ url: string;
137
+ /** The URL of the list's RSS feed */
138
+ feedUrl: string;
139
+ /** Whether the list has an RSS feed */
140
+ hasFeed: boolean;
141
+ /** The articles on the current page */
142
+ articles: TemplateDataArticle[];
143
+ /** The list's paginated pages */
144
+ pagination: TemplateDataPagination;
145
+ }
146
+ /** Everything given to a template */
147
+ export interface TemplateData {
148
+ /** Website data, always provided */
149
+ site: TemplateDataSite;
150
+ /** Blog data, always provided */
151
+ blog: TemplateDataBlog;
152
+ /** List data, provided when rendering list and feed templates, and index articles (the first page of their type's list) */
153
+ list?: TemplateDataList;
154
+ /** Article data, only provided when rendering single templates */
155
+ article?: TemplateDataArticle;
156
+ }
157
+ /** Where build warnings go */
158
+ export interface Logger {
159
+ /** Report a problem that doesn't stop the build */
160
+ warn(message: string): void;
161
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import type { ArticleTypeConfig } from "../config/index.ts";
2
+ /** Folders inside a type's URL path used by its tag and author lists */
3
+ export declare const RESERVED_SLUGS: string[];
4
+ /**
5
+ * Join URL path segments into a folder path relative to the website's root, ignoring empty segments.
6
+ *
7
+ * @example
8
+ * folderPath("", "news"); // "news/"
9
+ * folderPath("", ""); // ""
10
+ */
11
+ export declare const folderPath: (...segments: string[]) => string;
12
+ /**
13
+ * The root-relative URL of a folder path.
14
+ *
15
+ * @example
16
+ * folderUrl("news/"); // "/news/"
17
+ * folderUrl(""); // "/"
18
+ */
19
+ export declare const folderUrl: (folder: string) => string;
20
+ /**
21
+ * Check article types' URL paths: no two the same, and none clashing with the website's reserved paths at its root
22
+ * (`reservedPaths` in config.yml). Throws an Error describing the first problem.
23
+ *
24
+ * @param blogPath - the blog's URL path prefix
25
+ * @param reservedPaths - paths at the website's root that the blog can't use, e.g. another app's routes
26
+ *
27
+ * @example
28
+ * checkTypePaths("", { app: defaultTypeConfig("app") }, ["app"]); // throws: type "app" can't use the path "app"
29
+ */
30
+ export declare const checkTypePaths: (blogPath: string, types: Record<string, ArticleTypeConfig>, reservedPaths?: readonly string[]) => void;
31
+ /**
32
+ * Why an article slug can't be used in a type, or undefined if it can. Slugs can't be the tag and author list folders
33
+ * or numbers (list pages), and at the website's root, its reserved paths or another type's path.
34
+ *
35
+ * @param reservedPaths - paths at the website's root that the blog can't use (`reservedPaths` in config.yml)
36
+ *
37
+ * @example
38
+ * slugProblem("tags", "news", "", types); // 'the slug "tags" is used by tag lists'
39
+ */
40
+ export declare const slugProblem: (slug: string, type: string, blogPath: string, types: Record<string, ArticleTypeConfig>, reservedPaths?: readonly string[]) => string | undefined;
@@ -0,0 +1,67 @@
1
+ /** Folders inside a type's URL path used by its tag and author lists */
2
+ export const RESERVED_SLUGS = ["tags", "authors"];
3
+ /**
4
+ * Join URL path segments into a folder path relative to the website's root, ignoring empty segments.
5
+ *
6
+ * @example
7
+ * folderPath("", "news"); // "news/"
8
+ * folderPath("", ""); // ""
9
+ */
10
+ export const folderPath = (...segments) => segments
11
+ .filter(Boolean)
12
+ .map((segment) => `${segment}/`)
13
+ .join("");
14
+ /**
15
+ * The root-relative URL of a folder path.
16
+ *
17
+ * @example
18
+ * folderUrl("news/"); // "/news/"
19
+ * folderUrl(""); // "/"
20
+ */
21
+ export const folderUrl = (folder) => `/${folder}`;
22
+ /**
23
+ * Check article types' URL paths: no two the same, and none clashing with the website's reserved paths at its root
24
+ * (`reservedPaths` in config.yml). Throws an Error describing the first problem.
25
+ *
26
+ * @param blogPath - the blog's URL path prefix
27
+ * @param reservedPaths - paths at the website's root that the blog can't use, e.g. another app's routes
28
+ *
29
+ * @example
30
+ * checkTypePaths("", { app: defaultTypeConfig("app") }, ["app"]); // throws: type "app" can't use the path "app"
31
+ */
32
+ export const checkTypePaths = (blogPath, types, reservedPaths = []) => {
33
+ const seen = new Map();
34
+ for (const [type, { path }] of Object.entries(types)) {
35
+ const other = seen.get(path);
36
+ if (other !== undefined)
37
+ throw new Error(`config.yml: types "${other}" and "${type}" have the same path "${path}"`);
38
+ seen.set(path, type);
39
+ if (!blogPath && reservedPaths.includes(path))
40
+ throw new Error(`config.yml: type "${type}" can't use the path "${path}", which is reserved`);
41
+ }
42
+ };
43
+ /**
44
+ * Why an article slug can't be used in a type, or undefined if it can. Slugs can't be the tag and author list folders
45
+ * or numbers (list pages), and at the website's root, its reserved paths or another type's path.
46
+ *
47
+ * @param reservedPaths - paths at the website's root that the blog can't use (`reservedPaths` in config.yml)
48
+ *
49
+ * @example
50
+ * slugProblem("tags", "news", "", types); // 'the slug "tags" is used by tag lists'
51
+ */
52
+ export const slugProblem = (slug, type, blogPath, types, reservedPaths = []) => {
53
+ if (RESERVED_SLUGS.includes(slug))
54
+ return `the slug "${slug}" is used by ${slug === "tags" ? "tag" : "author"} lists`;
55
+ if (/^\d+$/.test(slug))
56
+ return `the slug "${slug}" is used by list pages`;
57
+ // A type that isn't configured is at its own name
58
+ const atRoot = !blogPath && !(types[type]?.path ?? type);
59
+ if (atRoot && reservedPaths.includes(slug))
60
+ return `the slug "${slug}" is reserved`;
61
+ if (atRoot) {
62
+ const other = Object.entries(types).find(([name, config]) => name !== type && config.path === slug);
63
+ if (other)
64
+ return `the slug "${slug}" is the path of type "${other[0]}"`;
65
+ }
66
+ return undefined;
67
+ };
@@ -0,0 +1,10 @@
1
+ export { buildBlog, DEFAULT_SITE_URL, type BuildOptions, type BuildResult, } from "./generator/build/index.ts";
2
+ export { parseConfig, type ArticleTypeConfig, type BlogConfig, type GenerateConfig, } from "./generator/config/index.ts";
3
+ export { REQUIRED_TEMPLATES } from "./generator/templates/index.ts";
4
+ export type * from "./generator/types/index.ts";
5
+ export { EMBED_RENDERERS, type EmbedContext, type EmbedRenderer, } from "./embeds/index.ts";
6
+ export { youtube } from "./embeds/youtube/index.ts";
7
+ export { bandcamp } from "./embeds/bandcamp/index.ts";
8
+ export { createEditorServer, EDITOR_HOST, EDITOR_PORT, startEditor, type EditorServer, type EditorServerOptions, } from "./editor/index.ts";
9
+ export { runCli, type CliContext } from "./cli/index.ts";
10
+ export { THEME_DIR } from "./theme/index.ts";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // edaha.md's public API: build a site from Markdown articles, run the article editor, and add embed renderers
2
+ export { buildBlog, DEFAULT_SITE_URL, } from "./generator/build/index.js";
3
+ export { parseConfig, } from "./generator/config/index.js";
4
+ export { REQUIRED_TEMPLATES } from "./generator/templates/index.js";
5
+ export { EMBED_RENDERERS, } from "./embeds/index.js";
6
+ export { youtube } from "./embeds/youtube/index.js";
7
+ export { bandcamp } from "./embeds/bandcamp/index.js";
8
+ export { createEditorServer, EDITOR_HOST, EDITOR_PORT, startEditor, } from "./editor/index.js";
9
+ export { runCli } from "./cli/index.js";
10
+ export { THEME_DIR } from "./theme/index.js";
@@ -0,0 +1,39 @@
1
+ import { Hono } from "hono";
2
+ import { type ArticleStore } from "../store/index.ts";
3
+ /** Options for the editor API */
4
+ export interface EditorAppOptions {
5
+ /** Origins allowed to change articles, e.g. "http://127.0.0.1:5180" */
6
+ allowedOrigins: readonly string[];
7
+ /** Fetches extra data for embed previews (defaults to the global fetch) */
8
+ fetch?: typeof fetch | undefined;
9
+ }
10
+ /**
11
+ * The Content Security Policy of preview pages and their files: like the website's news pages (its own files, YouTube
12
+ * and Bandcamp embeds), but with no scripts, requests or forms at all. Previews are served from the editor's own
13
+ * address, so this is what stops anything in an article from using the editor's API.
14
+ */
15
+ export declare const PREVIEW_CSP = "default-src 'self'; script-src 'none'; frame-src https://www.youtube-nocookie.com https://bandcamp.com; style-src 'self'; style-src-attr 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'self'";
16
+ /**
17
+ * Create the article editor's local API. Requests that change files must come from the editor's own page (checked
18
+ * with the Origin header), so other websites open in the same browser can't write articles.
19
+ *
20
+ * Routes:
21
+ * - `GET /api/articles`: list articles
22
+ * - `GET /api/types`: the article types from config.yml, with their labels
23
+ * - `GET /api/templates/:type`: the template names an article of a type can use
24
+ * - `POST /api/articles`: create an article
25
+ * - `GET|PUT|DELETE /api/articles/:type/:slug`: load, save (and move) or delete an article
26
+ * - `POST /api/articles/:type/:slug/files`: upload a file (multipart field "file")
27
+ * - `GET /files/:type/:slug/:name`: an article's file, for previews in the editor
28
+ * - `GET /api/embed?url=...`: render an embed URL as the website would, for previews in the editor
29
+ * - `POST /api/convert/markdown` and `POST /api/convert/html`: convert an article body between editor HTML and Markdown
30
+ * (`{ html | markdown, location? }`, where `location` is the saved article's, which relative URLs are relative to)
31
+ * - `POST /api/preview`: remember unsaved article data (`{ data, location? }`) for a preview page, and give its URL
32
+ * (`{ url }`); answers 400 if it can't be rendered
33
+ * - `GET /preview/:id/`: render a remembered preview with its type's "single" template, and `GET /<path>`: one of the
34
+ * blog's static files (e.g. `/site.css`), both with a Content Security Policy that forbids scripts (`PREVIEW_CSP`)
35
+ *
36
+ * @example
37
+ * const app = createEditorApp(new ArticleStore("packages/blog"), { allowedOrigins: ["http://127.0.0.1:5180"] });
38
+ */
39
+ export declare const createEditorApp: (store: ArticleStore, { allowedOrigins, fetch: fetchFn, }: EditorAppOptions) => Hono;