@lvl99dotcom/edaha-editor 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/client/assets/index-KKuFTVH2.css +1 -0
- package/dist/client/assets/index-n5aM_lw1.js +1573 -0
- package/dist/client/index.html +21 -0
- package/dist/editor/index.d.ts +69 -0
- package/dist/editor/index.js +125 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/server/app/index.d.ts +98 -0
- package/dist/server/app/index.js +389 -0
- package/dist/server/articleIndex/index.d.ts +126 -0
- package/dist/server/articleIndex/index.js +352 -0
- package/dist/server/convert/index.d.ts +38 -0
- package/dist/server/convert/index.js +180 -0
- package/dist/server/files/index.d.ts +66 -0
- package/dist/server/files/index.js +256 -0
- package/dist/server/store/index.d.ts +287 -0
- package/dist/server/store/index.js +692 -0
- package/dist/server/types/index.d.ts +249 -0
- package/dist/server/types/index.js +15 -0
- package/package.json +59 -3
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { stringify } from "yaml";
|
|
2
|
+
import { splitArticle } from "@lvl99dotcom/edaha.md/generator/article";
|
|
3
|
+
import { replaceOutsideCode } from "@lvl99dotcom/edaha.md/generator/format";
|
|
4
|
+
import { CORE_FIELDS } from "@lvl99dotcom/edaha.md/generator/metadata";
|
|
5
|
+
import { DEFAULT_FILE_ORDERS, } from "../types/index.js";
|
|
6
|
+
/** The most files a page of query results has */
|
|
7
|
+
export const MAX_FILES_PER_PAGE = 50;
|
|
8
|
+
/** File extensions of each kind (anything else is "other") */
|
|
9
|
+
const KIND_EXTENSIONS = {
|
|
10
|
+
image: ["png", "jpg", "jpeg", "gif", "webp", "svg", "avif", "ico", "bmp"],
|
|
11
|
+
document: [
|
|
12
|
+
"pdf",
|
|
13
|
+
"doc",
|
|
14
|
+
"docx",
|
|
15
|
+
"odt",
|
|
16
|
+
"rtf",
|
|
17
|
+
"txt",
|
|
18
|
+
"md",
|
|
19
|
+
"csv",
|
|
20
|
+
"xls",
|
|
21
|
+
"xlsx",
|
|
22
|
+
"ods",
|
|
23
|
+
"ppt",
|
|
24
|
+
"pptx",
|
|
25
|
+
"odp",
|
|
26
|
+
"epub",
|
|
27
|
+
],
|
|
28
|
+
archive: ["zip", "tar", "gz", "tgz", "bz2", "xz", "7z", "rar"],
|
|
29
|
+
video: ["mp4", "webm", "mov", "m4v", "ogv", "avi", "mkv"],
|
|
30
|
+
audio: ["mp3", "wav", "ogg", "oga", "m4a", "flac", "aac", "opus"],
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The kind of file a name is, by its extension.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* fileKind("photo.JPG"); // "image"
|
|
37
|
+
* fileKind("notes"); // "other"
|
|
38
|
+
*/
|
|
39
|
+
export const fileKind = (name) => {
|
|
40
|
+
const extension = /\.([^./]+)$/.exec(name)?.[1]?.toLowerCase() ?? "";
|
|
41
|
+
return (Object.entries(KIND_EXTENSIONS).find(([, extensions]) => extensions.includes(extension))?.[0] ?? "other");
|
|
42
|
+
};
|
|
43
|
+
/** A file's location, e.g. "news/welcome" */
|
|
44
|
+
const location = (file) => `${file.type}/${file.slug}`;
|
|
45
|
+
/** The value each sort compares */
|
|
46
|
+
const SORT_VALUES = {
|
|
47
|
+
name: (file) => file.name.toLocaleLowerCase(),
|
|
48
|
+
kind: (file) => file.kind,
|
|
49
|
+
size: (file) => file.size,
|
|
50
|
+
location,
|
|
51
|
+
};
|
|
52
|
+
/** Compare two sort values: numbers by size, text alphabetically */
|
|
53
|
+
const compare = (a, b) => typeof a === "number" && typeof b === "number"
|
|
54
|
+
? a - b
|
|
55
|
+
: String(a).localeCompare(String(b));
|
|
56
|
+
/**
|
|
57
|
+
* Find files: those whose name contains the search text (ignoring case) and that are of the kind and in an article of
|
|
58
|
+
* the type given, sorted by name, kind, size or location, ascending or descending (by default by location then name,
|
|
59
|
+
* A to Z), one page at a time.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* queryFiles(files, { search: "photo", kind: "image", sort: "size", order: "desc" });
|
|
63
|
+
*/
|
|
64
|
+
export const queryFiles = (files, query = {}) => {
|
|
65
|
+
const search = query.search?.trim().toLocaleLowerCase() ?? "";
|
|
66
|
+
const sort = query.sort ?? "location";
|
|
67
|
+
const direction = (query.order ?? DEFAULT_FILE_ORDERS[sort]) === "asc" ? 1 : -1;
|
|
68
|
+
const value = SORT_VALUES[sort];
|
|
69
|
+
const found = files
|
|
70
|
+
.filter((file) => (!search || file.name.toLocaleLowerCase().includes(search)) &&
|
|
71
|
+
(!query.kind || file.kind === query.kind) &&
|
|
72
|
+
(!query.type || file.type === query.type))
|
|
73
|
+
.sort((a, b) => direction * compare(value(a), value(b)) ||
|
|
74
|
+
location(a).localeCompare(location(b)) ||
|
|
75
|
+
a.name.localeCompare(b.name));
|
|
76
|
+
const perPage = Math.min(Math.max(Math.floor(query.perPage ?? MAX_FILES_PER_PAGE), 1), MAX_FILES_PER_PAGE);
|
|
77
|
+
const pages = Math.max(Math.ceil(found.length / perPage), 1);
|
|
78
|
+
const page = Math.min(Math.max(Math.floor(query.page ?? 1), 1), pages);
|
|
79
|
+
return {
|
|
80
|
+
files: found.slice((page - 1) * perPage, page * perPage),
|
|
81
|
+
total: found.length,
|
|
82
|
+
page,
|
|
83
|
+
pages,
|
|
84
|
+
perPage,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The file kinds and article types files are in, for the file browser's filters.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* fileFilters(files); // { kinds: ["document", "image"], types: ["news"] }
|
|
92
|
+
*/
|
|
93
|
+
export const fileFilters = (files) => ({
|
|
94
|
+
kinds: [...new Set(files.map((file) => file.kind))].sort(),
|
|
95
|
+
types: [...new Set(files.map((file) => file.type))].sort(),
|
|
96
|
+
});
|
|
97
|
+
/** Escape text for use in a regular expression */
|
|
98
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
99
|
+
/**
|
|
100
|
+
* The ways an article can refer to a file: its name (or `./` and its name) in the file's own article, and its path on
|
|
101
|
+
* the website (e.g. "/news/welcome/photo.png") or its full address anywhere.
|
|
102
|
+
*
|
|
103
|
+
* @param url - the file's path on the website
|
|
104
|
+
* @param siteUrl - the website's address (without a trailing slash), if it has one
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* fileReferences("photo.png", "/news/welcome/photo.png", "https://example.com", true);
|
|
108
|
+
* // ["photo.png", "./photo.png", "/news/welcome/photo.png", "https://example.com/news/welcome/photo.png"]
|
|
109
|
+
*/
|
|
110
|
+
export const fileReferences = (name, url, siteUrl, ownArticle) => [
|
|
111
|
+
...(ownArticle ? [name, `./${name}`] : []),
|
|
112
|
+
url,
|
|
113
|
+
...(siteUrl ? [siteUrl + url] : []),
|
|
114
|
+
];
|
|
115
|
+
/** A reference in Markdown or HTML: an image or link (with its text), or an HTML image or link */
|
|
116
|
+
const REFERENCE = /(?<image>!?)\[(?<text>[^\]]*)\]\(\s*<?(?<dest>[^)\s>]+)>?(?<title>\s+"[^"]*")?\s*\)|<img\b[^>]*?\ssrc=(?<imgQuote>["'])(?<imgSrc>[^"']+)\k<imgQuote>[^>]*>|<a\b[^>]*?\shref=(?<linkQuote>["'])(?<linkHref>[^"']+)\k<linkQuote>[^>]*>(?<linkText>[\s\S]*?)<\/a>/;
|
|
117
|
+
/** Swap a reference's file name for another, keeping its folder or address */
|
|
118
|
+
const renamed = (reference, name) => reference.replace(/[^/]+$/, name);
|
|
119
|
+
/**
|
|
120
|
+
* Change references to a file in Markdown (outside code): point them at a new file name, or remove them (images are
|
|
121
|
+
* removed, links keep their text). Returns the Markdown and how many references were changed.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* changeBodyReferences(" [A](a.png)", ["a.png"], { remove: true }); // { markdown: " A", count: 2 }
|
|
125
|
+
*/
|
|
126
|
+
export const changeBodyReferences = (markdown, references, change) => {
|
|
127
|
+
let count = 0;
|
|
128
|
+
const result = replaceOutsideCode(markdown, REFERENCE, (match) => {
|
|
129
|
+
const groups = match.groups;
|
|
130
|
+
// One of the three kinds of reference matched
|
|
131
|
+
const dest = (groups.dest ?? groups.imgSrc ?? groups.linkHref);
|
|
132
|
+
if (!references.includes(dest))
|
|
133
|
+
return match[0];
|
|
134
|
+
count++;
|
|
135
|
+
if ("rename" in change)
|
|
136
|
+
return match[0].replace(dest, renamed(dest, change.rename));
|
|
137
|
+
// Images go; links keep their text
|
|
138
|
+
if (groups.imgSrc || groups.image)
|
|
139
|
+
return "";
|
|
140
|
+
return (groups.text ?? groups.linkText);
|
|
141
|
+
});
|
|
142
|
+
return { markdown: result, count };
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Change references to a file in a custom setting's value, through lists and maps: text that is the file points at the
|
|
146
|
+
* new name, or is removed (from its list or map, or the setting itself).
|
|
147
|
+
*/
|
|
148
|
+
const changeValue = (value, references, change) => {
|
|
149
|
+
if (typeof value === "string" && references.includes(value))
|
|
150
|
+
return "rename" in change
|
|
151
|
+
? { value: renamed(value, change.rename), removed: false, count: 1 }
|
|
152
|
+
: { value: undefined, removed: true, count: 1 };
|
|
153
|
+
if (!value || typeof value !== "object")
|
|
154
|
+
return { value, removed: false, count: 0 };
|
|
155
|
+
let count = 0;
|
|
156
|
+
const entries = [];
|
|
157
|
+
for (const [key, item] of Object.entries(value)) {
|
|
158
|
+
const changed = changeValue(item, references, change);
|
|
159
|
+
count += changed.count;
|
|
160
|
+
if (!changed.removed)
|
|
161
|
+
entries.push([key, changed.value]);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
value: Array.isArray(value)
|
|
165
|
+
? entries.map(([, item]) => item)
|
|
166
|
+
: Object.fromEntries(entries),
|
|
167
|
+
removed: false,
|
|
168
|
+
count,
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Change references to a file in an article's settings: its thumbnail, its attachments and their thumbnails, and custom
|
|
173
|
+
* metadata (any value that is the file). Removing clears a thumbnail, and removes an attachment or a custom value. Returns the settings (the same object if nothing changed) and how many were changed.
|
|
174
|
+
*/
|
|
175
|
+
const changeHeaderReferences = (header, references, change) => {
|
|
176
|
+
let count = 0;
|
|
177
|
+
const next = { ...header };
|
|
178
|
+
const { thumbnail, attachments } = header;
|
|
179
|
+
if (typeof thumbnail === "string" && references.includes(thumbnail)) {
|
|
180
|
+
count++;
|
|
181
|
+
if ("rename" in change)
|
|
182
|
+
next.thumbnail = renamed(thumbnail, change.rename);
|
|
183
|
+
else
|
|
184
|
+
delete next.thumbnail;
|
|
185
|
+
}
|
|
186
|
+
if (Array.isArray(attachments)) {
|
|
187
|
+
const kept = [];
|
|
188
|
+
for (const attachment of attachments) {
|
|
189
|
+
const fields = typeof attachment === "string"
|
|
190
|
+
? { url: attachment }
|
|
191
|
+
: { ...attachment };
|
|
192
|
+
// The attachment itself, or only its thumbnail, may be the file
|
|
193
|
+
if (typeof fields.url === "string" && references.includes(fields.url)) {
|
|
194
|
+
count++;
|
|
195
|
+
if ("remove" in change)
|
|
196
|
+
continue;
|
|
197
|
+
fields.url = renamed(fields.url, change.rename);
|
|
198
|
+
}
|
|
199
|
+
if (typeof fields.thumbnail === "string" &&
|
|
200
|
+
references.includes(fields.thumbnail)) {
|
|
201
|
+
count++;
|
|
202
|
+
if ("rename" in change)
|
|
203
|
+
fields.thumbnail = renamed(fields.thumbnail, change.rename);
|
|
204
|
+
else
|
|
205
|
+
delete fields.thumbnail;
|
|
206
|
+
}
|
|
207
|
+
kept.push(typeof attachment === "string" ? fields.url : fields);
|
|
208
|
+
}
|
|
209
|
+
if (kept.length)
|
|
210
|
+
next.attachments = kept;
|
|
211
|
+
else
|
|
212
|
+
delete next.attachments;
|
|
213
|
+
}
|
|
214
|
+
// Custom metadata and other settings: any value that is the file
|
|
215
|
+
const removed = new Set();
|
|
216
|
+
for (const [key, value] of Object.entries(header)) {
|
|
217
|
+
if (CORE_FIELDS.includes(key))
|
|
218
|
+
continue;
|
|
219
|
+
const changed = changeValue(value, references, change);
|
|
220
|
+
count += changed.count;
|
|
221
|
+
if (changed.removed)
|
|
222
|
+
removed.add(key);
|
|
223
|
+
else if (changed.count)
|
|
224
|
+
next[key] = changed.value;
|
|
225
|
+
}
|
|
226
|
+
if (!count)
|
|
227
|
+
return { header, count };
|
|
228
|
+
return {
|
|
229
|
+
header: Object.fromEntries(Object.entries(next).filter(([key]) => !removed.has(key))),
|
|
230
|
+
count,
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Change references to a file in an article's source (its settings header and its body), keeping the header's format.
|
|
235
|
+
* Returns the new source, or undefined if the article doesn't refer to the file.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* changeArticleReferences(source, ["photo.png"], { rename: "photo.jpg" });
|
|
239
|
+
*/
|
|
240
|
+
export const changeArticleReferences = (source, references, change) => {
|
|
241
|
+
// Most articles don't mention the file at all
|
|
242
|
+
const names = [
|
|
243
|
+
...new Set(references.map((reference) => reference.replace(/^.*\//, ""))),
|
|
244
|
+
];
|
|
245
|
+
if (!new RegExp(names.map(escapeRegExp).join("|")).test(source))
|
|
246
|
+
return undefined;
|
|
247
|
+
const { header, format, content } = splitArticle(source);
|
|
248
|
+
const settings = changeHeaderReferences(header, references, change);
|
|
249
|
+
const body = changeBodyReferences(content, references, change);
|
|
250
|
+
if (!settings.count && !body.count)
|
|
251
|
+
return undefined;
|
|
252
|
+
const headerSource = settings.count
|
|
253
|
+
? `<!--${format}\n${format === "json" ? `${JSON.stringify(settings.header, null, 2)}\n` : stringify(settings.header)}-->`
|
|
254
|
+
: source.slice(0, source.length - content.length);
|
|
255
|
+
return headerSource + body.markdown;
|
|
256
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { type EmbedOptionValues, type EmbedPlugin, type EmbedResolver } from "@lvl99dotcom/edaha.md/embeds";
|
|
2
|
+
import { type HeaderFormat } from "@lvl99dotcom/edaha.md/generator/article";
|
|
3
|
+
import { type SiteConfig } from "@lvl99dotcom/edaha.md/generator/configFile";
|
|
4
|
+
import { type ArticleIndexOptions } from "../articleIndex/index.ts";
|
|
5
|
+
import type { ArticleFilters, ArticleLocation, ArticlePage, ArticleQuery, FileChange, FileFilters, FilePage, FileQuery, MetadataInfo, MetadataProblem, SiteInfo, ArticleTypeLabels, RecentArticles, EditorArticle, EditorArticleData, UploadResult } from "../types/index.ts";
|
|
6
|
+
/** An editor request that can't be done, with the HTTP status to answer with */
|
|
7
|
+
export declare class EditorError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
/** Problems with the article's custom metadata, when saving it was refused because of them */
|
|
10
|
+
readonly problems?: MetadataProblem[] | undefined;
|
|
11
|
+
constructor(status: number, message: string, problems?: MetadataProblem[]);
|
|
12
|
+
}
|
|
13
|
+
/** Options for an `ArticleStore` */
|
|
14
|
+
export interface ArticleStoreOptions extends ArticleIndexOptions {
|
|
15
|
+
/** Whether the article index watches the articles folder for changes made outside the editor (default: true) */
|
|
16
|
+
watch?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** How many previews the editor remembers (the newest) */
|
|
19
|
+
export declare const MAX_PREVIEWS = 20;
|
|
20
|
+
/** How many embed frames the editor remembers (the newest) */
|
|
21
|
+
export declare const MAX_EMBED_FRAMES = 200;
|
|
22
|
+
/** An embed block's content, for its frame in the editor's body */
|
|
23
|
+
export interface EmbedFrameData {
|
|
24
|
+
/** The embed plugin's key */
|
|
25
|
+
key: string;
|
|
26
|
+
/** The block's content */
|
|
27
|
+
content: string;
|
|
28
|
+
/** The block's options, as set in the embed dialog */
|
|
29
|
+
options: EmbedOptionValues;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check an article type and slug are valid folder names. Throws a 400 EditorError if not.
|
|
33
|
+
*/
|
|
34
|
+
export declare const checkLocation: (type: string, slug: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* The URL relative URLs in an article's body point at in the editor: its saved folder's file URL, or "" for an article
|
|
37
|
+
* that isn't saved yet (and has no files).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* bodyBaseUrl({ type: "news", slug: "hello" }); // "/files/news/hello/"
|
|
41
|
+
* bodyBaseUrl(undefined); // ""
|
|
42
|
+
*/
|
|
43
|
+
export declare const bodyBaseUrl: (location: {
|
|
44
|
+
type: string;
|
|
45
|
+
slug: string;
|
|
46
|
+
} | undefined) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Make an uploaded file name safe: a slug of its base name plus its lowercase extension.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* safeFileName("My Photo (1).JPG"); // "my-photo-1.jpg"
|
|
52
|
+
*/
|
|
53
|
+
export declare const safeFileName: (name: string) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Write an article's markdown source: the config header (YAML by default, or JSON), the title as an H1 and the body.
|
|
56
|
+
* The type (always the article's folder) and defaults (empty lists) are left out to keep the header short.
|
|
57
|
+
*
|
|
58
|
+
* @param format - the config header's format
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* serializeArticle({ type: "article", slug: "hi", status: "published", date, title: "Hi", tags: [], attachments: [] }, "Body");
|
|
62
|
+
* serializeArticle(data, "Body", "json"); // '<!--json\n{\n "status": "published", ...'
|
|
63
|
+
*/
|
|
64
|
+
export declare const serializeArticle: (data: EditorArticleData, body: string, format?: HeaderFormat) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Reads and writes articles in the site's articles folder (`articlesDir`) for the editor, and renders previews with the site's
|
|
67
|
+
* templates over the default theme's. Articles are listed and searched from an in-memory index (see `ArticleIndex`),
|
|
68
|
+
* read on first use and kept up to date as the editor saves and deletes articles, and (unless `watch` is false) as their
|
|
69
|
+
* files change outside the editor. Call `close` to stop watching.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const store = new ArticleStore(await loadSiteConfig({ siteDir: "my-site" }));
|
|
73
|
+
* await store.query({ search: "hello" });
|
|
74
|
+
* store.close();
|
|
75
|
+
*/
|
|
76
|
+
export declare class ArticleStore {
|
|
77
|
+
private readonly articlesDir;
|
|
78
|
+
private readonly configFile;
|
|
79
|
+
/** The site's templates folder, relative to the site folder */
|
|
80
|
+
private readonly templatesDir;
|
|
81
|
+
/** The site's static files folder, relative to the site folder */
|
|
82
|
+
private readonly staticDir;
|
|
83
|
+
/** Previews' unsaved data by ID, the newest last (see `rememberPreview`) */
|
|
84
|
+
private readonly previews;
|
|
85
|
+
/** Embed blocks shown in the editor's body by ID, the newest last (see `rememberEmbedFrame`) */
|
|
86
|
+
private readonly embedFrames;
|
|
87
|
+
private readonly siteDir;
|
|
88
|
+
private readonly themeDir;
|
|
89
|
+
/** What custom metadata is checked with, once read from the config file */
|
|
90
|
+
private metadataLoad?;
|
|
91
|
+
/** When the config file had last changed when its custom metadata was read */
|
|
92
|
+
private metadataChanged?;
|
|
93
|
+
/** The article index, once its first load has started */
|
|
94
|
+
private indexLoad?;
|
|
95
|
+
private readonly indexOptions;
|
|
96
|
+
/**
|
|
97
|
+
* @param site - the site's config file, folder (which holds the articles, templates and static files folders) and
|
|
98
|
+
* settings
|
|
99
|
+
* @param themeDir - the default theme folder that the site's templates and static files override
|
|
100
|
+
* @param options - how the article index watches for changes
|
|
101
|
+
*/
|
|
102
|
+
constructor(site: SiteConfig, themeDir?: string, options?: ArticleStoreOptions);
|
|
103
|
+
/** The site's templates over the theme's */
|
|
104
|
+
private loadTemplates;
|
|
105
|
+
/**
|
|
106
|
+
* Read the config file again (loading its embed plugin packages), so changes to it show without restarting the
|
|
107
|
+
* editor
|
|
108
|
+
*/
|
|
109
|
+
private config;
|
|
110
|
+
/**
|
|
111
|
+
* The template names an article of a type can use (see Templates.names).
|
|
112
|
+
*/
|
|
113
|
+
templates(type: string): string[];
|
|
114
|
+
/**
|
|
115
|
+
* The config file's embed plugins (read again each time, so changes show without restarting the editor).
|
|
116
|
+
*/
|
|
117
|
+
plugins(): Promise<EmbedPlugin[]>;
|
|
118
|
+
/**
|
|
119
|
+
* The website's name, the author of articles that don't name one (the config file's `author`, the website without
|
|
120
|
+
* one, or none for `false`), and the types with their own default author.
|
|
121
|
+
*/
|
|
122
|
+
site(): Promise<SiteInfo>;
|
|
123
|
+
/**
|
|
124
|
+
* The article types from the config file, with their labels.
|
|
125
|
+
*/
|
|
126
|
+
types(): Promise<Record<string, ArticleTypeLabels>>;
|
|
127
|
+
/** An article's folder */
|
|
128
|
+
private dir;
|
|
129
|
+
/** Read an article's source, or throw a 404 EditorError */
|
|
130
|
+
private source;
|
|
131
|
+
/**
|
|
132
|
+
* What articles' custom metadata is checked with, from the config file: a check giving an article's problems from its
|
|
133
|
+
* type and settings, and the context `loadArticle` reads a type's metadata with. It is read again when the config file
|
|
134
|
+
* changes, which checks every article again.
|
|
135
|
+
*/
|
|
136
|
+
private metadata;
|
|
137
|
+
/**
|
|
138
|
+
* Read the config file's custom metadata and every article now, rather than on first use, so the editor starts with
|
|
139
|
+
* every article checked.
|
|
140
|
+
*/
|
|
141
|
+
load(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* The custom metadata fields, which fields each configured type uses, and the groups the article form shows settings
|
|
144
|
+
* in.
|
|
145
|
+
*/
|
|
146
|
+
metadataInfo(): Promise<MetadataInfo>;
|
|
147
|
+
/** The article index, read on first use (and then watched, unless turned off) */
|
|
148
|
+
private index;
|
|
149
|
+
/**
|
|
150
|
+
* Find articles by title, type, author, tag and status, sorted by title or date, a page at a time (see
|
|
151
|
+
* `queryArticles`).
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* await store.query({ search: "hello", sort: "title", page: 2 });
|
|
155
|
+
*/
|
|
156
|
+
query(query: ArticleQuery): Promise<ArticlePage>;
|
|
157
|
+
/**
|
|
158
|
+
* Each type's most recently changed articles, for the editor's nav (see `recentArticles`).
|
|
159
|
+
*/
|
|
160
|
+
recent(count?: number): Promise<RecentArticles[]>;
|
|
161
|
+
/**
|
|
162
|
+
* The types, authors and tags articles use, for the article browser's filters.
|
|
163
|
+
*/
|
|
164
|
+
filters(): Promise<ArticleFilters>;
|
|
165
|
+
/**
|
|
166
|
+
* Where articles are on the website, from the config file: a function giving an article's path (e.g. "/news/hello/";
|
|
167
|
+
* an index article is at its type's path), and the website's address without a trailing slash, if it has one.
|
|
168
|
+
*/
|
|
169
|
+
private articleUrls;
|
|
170
|
+
/**
|
|
171
|
+
* Find files in the articles' folders by name, kind and article type, sorted by name, kind, size or location, a page
|
|
172
|
+
* at a time, with their paths on the website.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* await store.queryFiles({ kind: "image", sort: "size" });
|
|
176
|
+
*/
|
|
177
|
+
queryFiles(query: FileQuery): Promise<FilePage>;
|
|
178
|
+
/** The kinds of files and the article types they are in, for the file browser's filters */
|
|
179
|
+
fileFilters(): Promise<FileFilters>;
|
|
180
|
+
/** A file's path in an article's folder. Throws a 404 EditorError if there is no such file. */
|
|
181
|
+
private filePath;
|
|
182
|
+
/**
|
|
183
|
+
* Change references to a file in every article (see `changeArticleReferences`), or only find them with `dryRun`.
|
|
184
|
+
* Returns the articles that refer to it.
|
|
185
|
+
*/
|
|
186
|
+
private changeReferences;
|
|
187
|
+
/**
|
|
188
|
+
* The articles that refer to a file, e.g. to say which will change before replacing or deleting it.
|
|
189
|
+
*/
|
|
190
|
+
fileReferences(type: string, slug: string, name: string): Promise<ArticleLocation[]>;
|
|
191
|
+
/**
|
|
192
|
+
* Replace a file in an article's folder with an uploaded one. With the same (safe) name, the file is overwritten;
|
|
193
|
+
* with another, the new file is saved under its own name, references to the old one switch to it in every article,
|
|
194
|
+
* and the old file is removed. Throws a 409 EditorError if another file already has the new name.
|
|
195
|
+
*/
|
|
196
|
+
replaceFile(type: string, slug: string, name: string, fileName: string, contents: Uint8Array): Promise<FileChange>;
|
|
197
|
+
/**
|
|
198
|
+
* Delete a file from an article's folder, removing references to it in every article (images are removed, links keep
|
|
199
|
+
* their text, a thumbnail is cleared and attachments are removed).
|
|
200
|
+
*/
|
|
201
|
+
deleteFile(type: string, slug: string, name: string): Promise<FileChange>;
|
|
202
|
+
/** Stop watching the articles folder for changes */
|
|
203
|
+
close(): void;
|
|
204
|
+
/**
|
|
205
|
+
* Load an article for editing. Throws a 404 EditorError if it doesn't exist, or 422 if it can't be read.
|
|
206
|
+
*/
|
|
207
|
+
read(type: string, slug: string): Promise<EditorArticle>;
|
|
208
|
+
/**
|
|
209
|
+
* Save an article. When its type or slug changed, its folder (with all its files) moves to the new location.
|
|
210
|
+
* Pass no `from` for a new article. Returns where the article now is.
|
|
211
|
+
*/
|
|
212
|
+
save(data: EditorArticleData, from?: {
|
|
213
|
+
type: string;
|
|
214
|
+
slug: string;
|
|
215
|
+
}): Promise<{
|
|
216
|
+
type: string;
|
|
217
|
+
slug: string;
|
|
218
|
+
}>;
|
|
219
|
+
/**
|
|
220
|
+
* Render an article from unsaved editor data as the website would, with its type's "single" template, for the
|
|
221
|
+
* editor's preview. Drafts are shown as if published. Its files come from its saved folder (`location`), if it has one,
|
|
222
|
+
* and are shown from the editor's file URLs. Throws a 400 EditorError if it can't be rendered (e.g. a file isn't in
|
|
223
|
+
* the article's folder).
|
|
224
|
+
*
|
|
225
|
+
* @param embeds - renders embed blocks
|
|
226
|
+
*/
|
|
227
|
+
preview(data: EditorArticleData, location: {
|
|
228
|
+
type: string;
|
|
229
|
+
slug: string;
|
|
230
|
+
} | undefined, embeds: EmbedResolver): Promise<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Delete an article and all its files.
|
|
233
|
+
*/
|
|
234
|
+
remove(type: string, slug: string): Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Save an uploaded file into an article's folder (replacing a file with the same name).
|
|
237
|
+
*/
|
|
238
|
+
upload(type: string, slug: string, fileName: string, contents: Uint8Array): Promise<UploadResult>;
|
|
239
|
+
/**
|
|
240
|
+
* Remember an article's unsaved data for its preview page, under a new ID. Only the newest `MAX_PREVIEWS` are kept,
|
|
241
|
+
* in memory: they're gone when the editor stops. Returns the ID.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* const id = store.rememberPreview(data, { type: "news", slug: "hello" }); // the editor shows it at /preview/<id>/
|
|
245
|
+
*/
|
|
246
|
+
rememberPreview(data: EditorArticleData, location: {
|
|
247
|
+
type: string;
|
|
248
|
+
slug: string;
|
|
249
|
+
} | undefined): string;
|
|
250
|
+
/**
|
|
251
|
+
* Remember an embed block for its frame in the editor's body, under an ID made from it (so the same block keeps its
|
|
252
|
+
* frame's URL). Only the newest `MAX_EMBED_FRAMES` are kept.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* const id = store.rememberEmbedFrame({ key: "youtube", content: "https://youtu.be/aju_UB5VIf8", options: {} }); // shown at /embed-frame/<id>/
|
|
256
|
+
*/
|
|
257
|
+
rememberEmbedFrame(frame: EmbedFrameData): string;
|
|
258
|
+
/**
|
|
259
|
+
* A remembered embed block (see `rememberEmbedFrame`). Throws a 404 EditorError if there is none with that ID (e.g.
|
|
260
|
+
* after the editor restarted).
|
|
261
|
+
*/
|
|
262
|
+
embedFrame(id: string): EmbedFrameData;
|
|
263
|
+
/**
|
|
264
|
+
* Render a remembered preview as the website would (see `preview`), so changes to templates show when it reloads.
|
|
265
|
+
* Throws a 404 EditorError if there is no preview with that ID (e.g. after the editor restarted).
|
|
266
|
+
*
|
|
267
|
+
* @param embeds - renders embed blocks
|
|
268
|
+
*/
|
|
269
|
+
renderPreview(id: string, embeds: EmbedResolver): Promise<string>;
|
|
270
|
+
/**
|
|
271
|
+
* Read a file at its path on the website, for previews and the article body: one of the static files published at
|
|
272
|
+
* the website's root (the site's `static/`, then the theme's), e.g. `site.css`, or else a file in an article's
|
|
273
|
+
* folder, e.g. `news/welcome/photo.png`. Throws a 404 EditorError if there is no such file, or the path leaves the
|
|
274
|
+
* folder or names a hidden file.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* await store.staticFile("fonts/my-font.woff2");
|
|
278
|
+
* await store.staticFile("news/welcome/photo.png");
|
|
279
|
+
*/
|
|
280
|
+
staticFile(path: string): Promise<Uint8Array>;
|
|
281
|
+
/** The static folders (stylesheet, fonts) published at the website's root: the site's, then the theme's */
|
|
282
|
+
get staticDirs(): string[];
|
|
283
|
+
/**
|
|
284
|
+
* Read a file from an article's folder. Throws a 404 EditorError if there is no such file.
|
|
285
|
+
*/
|
|
286
|
+
file(type: string, slug: string, name: string): Promise<Uint8Array>;
|
|
287
|
+
}
|