@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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Matt Scheurich]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lvl99dotcom/edaha.md
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
edaha.md's static website generator: the `edaha` command, the build, embeds and the default theme. It builds pages, paginated lists, tag and author pages and RSS feeds from Markdown articles with Nunjucks templates.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm add @lvl99dotcom/edaha.md --save-dev
|
|
7
|
+
npx edaha build --dir my-site
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Add [`@lvl99dotcom/edaha-editor`](https://www.npmjs.com/package/@lvl99dotcom/edaha-editor) to write articles in a local WYSIWYG editor with `edaha editor`.
|
|
11
|
+
|
|
12
|
+
See the [edaha.md README](https://github.com/lvl99/edaha.md#readme) and [docs](https://lvl99.github.io/edaha.md/).
|
|
13
|
+
|
|
14
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `edaha` command: runs the CLI with this process's arguments and surroundings (see ./index.ts)
|
|
3
|
+
import { runCli } from "./index.js";
|
|
4
|
+
process.exitCode = await runCli(process.argv.slice(2), {
|
|
5
|
+
cwd: process.cwd(),
|
|
6
|
+
env: process.env,
|
|
7
|
+
log: (message) => console.log(message),
|
|
8
|
+
error: (message) => console.error(message),
|
|
9
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { BuildOptions, BuildResult } from "../generator/build/index.ts";
|
|
2
|
+
/** The package with the article editor, which `edaha editor` loads when it is installed */
|
|
3
|
+
export declare const EDITOR_PACKAGE = "@lvl99dotcom/edaha-editor";
|
|
4
|
+
/** The editor's default port */
|
|
5
|
+
export declare const EDITOR_PORT = 5180;
|
|
6
|
+
/** What `edaha editor` passes to the editor package's `startEditor` */
|
|
7
|
+
export interface EditorOptions {
|
|
8
|
+
/** The folder to look for a config file in */
|
|
9
|
+
siteDir: string;
|
|
10
|
+
/** The config file, if one was named */
|
|
11
|
+
configFile?: string | undefined;
|
|
12
|
+
/** The port to listen on */
|
|
13
|
+
port: number;
|
|
14
|
+
}
|
|
15
|
+
/** A running editor, as the editor package's `startEditor` gives it */
|
|
16
|
+
export interface RunningEditor {
|
|
17
|
+
/** The editor's address, e.g. "http://127.0.0.1:5180" */
|
|
18
|
+
url: string;
|
|
19
|
+
/** Stop the editor */
|
|
20
|
+
close: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/** Starts the article editor */
|
|
23
|
+
export type StartEditor = (options: EditorOptions) => Promise<RunningEditor>;
|
|
24
|
+
/** How to use the `edaha` command */
|
|
25
|
+
export declare const USAGE = "Usage: edaha <command> [options]\n\nCommands:\n build Build the site into the config file's outputDir (and copy it into publishDir, if set)\n editor Run the local article editor (only reachable from this computer)\n\nOptions:\n -c, --config <file> The config file (default: the first edahaconfig file found in --dir, then in the nearest\n package.json's folder). The site folder is the config file's folder.\n --dir <folder> The folder to look for a config file in (default: the current folder)\n --site-url <url> build: the website's absolute URL for feeds (default: SITE_URL, then the config's siteUrl)\n --port <number> editor: the port to listen on (default: 5180)\n -h, --help Show this help\n -v, --version Show edaha.md's version\n";
|
|
26
|
+
/** What the command line needs from its surroundings, so it can be tested */
|
|
27
|
+
export interface CliContext {
|
|
28
|
+
/** The folder the command runs in */
|
|
29
|
+
cwd: string;
|
|
30
|
+
/** Environment variables */
|
|
31
|
+
env: Record<string, string | undefined>;
|
|
32
|
+
/** Where messages go */
|
|
33
|
+
log: (message: string) => void;
|
|
34
|
+
/** Where errors and warnings go */
|
|
35
|
+
error: (message: string) => void;
|
|
36
|
+
/** Builds the site (default: buildSite) */
|
|
37
|
+
build?: (options: BuildOptions) => Promise<BuildResult>;
|
|
38
|
+
/** Starts the editor (default: the editor package's startEditor, see loadEditor) */
|
|
39
|
+
editor?: StartEditor;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Load `startEditor` from the editor package. Throws with how to install it if it isn't installed.
|
|
43
|
+
*
|
|
44
|
+
* @param importPackage - imports a package by name (replaceable for tests)
|
|
45
|
+
* @example
|
|
46
|
+
* const startEditor = await loadEditor();
|
|
47
|
+
* await startEditor({ siteDir: "my-site", port: EDITOR_PORT });
|
|
48
|
+
*/
|
|
49
|
+
export declare const loadEditor: (importPackage?: (name: string) => Promise<unknown>) => Promise<StartEditor>;
|
|
50
|
+
/**
|
|
51
|
+
* edaha.md's version, from its package.json.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* version(); // "0.2.0"
|
|
55
|
+
*/
|
|
56
|
+
export declare const version: () => string;
|
|
57
|
+
/**
|
|
58
|
+
* Read a port number from the command line.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* parsePort("5180"); // 5180
|
|
62
|
+
*/
|
|
63
|
+
export declare const parsePort: (value: string) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Run the `edaha` command with its arguments (without `node` and the script). Returns the exit code; for `editor`, it
|
|
66
|
+
* returns once the editor is running.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* await runCli(["build", "--dir", "my-site"], { cwd: process.cwd(), env: process.env, log: console.log, error: console.error });
|
|
70
|
+
*/
|
|
71
|
+
export declare const runCli: (args: string[], context: CliContext) => Promise<number>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { resolve } from "node:path";
|
|
11
|
+
import { parseArgs } from "node:util";
|
|
12
|
+
import { buildSite } from "../generator/build/index.js";
|
|
13
|
+
/** The package with the article editor, which `edaha editor` loads when it is installed */
|
|
14
|
+
export const EDITOR_PACKAGE = "@lvl99dotcom/edaha-editor";
|
|
15
|
+
/** The editor's default port */
|
|
16
|
+
export const EDITOR_PORT = 5180;
|
|
17
|
+
/** How to use the `edaha` command */
|
|
18
|
+
export const USAGE = `Usage: edaha <command> [options]
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
build Build the site into the config file's outputDir (and copy it into publishDir, if set)
|
|
22
|
+
editor Run the local article editor (only reachable from this computer)
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
-c, --config <file> The config file (default: the first edahaconfig file found in --dir, then in the nearest
|
|
26
|
+
package.json's folder). The site folder is the config file's folder.
|
|
27
|
+
--dir <folder> The folder to look for a config file in (default: the current folder)
|
|
28
|
+
--site-url <url> build: the website's absolute URL for feeds (default: SITE_URL, then the config's siteUrl)
|
|
29
|
+
--port <number> editor: the port to listen on (default: ${EDITOR_PORT})
|
|
30
|
+
-h, --help Show this help
|
|
31
|
+
-v, --version Show edaha.md's version
|
|
32
|
+
`;
|
|
33
|
+
/**
|
|
34
|
+
* Load `startEditor` from the editor package. Throws with how to install it if it isn't installed.
|
|
35
|
+
*
|
|
36
|
+
* @param importPackage - imports a package by name (replaceable for tests)
|
|
37
|
+
* @example
|
|
38
|
+
* const startEditor = await loadEditor();
|
|
39
|
+
* await startEditor({ siteDir: "my-site", port: EDITOR_PORT });
|
|
40
|
+
*/
|
|
41
|
+
export const loadEditor = async (importPackage = (name) => import(__rewriteRelativeImportExtension(name))) => {
|
|
42
|
+
try {
|
|
43
|
+
return (await importPackage(EDITOR_PACKAGE)).startEditor;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// Only when the editor package itself is missing, not one of its own dependencies
|
|
47
|
+
if (error.code === "ERR_MODULE_NOT_FOUND" &&
|
|
48
|
+
error.message.includes(`'${EDITOR_PACKAGE}'`))
|
|
49
|
+
throw new Error(`The article editor isn't installed. Install it next to edaha.md with \`npm add -D ${EDITOR_PACKAGE}\` (or pnpm/yarn).`, { cause: error });
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* edaha.md's version, from its package.json.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* version(); // "0.2.0"
|
|
58
|
+
*/
|
|
59
|
+
export const version = () => JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
|
|
60
|
+
/**
|
|
61
|
+
* Read a port number from the command line.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* parsePort("5180"); // 5180
|
|
65
|
+
*/
|
|
66
|
+
export const parsePort = (value) => {
|
|
67
|
+
const port = Number(value);
|
|
68
|
+
if (!/^\d+$/.test(value) || port < 1 || port > 65535)
|
|
69
|
+
throw new Error(`--port must be a number from 1 to 65535, got "${value}"`);
|
|
70
|
+
return port;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Run the `edaha` command with its arguments (without `node` and the script). Returns the exit code; for `editor`, it
|
|
74
|
+
* returns once the editor is running.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* await runCli(["build", "--dir", "my-site"], { cwd: process.cwd(), env: process.env, log: console.log, error: console.error });
|
|
78
|
+
*/
|
|
79
|
+
export const runCli = async (args, context) => {
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = parse(args);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
context.error(`${error.message}\n\n${USAGE}`);
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
const { values, positionals } = parsed;
|
|
89
|
+
if (values.version) {
|
|
90
|
+
context.log(version());
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
const [command, ...rest] = positionals;
|
|
94
|
+
if (values.help || !command) {
|
|
95
|
+
context.log(USAGE);
|
|
96
|
+
return values.help ? 0 : 1;
|
|
97
|
+
}
|
|
98
|
+
if (rest.length) {
|
|
99
|
+
context.error(`Unexpected arguments: ${rest.join(" ")}\n\n${USAGE}`);
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
const siteDir = resolve(context.cwd, values.dir ?? ".");
|
|
103
|
+
const configFile = values.config === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: resolve(context.cwd, values.config);
|
|
106
|
+
try {
|
|
107
|
+
if (command === "build") {
|
|
108
|
+
const result = await (context.build ?? buildSite)({
|
|
109
|
+
siteDir,
|
|
110
|
+
configFile,
|
|
111
|
+
siteUrl: values["site-url"] ?? context.env.SITE_URL,
|
|
112
|
+
logger: { warn: context.error },
|
|
113
|
+
});
|
|
114
|
+
context.log(`Built ${result.articles.length} articles (${result.files.length} files) into ${result.outputDir}` +
|
|
115
|
+
(result.publishDir
|
|
116
|
+
? ` and copied them into ${result.publishDir}`
|
|
117
|
+
: ""));
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
if (command === "editor") {
|
|
121
|
+
const editor = await (context.editor ?? (await loadEditor()))({
|
|
122
|
+
siteDir,
|
|
123
|
+
configFile,
|
|
124
|
+
port: values.port === undefined ? EDITOR_PORT : parsePort(values.port),
|
|
125
|
+
});
|
|
126
|
+
context.log(`Article editor running at ${editor.url} (press Ctrl+C to stop)`);
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
context.error(error.message);
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
context.error(`Unknown command "${command}"\n\n${USAGE}`);
|
|
135
|
+
return 1;
|
|
136
|
+
};
|
|
137
|
+
/** Parse the command line's options */
|
|
138
|
+
const parse = (args) => parseArgs({
|
|
139
|
+
args,
|
|
140
|
+
allowPositionals: true,
|
|
141
|
+
options: {
|
|
142
|
+
config: { type: "string", short: "c" },
|
|
143
|
+
dir: { type: "string" },
|
|
144
|
+
"site-url": { type: "string" },
|
|
145
|
+
port: { type: "string" },
|
|
146
|
+
help: { type: "boolean", short: "h" },
|
|
147
|
+
version: { type: "boolean", short: "v" },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embed blocks in article markdown: `<!-- embed:<key> -->content<!-- /embed:<key> -->`, where the closing tag may leave
|
|
3
|
+
* out the key. Group 1 is the key (undefined for an old `<!-- embed -->` block without one), group 2 the content.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EMBED_BLOCK: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
* An embed block's content without the blank lines around it, so blocks can be written on their own lines. Spaces at
|
|
8
|
+
* the start of its first line are kept (e.g. indented code).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* embedContent("\n graph TD;\n A-->B;\n"); // " graph TD;\n A-->B;"
|
|
12
|
+
*/
|
|
13
|
+
export declare const embedContent: (content: string) => string;
|
|
14
|
+
/** An embed's options, by name, as set in the embed dialog */
|
|
15
|
+
export type EmbedOptionValues = Record<string, unknown>;
|
|
16
|
+
/** An embed block's options and content */
|
|
17
|
+
export interface EmbedBlockParts {
|
|
18
|
+
/** What is between its tags after its options, without blank lines around it (see embedContent) */
|
|
19
|
+
content: string;
|
|
20
|
+
/** Its options (empty when it has none, or they can't be read) */
|
|
21
|
+
options: EmbedOptionValues;
|
|
22
|
+
/** Why its options can't be read, if they can't */
|
|
23
|
+
optionsError?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Split an embed block's text (between its tags) into its options and content.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* splitEmbed("\n<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b\n");
|
|
30
|
+
* // { content: "https://a.bandcamp.com/album/b", options: { layout: "large" } }
|
|
31
|
+
*/
|
|
32
|
+
export declare const splitEmbed: (text: string) => EmbedBlockParts;
|
|
33
|
+
/**
|
|
34
|
+
* An embed block's options from JSON (e.g. an editor's `data-options` attribute), or none when it isn't a map.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* embedOptionsOf('{"layout":"large"}'); // { layout: "large" }
|
|
38
|
+
* embedOptionsOf(null); // {}
|
|
39
|
+
*/
|
|
40
|
+
export declare const embedOptionsOf: (json: string | null) => EmbedOptionValues;
|
|
41
|
+
/**
|
|
42
|
+
* Write an embed block: on one line for single-line content (e.g. a URL) without options, otherwise with its tags on
|
|
43
|
+
* their own lines, and its options (if any) in YAML before the content.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* embedBlock("youtube", "https://youtu.be/aju_UB5VIf8"); // "<!-- embed:youtube -->https://youtu.be/aju_UB5VIf8<!-- /embed:youtube -->"
|
|
47
|
+
* embedBlock("mermaidjs", "graph TD;\n A-->B;"); // "<!-- embed:mermaidjs -->\ngraph TD;\n A-->B;\n<!-- /embed:mermaidjs -->"
|
|
48
|
+
* embedBlock("bandcamp", "https://a.bandcamp.com/album/b", { layout: "large" });
|
|
49
|
+
* // "<!-- embed:bandcamp -->\n<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b\n<!-- /embed:bandcamp -->"
|
|
50
|
+
*/
|
|
51
|
+
export declare const embedBlock: (key: string, content: string, options?: EmbedOptionValues) => string;
|
|
52
|
+
/**
|
|
53
|
+
* What goes between an embed block's tags: its options (if any) in YAML, then its content.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* embedText("https://youtu.be/x"); // "https://youtu.be/x"
|
|
57
|
+
* embedText("https://a.bandcamp.com/album/b", { layout: "large" }); // "<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b"
|
|
58
|
+
*/
|
|
59
|
+
export declare const embedText: (content: string, options?: EmbedOptionValues) => string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Reading and writing embed blocks in article markdown. Has no Node.js imports, so the editor's page can use it too.
|
|
2
|
+
import { parse, stringify } from "yaml";
|
|
3
|
+
/**
|
|
4
|
+
* Embed blocks in article markdown: `<!-- embed:<key> -->content<!-- /embed:<key> -->`, where the closing tag may leave
|
|
5
|
+
* out the key. Group 1 is the key (undefined for an old `<!-- embed -->` block without one), group 2 the content.
|
|
6
|
+
*/
|
|
7
|
+
export const EMBED_BLOCK = /<!--\s*embed(?::([a-z0-9]+(?:-[a-z0-9]+)*))?\s*-->([\s\S]*?)<!--\s*\/embed(?::\1)?\s*-->/g;
|
|
8
|
+
/**
|
|
9
|
+
* An embed block's content without the blank lines around it, so blocks can be written on their own lines. Spaces at
|
|
10
|
+
* the start of its first line are kept (e.g. indented code).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* embedContent("\n graph TD;\n A-->B;\n"); // " graph TD;\n A-->B;"
|
|
14
|
+
*/
|
|
15
|
+
export const embedContent = (content) => content.replace(/^(?:[ \t]*\r?\n)+/, "").trimEnd();
|
|
16
|
+
/**
|
|
17
|
+
* The options at the start of an embed block: `<!--yaml ... -->` (or `<!--yml`, or `<!--json` for JSON), like an
|
|
18
|
+
* article's config header.
|
|
19
|
+
*/
|
|
20
|
+
const EMBED_OPTIONS = /^\s*<!--(yaml|yml|json)[ \t]*\r?\n([\s\S]*?)-->/;
|
|
21
|
+
/**
|
|
22
|
+
* Split an embed block's text (between its tags) into its options and content.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* splitEmbed("\n<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b\n");
|
|
26
|
+
* // { content: "https://a.bandcamp.com/album/b", options: { layout: "large" } }
|
|
27
|
+
*/
|
|
28
|
+
export const splitEmbed = (text) => {
|
|
29
|
+
const match = EMBED_OPTIONS.exec(text);
|
|
30
|
+
if (!match)
|
|
31
|
+
return { content: embedContent(text), options: {} };
|
|
32
|
+
const content = embedContent(text.slice(match[0].length));
|
|
33
|
+
let options;
|
|
34
|
+
try {
|
|
35
|
+
const source = match[2];
|
|
36
|
+
options =
|
|
37
|
+
match[1] === "json"
|
|
38
|
+
? source.trim()
|
|
39
|
+
? JSON.parse(source)
|
|
40
|
+
: null
|
|
41
|
+
: parse(source);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
content,
|
|
46
|
+
options: {},
|
|
47
|
+
optionsError: `The options can't be read: ${error.message}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (options === null || options === undefined)
|
|
51
|
+
return { content, options: {} };
|
|
52
|
+
return typeof options === "object" && !Array.isArray(options)
|
|
53
|
+
? { content, options: options }
|
|
54
|
+
: {
|
|
55
|
+
content,
|
|
56
|
+
options: {},
|
|
57
|
+
optionsError: "The options must be a map of names to values",
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* An embed block's options from JSON (e.g. an editor's `data-options` attribute), or none when it isn't a map.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* embedOptionsOf('{"layout":"large"}'); // { layout: "large" }
|
|
65
|
+
* embedOptionsOf(null); // {}
|
|
66
|
+
*/
|
|
67
|
+
export const embedOptionsOf = (json) => {
|
|
68
|
+
try {
|
|
69
|
+
const options = JSON.parse(json ?? "");
|
|
70
|
+
return options && typeof options === "object" && !Array.isArray(options)
|
|
71
|
+
? options
|
|
72
|
+
: {};
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Write an embed block: on one line for single-line content (e.g. a URL) without options, otherwise with its tags on
|
|
80
|
+
* their own lines, and its options (if any) in YAML before the content.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* embedBlock("youtube", "https://youtu.be/aju_UB5VIf8"); // "<!-- embed:youtube -->https://youtu.be/aju_UB5VIf8<!-- /embed:youtube -->"
|
|
84
|
+
* embedBlock("mermaidjs", "graph TD;\n A-->B;"); // "<!-- embed:mermaidjs -->\ngraph TD;\n A-->B;\n<!-- /embed:mermaidjs -->"
|
|
85
|
+
* embedBlock("bandcamp", "https://a.bandcamp.com/album/b", { layout: "large" });
|
|
86
|
+
* // "<!-- embed:bandcamp -->\n<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b\n<!-- /embed:bandcamp -->"
|
|
87
|
+
*/
|
|
88
|
+
export const embedBlock = (key, content, options = {}) => {
|
|
89
|
+
const text = embedText(content, options);
|
|
90
|
+
return text.includes("\n")
|
|
91
|
+
? `<!-- embed:${key} -->\n${text}\n<!-- /embed:${key} -->`
|
|
92
|
+
: `<!-- embed:${key} -->${text}<!-- /embed:${key} -->`;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* What goes between an embed block's tags: its options (if any) in YAML, then its content.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* embedText("https://youtu.be/x"); // "https://youtu.be/x"
|
|
99
|
+
* embedText("https://a.bandcamp.com/album/b", { layout: "large" }); // "<!--yaml\nlayout: large\n-->\nhttps://a.bandcamp.com/album/b"
|
|
100
|
+
*/
|
|
101
|
+
export const embedText = (content, options = {}) => Object.keys(options).length
|
|
102
|
+
? `<!--yaml\n${stringify(options)}-->\n${content}`
|
|
103
|
+
: content;
|