@lvl99dotcom/edaha.md 0.0.0-stage → 0.2.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.
- package/LICENSE +201 -0
- package/README.md +13 -2
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +9 -0
- package/dist/cli/index.d.ts +71 -0
- package/dist/cli/index.js +149 -0
- package/dist/embeds/blocks/index.d.ts +59 -0
- package/dist/embeds/blocks/index.js +103 -0
- package/dist/embeds/index.d.ts +143 -0
- package/dist/embeds/index.js +411 -0
- package/dist/embeds/types/index.d.ts +117 -0
- package/dist/embeds/types/index.js +1 -0
- package/dist/generator/article/index.d.ts +151 -0
- package/dist/generator/article/index.js +325 -0
- package/dist/generator/build/index.d.ts +109 -0
- package/dist/generator/build/index.js +363 -0
- package/dist/generator/config/index.d.ts +96 -0
- package/dist/generator/config/index.js +298 -0
- package/dist/generator/configFile/index.d.ts +58 -0
- package/dist/generator/configFile/index.js +122 -0
- package/dist/generator/fields/index.d.ts +93 -0
- package/dist/generator/fields/index.js +186 -0
- package/dist/generator/format/index.d.ts +92 -0
- package/dist/generator/format/index.js +177 -0
- package/dist/generator/lists/index.d.ts +63 -0
- package/dist/generator/lists/index.js +133 -0
- package/dist/generator/markdown/index.d.ts +25 -0
- package/dist/generator/markdown/index.js +62 -0
- package/dist/generator/metadata/index.d.ts +150 -0
- package/dist/generator/metadata/index.js +361 -0
- package/dist/generator/metadataGroups/index.d.ts +45 -0
- package/dist/generator/metadataGroups/index.js +169 -0
- package/dist/generator/slug/index.d.ts +26 -0
- package/dist/generator/slug/index.js +57 -0
- package/dist/generator/templates/index.d.ts +88 -0
- package/dist/generator/templates/index.js +175 -0
- package/dist/generator/types/index.d.ts +186 -0
- package/dist/generator/types/index.js +1 -0
- package/dist/generator/urls/index.d.ts +50 -0
- package/dist/generator/urls/index.js +77 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/index.js +9 -0
- package/package.json +64 -3
- package/theme/static/base.css +328 -0
- package/theme/templates/article/list.njk +69 -0
- package/theme/templates/article/single.njk +64 -0
- package/theme/templates/layouts/html.njk +72 -0
- package/theme/templates/layouts/rssfeed.njk +28 -0
- package/theme/templates/page/home.njk +16 -0
- package/theme/templates/page/single.njk +18 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { cp, mkdir, readdir, readFile, rm, stat, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
3
|
+
import { cachedFetch, EMBED_PAGE_PARTS, EmbedResolver, } from "../../embeds/index.js";
|
|
4
|
+
import { loadArticle } from "../article/index.js";
|
|
5
|
+
import { MetadataValidator, typeMetadataKeys } from "../metadata/index.js";
|
|
6
|
+
import { defaultTypeConfig, RESERVED_TYPES, SOURCE_FOLDERS, } from "../config/index.js";
|
|
7
|
+
import { loadSiteConfig } from "../configFile/index.js";
|
|
8
|
+
import { collectLists, PAGE_SIZE, pageFile, paginate } from "../lists/index.js";
|
|
9
|
+
import { createMarkdown, renderMarkdown } from "../markdown/index.js";
|
|
10
|
+
import { isSlug } from "../slug/index.js";
|
|
11
|
+
import { THEME_DIR } from "../../theme/index.js";
|
|
12
|
+
import { Templates } from "../templates/index.js";
|
|
13
|
+
import { checkTypePaths, folderPath, baseUrlOf, folderUrl, slugProblem, } from "../urls/index.js";
|
|
14
|
+
export { RESERVED_TYPES } from "../config/index.js";
|
|
15
|
+
/** Used for feeds when neither `SITE_URL` nor `siteUrl` in the config file is set */
|
|
16
|
+
export const DEFAULT_SITE_URL = "http://localhost";
|
|
17
|
+
/** List the names of sub-folders in a folder (none if it doesn't exist) */
|
|
18
|
+
const subfolders = async (dir) => {
|
|
19
|
+
try {
|
|
20
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
21
|
+
return entries
|
|
22
|
+
.filter((entry) => entry.isDirectory())
|
|
23
|
+
.map((entry) => entry.name)
|
|
24
|
+
.sort();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/** List every file in a folder and its sub-folders, relative to it (none if it doesn't exist) */
|
|
31
|
+
const listFiles = async (dir) => {
|
|
32
|
+
try {
|
|
33
|
+
const entries = await readdir(dir, {
|
|
34
|
+
recursive: true,
|
|
35
|
+
withFileTypes: true,
|
|
36
|
+
});
|
|
37
|
+
return entries
|
|
38
|
+
.filter((entry) => entry.isFile())
|
|
39
|
+
.map((entry) => relative(dir, join(entry.parentPath, entry.name)).split(sep).join("/"))
|
|
40
|
+
.sort();
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** Whether a path exists */
|
|
47
|
+
const exists = (path) => stat(path).then(() => true, () => false);
|
|
48
|
+
/** Whether one folder is the other or inside it */
|
|
49
|
+
const overlaps = (a, b) => {
|
|
50
|
+
const fromA = relative(a, b);
|
|
51
|
+
const fromB = relative(b, a);
|
|
52
|
+
return !fromA || !fromB || !fromA.startsWith("..") || !fromB.startsWith("..");
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Resolve `outputDir` from the config file: a folder inside the site folder, apart from its source folders (the
|
|
56
|
+
* articles, templates and static files folders), as it is emptied on every build.
|
|
57
|
+
*
|
|
58
|
+
* @param sources - the source folders, relative to the site folder (default: the default ones)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* resolveOutputDir("/site", "build"); // "/site/build"
|
|
62
|
+
* resolveOutputDir("/site", "site/build", ["site/content", "site/templates", "site/static"]); // "/site/site/build"
|
|
63
|
+
*/
|
|
64
|
+
export const resolveOutputDir = (siteDir, folder, sources = Object.values(SOURCE_FOLDERS)) => {
|
|
65
|
+
const dir = resolve(siteDir, folder);
|
|
66
|
+
const fromSite = relative(resolve(siteDir), dir);
|
|
67
|
+
if (!fromSite || fromSite.startsWith("..") || isAbsolute(fromSite))
|
|
68
|
+
throw new Error(`"outputDir" must be a folder inside the site folder, got "${folder}"`);
|
|
69
|
+
if (sources.some((source) => overlaps(join(siteDir, source), dir)))
|
|
70
|
+
throw new Error(`"outputDir" must be apart from ${sources.join(", ")}, got "${folder}"`);
|
|
71
|
+
return dir;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Resolve `publishDir` from the config file, relative to the site folder: any folder apart from the site folder, e.g.
|
|
75
|
+
* another app's build folder.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* resolvePublishDir("/work/site", "../app/dist"); // "/work/app/dist"
|
|
79
|
+
*/
|
|
80
|
+
export const resolvePublishDir = (siteDir, folder) => {
|
|
81
|
+
const dir = resolve(siteDir, folder);
|
|
82
|
+
if (overlaps(resolve(siteDir), dir))
|
|
83
|
+
throw new Error(`"publishDir" must be a folder apart from the site folder, got "${folder}"`);
|
|
84
|
+
return dir;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Map each static file's path to its source: the theme's files, overridden by the site's files with the same path.
|
|
88
|
+
*
|
|
89
|
+
* @param dirs - static folders, the overriding one last
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* await staticFiles(["/theme/static", "/site/static"]); // Map { "site.css" => "/site/static/site.css", ... }
|
|
93
|
+
*/
|
|
94
|
+
export const staticFiles = async (dirs) => {
|
|
95
|
+
const files = new Map();
|
|
96
|
+
for (const dir of dirs)
|
|
97
|
+
for (const file of await listFiles(dir))
|
|
98
|
+
files.set(file, join(dir, file));
|
|
99
|
+
// Sorted by path, comparing characters (not the locale's order)
|
|
100
|
+
return new Map([...files].sort(([a], [b]) => Number(a > b) - Number(a < b)));
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* An article type's template data: its settings and URL.
|
|
104
|
+
*/
|
|
105
|
+
const typeData = (sitePath, config, baseUrl) => ({
|
|
106
|
+
...config,
|
|
107
|
+
url: folderUrl(folderPath(sitePath, config.path), baseUrl),
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* The website's template data: its name, description, absolute URL and home URL, default author, and each article
|
|
111
|
+
* type's settings and URL.
|
|
112
|
+
*
|
|
113
|
+
* @param typeConfigs - the article types' settings (configured ones, plus defaults for any others)
|
|
114
|
+
* @param url - the website's absolute URL (a trailing slash is removed)
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* siteData(config, config.types, "https://example.com").types.news.url; // "/news/"
|
|
118
|
+
*/
|
|
119
|
+
export const siteData = (config, typeConfigs, url) => {
|
|
120
|
+
const baseUrl = baseUrlOf(url);
|
|
121
|
+
return {
|
|
122
|
+
name: config.name,
|
|
123
|
+
description: config.description,
|
|
124
|
+
url: url.replace(/\/+$/, ""),
|
|
125
|
+
baseUrl,
|
|
126
|
+
path: folderUrl(folderPath(config.path), baseUrl),
|
|
127
|
+
author: config.author === false
|
|
128
|
+
? undefined
|
|
129
|
+
: (config.author ?? { name: config.name }),
|
|
130
|
+
types: Object.fromEntries(Object.entries(typeConfigs).map(([type, typeConfig]) => [
|
|
131
|
+
type,
|
|
132
|
+
typeData(config.path, typeConfig, baseUrl),
|
|
133
|
+
])),
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* The template data for an article's page, with its type's list for an index article.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* articlePageData(site, article); // { site, type: "news", isArticle: true, isList: false, article }
|
|
141
|
+
*/
|
|
142
|
+
export const articlePageData = (site, article, list) => ({
|
|
143
|
+
site,
|
|
144
|
+
type: article.type,
|
|
145
|
+
isArticle: true,
|
|
146
|
+
isList: false,
|
|
147
|
+
article,
|
|
148
|
+
...(list ? { list } : {}),
|
|
149
|
+
});
|
|
150
|
+
/**
|
|
151
|
+
* The template data for a list's page or feed.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* listPageData(site, list); // { site, type: "news", isArticle: false, isList: true, list }
|
|
155
|
+
*/
|
|
156
|
+
export const listPageData = (site, list) => ({
|
|
157
|
+
site,
|
|
158
|
+
type: list.type,
|
|
159
|
+
isArticle: false,
|
|
160
|
+
isList: true,
|
|
161
|
+
list,
|
|
162
|
+
});
|
|
163
|
+
/**
|
|
164
|
+
* The embed plugins to build with: the config file's, then the given ones whose keys the config file doesn't use.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* withPlugins([youtube], [youtube2, mermaidjs]); // [youtube, mermaidjs]
|
|
168
|
+
*/
|
|
169
|
+
export const withPlugins = (configPlugins, plugins = []) => {
|
|
170
|
+
const keys = new Set(configPlugins.map((plugin) => plugin.key));
|
|
171
|
+
return [
|
|
172
|
+
...configPlugins,
|
|
173
|
+
...plugins.filter((plugin) => !keys.has(plugin.key)),
|
|
174
|
+
];
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Build the site: render every published and unlisted article with its assets, then each type's paginated list and
|
|
178
|
+
* RSS feed, and its tag and author lists, and copy the static files (the theme's, overridden by the site's `static/`)
|
|
179
|
+
* as they are. Files are written to `outputDir` (emptied first). If `publishDir` is set, they are then copied into it
|
|
180
|
+
* (the website's root): the files published by the previous build are removed from it first, and the build stops if a
|
|
181
|
+
* file is already there.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* await buildSite({ siteDir: "my-site", siteUrl: "https://example.com" });
|
|
185
|
+
*/
|
|
186
|
+
export const buildSite = async (options) => {
|
|
187
|
+
const logger = options.logger ?? console;
|
|
188
|
+
const { configFile, siteDir, config } = await loadSiteConfig({
|
|
189
|
+
siteDir: options.siteDir,
|
|
190
|
+
configFile: options.configFile,
|
|
191
|
+
logger,
|
|
192
|
+
});
|
|
193
|
+
const configName = basename(configFile);
|
|
194
|
+
const themeDir = options.themeDir ?? THEME_DIR;
|
|
195
|
+
/** Run a check of the config's settings, naming the config file in its error */
|
|
196
|
+
const checkConfig = (check) => {
|
|
197
|
+
try {
|
|
198
|
+
return check();
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw new Error(`${configName}: ${error.message}`, {
|
|
202
|
+
cause: error,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const outputDir = checkConfig(() => resolveOutputDir(siteDir, config.outputDir, [
|
|
207
|
+
config.articlesDir,
|
|
208
|
+
config.templatesDir,
|
|
209
|
+
config.staticDir,
|
|
210
|
+
]));
|
|
211
|
+
const publishDir = config.publishDir === undefined
|
|
212
|
+
? undefined
|
|
213
|
+
: checkConfig(() => resolvePublishDir(siteDir, config.publishDir));
|
|
214
|
+
const templates = new Templates([join(siteDir, config.templatesDir), join(themeDir, "templates")], logger);
|
|
215
|
+
const siteUrl = options.siteUrl || config.siteUrl;
|
|
216
|
+
if (!siteUrl)
|
|
217
|
+
logger.warn(`SITE_URL is not set and ${configName} has no "siteUrl"; feeds will link to ${DEFAULT_SITE_URL}`);
|
|
218
|
+
// Article types: configured ones, plus any other type folders (with defaults)
|
|
219
|
+
const articlesDir = join(siteDir, config.articlesDir);
|
|
220
|
+
const typeFolders = await subfolders(articlesDir);
|
|
221
|
+
const typeConfigs = { ...config.types };
|
|
222
|
+
for (const type of typeFolders) {
|
|
223
|
+
if (!isSlug(type) || RESERVED_TYPES.includes(type))
|
|
224
|
+
throw new Error(`${config.articlesDir}/${type}: article types must be lowercase kebab-case and not ${RESERVED_TYPES.join(" or ")}`);
|
|
225
|
+
if (!typeConfigs[type]) {
|
|
226
|
+
logger.warn(`${config.articlesDir}/${type}: type "${type}" is not in ${configName}; using the default settings`);
|
|
227
|
+
typeConfigs[type] = defaultTypeConfig(type);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
checkConfig(() => checkTypePaths(config.path, typeConfigs, config.reservedPaths));
|
|
231
|
+
const site = siteData(config, typeConfigs, siteUrl || DEFAULT_SITE_URL);
|
|
232
|
+
const markdown = createMarkdown();
|
|
233
|
+
const embeds = new EmbedResolver({
|
|
234
|
+
// Pages that show the same embed don't fetch it again
|
|
235
|
+
fetch: cachedFetch(options.fetch ?? fetch),
|
|
236
|
+
logger,
|
|
237
|
+
plugins: withPlugins(config.plugins, options.plugins),
|
|
238
|
+
});
|
|
239
|
+
// Remove what the previous build published, then empty the build folder
|
|
240
|
+
if (publishDir)
|
|
241
|
+
for (const file of await listFiles(outputDir))
|
|
242
|
+
await rm(join(publishDir, file), { force: true });
|
|
243
|
+
await rm(outputDir, { recursive: true, force: true });
|
|
244
|
+
const files = [];
|
|
245
|
+
const write = async (file, contents) => {
|
|
246
|
+
const path = join(outputDir, file);
|
|
247
|
+
await mkdir(dirname(path), { recursive: true });
|
|
248
|
+
await writeFile(path, contents);
|
|
249
|
+
files.push(file);
|
|
250
|
+
};
|
|
251
|
+
// Validates articles' custom metadata
|
|
252
|
+
const validator = new MetadataValidator(config.metadata);
|
|
253
|
+
// Load articles (types that generate nothing are still checked for errors)
|
|
254
|
+
const articles = [];
|
|
255
|
+
for (const type of typeFolders) {
|
|
256
|
+
const typeConfig = site.types[type];
|
|
257
|
+
const built = typeConfig.generate.article;
|
|
258
|
+
// The type's folder in the output folder: its URL without the site's base URL
|
|
259
|
+
const typeFolder = typeConfig.url.slice(site.baseUrl.length + 1);
|
|
260
|
+
for (const slug of await subfolders(join(articlesDir, type))) {
|
|
261
|
+
const source = `${config.articlesDir}/${type}/${slug}`;
|
|
262
|
+
if (!isSlug(slug))
|
|
263
|
+
throw new Error(`${source}: folder names must be lowercase kebab-case`);
|
|
264
|
+
const problem = slugProblem(slug, type, config.path, typeConfigs, config.reservedPaths);
|
|
265
|
+
if (problem)
|
|
266
|
+
throw new Error(`${source}: ${problem}`);
|
|
267
|
+
const dir = join(articlesDir, type, slug);
|
|
268
|
+
let text;
|
|
269
|
+
try {
|
|
270
|
+
text = await readFile(join(dir, "article.md"), "utf8");
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
logger.warn(`${source}: no article.md; skipped`);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
// An index article is its type's front page
|
|
277
|
+
const folder = slug === "index" ? typeFolder : `${typeFolder}${slug}/`;
|
|
278
|
+
const article = await loadArticle(text, type, {
|
|
279
|
+
site,
|
|
280
|
+
dir,
|
|
281
|
+
slug,
|
|
282
|
+
url: folderUrl(folder, site.baseUrl),
|
|
283
|
+
typeUrl: typeConfig.url,
|
|
284
|
+
source,
|
|
285
|
+
// Embeds are rendered with the pages that show them
|
|
286
|
+
replaceEmbeds: async (md) => embeds.replaceBlocks(md, source),
|
|
287
|
+
renderMarkdown: (md, baseUrl) => renderMarkdown(markdown, md, baseUrl, site.baseUrl),
|
|
288
|
+
metadata: {
|
|
289
|
+
validator,
|
|
290
|
+
keys: typeMetadataKeys(config.metadata, typeConfigs[type]?.metadata),
|
|
291
|
+
typeLabel: typeConfig.labelPlural,
|
|
292
|
+
warn: (message) => logger.warn(message),
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
if (article && built)
|
|
296
|
+
articles.push({ article, dir, folder });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Lists (published articles only, without index articles)
|
|
300
|
+
const withIndex = new Set(articles
|
|
301
|
+
.filter(({ article }) => article.slug === "index")
|
|
302
|
+
.map(({ article }) => article.type));
|
|
303
|
+
const listed = articles
|
|
304
|
+
.map(({ article }) => article)
|
|
305
|
+
.filter((article) => article.status === "published" && article.slug !== "index");
|
|
306
|
+
const lists = collectLists(listed, site, withIndex);
|
|
307
|
+
/** Render a page's template, then the embeds it shows (see EmbedResolver.renderPage) */
|
|
308
|
+
const renderPage = (template, data, url) => embeds.renderPage(templates.render(template, { ...data, embeds: EMBED_PAGE_PARTS }), url);
|
|
309
|
+
const firstPages = new Map();
|
|
310
|
+
for (const list of lists) {
|
|
311
|
+
const pages = paginate(list);
|
|
312
|
+
if (list.kind === "type")
|
|
313
|
+
firstPages.set(list.type, pages[0]);
|
|
314
|
+
if (list.pages) {
|
|
315
|
+
const listTemplate = templates.resolve(list.type, "list");
|
|
316
|
+
for (const page of pages)
|
|
317
|
+
await write(list.dir + pageFile(page.pagination.page.index), await renderPage(listTemplate, listPageData(site, page), page.pagination.page.url));
|
|
318
|
+
}
|
|
319
|
+
if (list.feed)
|
|
320
|
+
await write(`${list.dir}feed.xml`, await renderPage("layouts/rssfeed.njk",
|
|
321
|
+
// The feed has the newest articles that can be in feeds
|
|
322
|
+
listPageData(site, {
|
|
323
|
+
...pages[0],
|
|
324
|
+
articles: list.feedArticles.slice(0, PAGE_SIZE),
|
|
325
|
+
}), `${list.dir}feed.xml`));
|
|
326
|
+
}
|
|
327
|
+
// Article pages with their assets; index articles also get their type's list
|
|
328
|
+
for (const { article, dir, folder } of articles) {
|
|
329
|
+
await cp(dir, join(outputDir, folder), {
|
|
330
|
+
recursive: true,
|
|
331
|
+
filter: (path) => path !== join(dir, "article.md"),
|
|
332
|
+
});
|
|
333
|
+
const list = article.slug === "index" ? firstPages.get(article.type) : undefined;
|
|
334
|
+
await write(`${folder}index.html`, await renderPage(templates.resolve(article.type, article.template), articlePageData(site, article, list), article.url));
|
|
335
|
+
}
|
|
336
|
+
// Static files (stylesheet, fonts) at the website's root, beside the articles
|
|
337
|
+
const statics = await staticFiles([
|
|
338
|
+
join(themeDir, "static"),
|
|
339
|
+
join(siteDir, config.staticDir),
|
|
340
|
+
]);
|
|
341
|
+
for (const file of statics.keys())
|
|
342
|
+
if (await exists(join(outputDir, file)))
|
|
343
|
+
throw new Error(`${config.staticDir}/${file} has the same path as an article's file; rename one of them`);
|
|
344
|
+
for (const [file, source] of statics) {
|
|
345
|
+
await mkdir(dirname(join(outputDir, file)), { recursive: true });
|
|
346
|
+
await cp(source, join(outputDir, file));
|
|
347
|
+
}
|
|
348
|
+
// Publish into the website's root, without replacing anything already there
|
|
349
|
+
const built = await listFiles(outputDir);
|
|
350
|
+
if (publishDir) {
|
|
351
|
+
for (const file of built)
|
|
352
|
+
if (await exists(join(publishDir, file)))
|
|
353
|
+
throw new Error(`${file} is already in "publishDir" (${config.publishDir}); remove it there or rename the article`);
|
|
354
|
+
if (built.length)
|
|
355
|
+
await cp(outputDir, publishDir, { recursive: true });
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
outputDir,
|
|
359
|
+
publishDir,
|
|
360
|
+
articles: articles.map(({ article }) => article),
|
|
361
|
+
files: built,
|
|
362
|
+
};
|
|
363
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { EmbedPlugin } from "../../embeds/types/index.ts";
|
|
2
|
+
import type { AuthorConfig } from "../article/index.ts";
|
|
3
|
+
import { type MetadataDefinitions } from "../metadata/index.ts";
|
|
4
|
+
import { type MetadataGroupConfig } from "../metadataGroups/index.ts";
|
|
5
|
+
/** What is built for an article type */
|
|
6
|
+
export interface GenerateConfig {
|
|
7
|
+
/** Build the type's articles (when false, nothing else is built for it either) */
|
|
8
|
+
article: boolean;
|
|
9
|
+
/** Build the type's list pages, and include its articles in the all-articles list */
|
|
10
|
+
list: boolean;
|
|
11
|
+
/** Build the type's feed, and include its articles in the all-articles, tag and author feeds */
|
|
12
|
+
feed: boolean;
|
|
13
|
+
/** Include the type's articles in author lists */
|
|
14
|
+
author: boolean;
|
|
15
|
+
/** Include the type's articles in tag lists */
|
|
16
|
+
tag: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Settings of an article type */
|
|
19
|
+
export interface ArticleTypeConfig {
|
|
20
|
+
/** The type's URL path ("" for the site's root), e.g. "news" */
|
|
21
|
+
path: string;
|
|
22
|
+
/** Label for one article, e.g. "Article" */
|
|
23
|
+
labelSingle: string;
|
|
24
|
+
/** Label for several articles, e.g. "Articles" */
|
|
25
|
+
labelPlural: string;
|
|
26
|
+
/** What is built for the type */
|
|
27
|
+
generate: GenerateConfig;
|
|
28
|
+
/** The custom metadata fields the type uses: those listed, none for `false`, or all when undefined */
|
|
29
|
+
metadata?: string[] | false | undefined;
|
|
30
|
+
/** The author of the type's articles that don't name one, or `false` for none. Default: the site's `author` */
|
|
31
|
+
author?: AuthorConfig | false | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** The site's settings from the config file */
|
|
34
|
+
export interface EdahaConfig {
|
|
35
|
+
/** The name of the website */
|
|
36
|
+
name: string;
|
|
37
|
+
/** The description of the website */
|
|
38
|
+
description: string;
|
|
39
|
+
/** The URL path prefix of every article type ("" for the website's root) */
|
|
40
|
+
path: string;
|
|
41
|
+
/** The build folder, relative to the site folder and inside it (emptied on every build). Default: "build" */
|
|
42
|
+
outputDir: string;
|
|
43
|
+
/** The articles folder, relative to the site folder and inside it. Default: "articles" */
|
|
44
|
+
articlesDir: string;
|
|
45
|
+
/** The site's templates folder, over the theme's, relative to the site folder and inside it. Default: "templates" */
|
|
46
|
+
templatesDir: string;
|
|
47
|
+
/** The site's static files folder, over the theme's, relative to the site folder and inside it. Default: "static" */
|
|
48
|
+
staticDir: string;
|
|
49
|
+
/** Optional; where built files are copied to, relative to the site folder (e.g. another app's build folder) */
|
|
50
|
+
publishDir?: string | undefined;
|
|
51
|
+
/** Optional; the website's absolute URL for feeds, used when the `SITE_URL` environment variable isn't set */
|
|
52
|
+
siteUrl?: string | undefined;
|
|
53
|
+
/** Paths at the website's root that the site can't use, e.g. another app's routes. Default: none */
|
|
54
|
+
reservedPaths: string[];
|
|
55
|
+
/** Article type settings, by type */
|
|
56
|
+
types: Record<string, ArticleTypeConfig>;
|
|
57
|
+
/**
|
|
58
|
+
* Embed plugins, for `<!-- embed:<key> -->` blocks. The config file names their packages (loaded by loadSiteConfig);
|
|
59
|
+
* a JavaScript config file can also give the plugins themselves. Default: none
|
|
60
|
+
*/
|
|
61
|
+
plugins: EmbedPlugin[];
|
|
62
|
+
/** Custom metadata fields' JSON Schemas, by the key articles store their values under. Default: none */
|
|
63
|
+
metadata: MetadataDefinitions;
|
|
64
|
+
/** Groups of settings in the editor, besides the built-in ones, by key. Default: none */
|
|
65
|
+
metadataGroups: Record<string, MetadataGroupConfig>;
|
|
66
|
+
/** The author of articles that don't name one (unless their type has its own), or `false` for none. Default: none (the website's name is used) */
|
|
67
|
+
author?: AuthorConfig | false | undefined;
|
|
68
|
+
}
|
|
69
|
+
/** List folders that can't be used as article types */
|
|
70
|
+
export declare const RESERVED_TYPES: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Settings for an article type that isn't configured: everything generated, labelled from its name.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* defaultTypeConfig("video"); // { path: "video", labelSingle: "Video", labelPlural: "Videos", generate: { article: true, ... } }
|
|
76
|
+
*/
|
|
77
|
+
export declare const defaultTypeConfig: (type: string) => ArticleTypeConfig;
|
|
78
|
+
/**
|
|
79
|
+
* Read the optional list of reserved paths: URL path segments or file names, e.g. "app" or "jwks.json".
|
|
80
|
+
*/
|
|
81
|
+
/** The site's source folders' settings, with their defaults */
|
|
82
|
+
export declare const SOURCE_FOLDERS: {
|
|
83
|
+
readonly articlesDir: "articles";
|
|
84
|
+
readonly templatesDir: "templates";
|
|
85
|
+
readonly staticDir: "static";
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Validate the settings read from the site's config file (YAML, JSON or JavaScript) and fill in defaults. Errors start
|
|
89
|
+
* with the config file's name.
|
|
90
|
+
*
|
|
91
|
+
* @param source - the config file's name, for errors
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* parseConfig({ name: "News", description: "Updates" }, "edaha.config.json");
|
|
95
|
+
*/
|
|
96
|
+
export declare const parseConfig: (data: unknown, source?: string) => EdahaConfig;
|