@lvl99dotcom/edaha.md 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +258 -2
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +9 -0
- package/dist/cli/index.d.ts +41 -0
- package/dist/cli/index.js +110 -0
- package/dist/client/assets/index-BbKEbPS8.css +1 -0
- package/dist/client/assets/index-DtG7vi1d.js +559 -0
- package/dist/client/index.html +13 -0
- package/dist/editor/index.d.ts +62 -0
- package/dist/editor/index.js +102 -0
- package/dist/embeds/bandcamp/index.d.ts +9 -0
- package/dist/embeds/bandcamp/index.js +28 -0
- package/dist/embeds/index.d.ts +40 -0
- package/dist/embeds/index.js +71 -0
- package/dist/embeds/types/index.d.ts +14 -0
- package/dist/embeds/types/index.js +1 -0
- package/dist/embeds/youtube/index.d.ts +17 -0
- package/dist/embeds/youtube/index.js +48 -0
- package/dist/generator/article/index.d.ts +111 -0
- package/dist/generator/article/index.js +257 -0
- package/dist/generator/build/index.d.ts +77 -0
- package/dist/generator/build/index.js +293 -0
- package/dist/generator/config/index.d.ts +59 -0
- package/dist/generator/config/index.js +176 -0
- package/dist/generator/format/index.d.ts +52 -0
- package/dist/generator/format/index.js +102 -0
- package/dist/generator/lists/index.d.ts +63 -0
- package/dist/generator/lists/index.js +132 -0
- package/dist/generator/markdown/index.d.ts +20 -0
- package/dist/generator/markdown/index.js +55 -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 +56 -0
- package/dist/generator/templates/index.js +109 -0
- package/dist/generator/types/index.d.ts +161 -0
- package/dist/generator/types/index.js +1 -0
- package/dist/generator/urls/index.d.ts +40 -0
- package/dist/generator/urls/index.js +67 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/server/app/index.d.ts +39 -0
- package/dist/server/app/index.js +138 -0
- package/dist/server/convert/index.d.ts +25 -0
- package/dist/server/convert/index.js +125 -0
- package/dist/server/store/index.d.ts +148 -0
- package/dist/server/store/index.js +411 -0
- package/dist/server/types/index.d.ts +76 -0
- package/dist/server/types/index.js +1 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/index.js +9 -0
- package/package.json +93 -3
- package/theme/static/site.css +220 -0
- package/theme/templates/article/list.njk +69 -0
- package/theme/templates/article/single.njk +58 -0
- package/theme/templates/layouts/html.njk +50 -0
- package/theme/templates/layouts/rssfeed.njk +28 -0
- package/theme/templates/page/home.njk +21 -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 [yyyy] [name of copyright owner]
|
|
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,259 @@
|
|
|
1
|
-
#
|
|
1
|
+
# edaha.md
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A static website and blog generator. It builds pages, paginated lists, tag and author pages and RSS feeds from Markdown articles with [Nunjucks](https://mozilla.github.io/nunjucks/) templates. It also includes a local article editor.
|
|
4
|
+
|
|
5
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Node.js 22 or later.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add -D @lvl99dotcom/edaha.md
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
A site is a folder with a `config.yml` and an `articles/` folder:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
my-site/
|
|
21
|
+
config.yml
|
|
22
|
+
articles/
|
|
23
|
+
news/
|
|
24
|
+
hello-world/
|
|
25
|
+
article.md
|
|
26
|
+
photo.jpg
|
|
27
|
+
templates/ # optional; overrides the default theme's templates
|
|
28
|
+
static/ # optional; overrides and adds to the default theme's static files
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
# config.yml
|
|
33
|
+
name: My Site
|
|
34
|
+
description: News and notes.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npx edaha build --dir my-site --site-url https://example.com
|
|
39
|
+
npx edaha editor --dir my-site
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The build writes the website into `my-site/dist`. The editor runs at http://127.0.0.1:5180.
|
|
43
|
+
|
|
44
|
+
## Commands
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
edaha build Build the site into config.yml's outputDir (and copy it into publishDir, if set)
|
|
48
|
+
edaha editor Run the local article editor (only reachable from this computer)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Option | Command | Description |
|
|
52
|
+
| ------------------ | ------- | ------------------------------------------------------------------------------------ |
|
|
53
|
+
| `--dir <folder>` | both | The site folder. Default: the current folder |
|
|
54
|
+
| `--site-url <url>` | build | The website's absolute URL, for feeds. Default: `SITE_URL`, then `siteUrl` in config |
|
|
55
|
+
| `--port <number>` | editor | The port to listen on. Default: 5180 |
|
|
56
|
+
| `-h`, `--help` | | Show help |
|
|
57
|
+
| `-v`, `--version` | | Show the version |
|
|
58
|
+
|
|
59
|
+
## config.yml
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
# Required: the website's name and description
|
|
63
|
+
name: My Site
|
|
64
|
+
description: News and notes.
|
|
65
|
+
# Optional; the URL path prefix of every article type. Default: "" (the website's root)
|
|
66
|
+
path: ""
|
|
67
|
+
# Optional; the build folder, inside the site folder. It is emptied on every build. Default: dist
|
|
68
|
+
outputDir: dist
|
|
69
|
+
# Optional; a folder outside the site folder that the built files are copied into, e.g. another app's build folder
|
|
70
|
+
publishDir: ../app/dist
|
|
71
|
+
# Optional; the website's absolute URL for feeds, used when SITE_URL isn't set. Default: http://localhost (with a warning)
|
|
72
|
+
siteUrl: https://example.com
|
|
73
|
+
# Optional; paths at the website's root that articles and types can't use, e.g. another app's routes
|
|
74
|
+
reservedPaths: [app, api]
|
|
75
|
+
# Optional; settings for each article type (a folder in articles/)
|
|
76
|
+
types:
|
|
77
|
+
news:
|
|
78
|
+
labelSingle: News
|
|
79
|
+
labelPlural: News
|
|
80
|
+
page:
|
|
81
|
+
labelSingle: Page
|
|
82
|
+
labelPlural: Pages
|
|
83
|
+
# The website's own pages, at its root: page/index is "/", page/about is "/about"
|
|
84
|
+
path: ""
|
|
85
|
+
generate:
|
|
86
|
+
list: false
|
|
87
|
+
feed: false
|
|
88
|
+
author: false
|
|
89
|
+
tag: false
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- **Article types:** each folder in `articles/` is a type. `types` sets:
|
|
93
|
+
- its URL `path` (default: its name; `""` for the root);
|
|
94
|
+
- its labels (`labelSingle`, `labelPlural`);
|
|
95
|
+
- what is built for it (`generate`: `article`, `list`, `feed`, `author`, `tag`, all `true` by default, or `generate: false` for nothing).
|
|
96
|
+
|
|
97
|
+
A type that isn't configured gives a warning and uses the defaults. Unknown settings stop the build. Types can't be called `tags` or `authors`.
|
|
98
|
+
|
|
99
|
+
- **Publishing:** when `publishDir` is set, the copy first removes what the previous build published there. It stops if a file is already there (e.g. one written by the other app's build).
|
|
100
|
+
|
|
101
|
+
## Articles
|
|
102
|
+
|
|
103
|
+
Each article is a folder `articles/<type>/<slug>/` with an `article.md`. Its images and attachments go in the same folder. Folder names are lowercase kebab-case.
|
|
104
|
+
|
|
105
|
+
```md
|
|
106
|
+
<!--yaml
|
|
107
|
+
date: 2026-10-19T12:00:00.000Z # required
|
|
108
|
+
status: published # published (default), draft (not built) or unlisted (own page only, not in lists or feeds)
|
|
109
|
+
author: Jo Bloggs # or { name, email, url }; defaults to the website name
|
|
110
|
+
template: single # optional; a template in templates/<type>/ (or templates/article/), e.g. home
|
|
111
|
+
tags: [News]
|
|
112
|
+
thumbnail: thumb.jpg # relative to the article folder, or an absolute URL
|
|
113
|
+
attachments:
|
|
114
|
+
- url: guide.pdf
|
|
115
|
+
-->
|
|
116
|
+
|
|
117
|
+
# Article title
|
|
118
|
+
|
|
119
|
+
The excerpt shown in lists. <!-- readmore -->The rest of the article.
|
|
120
|
+
|
|
121
|
+
<!-- embed -->https://www.youtube.com/watch?v=aju_UB5VIf8<!-- /embed -->
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- **Heading IDs:** headings get IDs from their text, so they can be linked to. "This?! Is an, example..." becomes `#this-is-an-example`. A repeated heading gets `-2`, `-3`…, and a heading without letters or numbers gets none.
|
|
125
|
+
- **Extra HTML:** `<small>`, `<big>` and `<details><summary>…</summary>…</details>` can be used. Leave a blank line after `<summary>…</summary>` and before `</details>`, so the content between them is read as Markdown.
|
|
126
|
+
- **Output:**
|
|
127
|
+
- Each type's list is at its path (e.g. `/news/`, 20 per page: `/news/2`, …), with a `feed.xml` RSS feed.
|
|
128
|
+
- Tag and author lists are under it (`/news/tags/<tag>/`, `/news/authors/<author>/`).
|
|
129
|
+
- Articles are at `/<type path>/<slug>/`.
|
|
130
|
+
- An article named `index` is built at its type's path in place of the list (the feed is still built). Its template gets the list's newest articles.
|
|
131
|
+
- **URLs can't clash:** slugs can't be `tags`, `authors` or numbers. At the website's root, slugs and type paths can't be a `reservedPaths` entry or another type's path.
|
|
132
|
+
|
|
133
|
+
## Embeds
|
|
134
|
+
|
|
135
|
+
Put a URL between `<!-- embed -->` and `<!-- /embed -->` to embed it:
|
|
136
|
+
|
|
137
|
+
- **YouTube** embeds always use youtube-nocookie.com.
|
|
138
|
+
- **Bandcamp** embeds fetch the page at build time, so the build needs internet access.
|
|
139
|
+
|
|
140
|
+
An unrecognised URL gives a warning and is rendered as a link.
|
|
141
|
+
|
|
142
|
+
To add your own renderers, build from code:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import {
|
|
146
|
+
buildBlog,
|
|
147
|
+
EMBED_RENDERERS,
|
|
148
|
+
type EmbedRenderer,
|
|
149
|
+
} from "@lvl99dotcom/edaha.md";
|
|
150
|
+
|
|
151
|
+
const vimeo: EmbedRenderer = {
|
|
152
|
+
name: "Vimeo",
|
|
153
|
+
match: (url) => url.hostname === "vimeo.com",
|
|
154
|
+
render: async (url) =>
|
|
155
|
+
`<iframe src="https://player.vimeo.com/video${url.pathname}"></iframe>`,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
await buildBlog({
|
|
159
|
+
siteDir: "my-site",
|
|
160
|
+
siteUrl: "https://example.com",
|
|
161
|
+
embedRenderers: [...EMBED_RENDERERS, vimeo],
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The editor's previews only use the built-in renderers.
|
|
166
|
+
|
|
167
|
+
## Templates and the default theme
|
|
168
|
+
|
|
169
|
+
edaha.md ships a neutral default theme in `theme/`: Nunjucks templates in `theme/templates/` and a stylesheet in `theme/static/site.css`.
|
|
170
|
+
|
|
171
|
+
- **Templates:** a site's own `templates/` folder overrides the theme's templates file by file. `article/single.njk`, `article/list.njk`, `layouts/html.njk` and `layouts/rssfeed.njk` must exist in one of the two. They are the defaults for every type. A type's own folder (e.g. `templates/page/`) overrides them, and an article's `template` setting picks another one (e.g. `page/home.njk`).
|
|
172
|
+
- **Static files:** a site's own `static/` folder is copied to the website's root, over the theme's static files. A static file with the same path as an article's file stops the build.
|
|
173
|
+
|
|
174
|
+
Templates get these variables:
|
|
175
|
+
|
|
176
|
+
- `site.url`: the website's absolute URL.
|
|
177
|
+
- `blog`: `name`, `description`, `url` and each type's settings and `url`.
|
|
178
|
+
- `article` (on article pages): its settings, `bodyHtml`, `excerptHtml`, `author`, `tags` and `attachments`.
|
|
179
|
+
- `list` (on list pages and index articles): its `articles` and `pagination`.
|
|
180
|
+
|
|
181
|
+
They have these filters:
|
|
182
|
+
|
|
183
|
+
- `date`: e.g. 19 October 2026.
|
|
184
|
+
- `rfc822`: the date format feeds use.
|
|
185
|
+
- `absoluteUrls(site.url)`: makes root-relative links absolute.
|
|
186
|
+
|
|
187
|
+
The full types are exported as `TemplateData*`.
|
|
188
|
+
|
|
189
|
+
## Editor
|
|
190
|
+
|
|
191
|
+
`edaha editor` runs a local WYSIWYG editor for a site's articles. It only listens on `127.0.0.1` and must never be deployed.
|
|
192
|
+
|
|
193
|
+
- **Articles:** it lists every article (including drafts), grouped by type with the newest first. It edits the title, template, body and settings.
|
|
194
|
+
- **Body:** rich text with images, links, tables, small and big text, collapsible details blocks, embeds and the read more break.
|
|
195
|
+
- **Files:** it uploads images and attachments into the article's folder. Uploads need the article to be saved first.
|
|
196
|
+
- **Moving:** changing an article's type or slug moves its folder.
|
|
197
|
+
- **Views:** "WYSIWYG", "Markdown" and "Preview" switch between rich text, the body's Markdown, and the unsaved article rendered with its type's "single" template. The preview uses the site's templates and static files over the theme's. It is sent with a Content Security Policy that forbids scripts, requests and forms, so nothing in an article can use the editor's API.
|
|
198
|
+
- **Safety:** its API only accepts changes from the editor page itself.
|
|
199
|
+
- **Saving:** saving rewrites `article.md` in a normalised form (e.g. the read more break on its own line).
|
|
200
|
+
|
|
201
|
+
## API
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { buildBlog, startEditor } from "@lvl99dotcom/edaha.md";
|
|
205
|
+
|
|
206
|
+
const result = await buildBlog({
|
|
207
|
+
siteDir: "my-site",
|
|
208
|
+
siteUrl: "https://example.com",
|
|
209
|
+
});
|
|
210
|
+
console.log(result.files);
|
|
211
|
+
|
|
212
|
+
const editor = await startEditor({ siteDir: "my-site", port: 5180 });
|
|
213
|
+
console.log(`Open ${editor.url}`);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`buildBlog` options:
|
|
217
|
+
|
|
218
|
+
- `siteDir` (required)
|
|
219
|
+
- `siteUrl`
|
|
220
|
+
- `themeDir`: another theme folder
|
|
221
|
+
- `logger`
|
|
222
|
+
- `fetch`
|
|
223
|
+
- `embedRenderers`
|
|
224
|
+
|
|
225
|
+
`startEditor` options:
|
|
226
|
+
|
|
227
|
+
- `siteDir` (required)
|
|
228
|
+
- `port`
|
|
229
|
+
- `themeDir`
|
|
230
|
+
- `fetch`
|
|
231
|
+
|
|
232
|
+
## Development
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
pnpm install
|
|
236
|
+
pnpm build # dist/: Node.js code and types (tsc), and the editor page (Vite)
|
|
237
|
+
pnpm test # unit tests
|
|
238
|
+
pnpm test:coverage # unit tests with coverage
|
|
239
|
+
pnpm typecheck
|
|
240
|
+
pnpm lint
|
|
241
|
+
pnpm format:check
|
|
242
|
+
EDAHA_SITE_DIR=../my-site pnpm dev:editor # work on the editor page with Vite, for a site
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Project layout
|
|
246
|
+
|
|
247
|
+
- `src/generator/`: reads `config.yml` and articles, renders templates and builds the site (`buildBlog`).
|
|
248
|
+
- `src/embeds/`: embed renderers.
|
|
249
|
+
- `src/server/`: the editor's API, article store and Markdown conversion.
|
|
250
|
+
- `src/client/`: the editor page (Lit and Tiptap), bundled into `dist/client`.
|
|
251
|
+
- `src/editor/`: the editor's web server (`startEditor`).
|
|
252
|
+
- `src/cli/`: the `edaha` command.
|
|
253
|
+
- `src/theme/`: the path to `theme/`.
|
|
254
|
+
- `src/shared/tests/`: test helpers and a fixture site.
|
|
255
|
+
- `theme/`: the default templates and stylesheet.
|
|
256
|
+
|
|
257
|
+
Source imports name their files with `.ts` extensions (e.g. `../slug/index.ts`), so scripts run directly with Node.js type stripping. The build rewrites them to `.js`.
|
|
258
|
+
|
|
259
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) to contribute.
|
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,41 @@
|
|
|
1
|
+
import { type EditorServer, type EditorServerOptions } from "../editor/index.ts";
|
|
2
|
+
import type { BuildOptions, BuildResult } from "../generator/build/index.ts";
|
|
3
|
+
/** How to use the `edaha` command */
|
|
4
|
+
export declare const USAGE = "Usage: edaha <command> [options]\n\nCommands:\n build Build the site into config.yml's outputDir (and copy it into publishDir, if set)\n editor Run the local article editor (only reachable from this computer)\n\nOptions:\n --dir <folder> The site folder, which holds config.yml and articles/ (default: the current folder)\n --site-url <url> build: the website's absolute URL for feeds (default: SITE_URL, then config.yml'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";
|
|
5
|
+
/** What the command line needs from its surroundings, so it can be tested */
|
|
6
|
+
export interface CliContext {
|
|
7
|
+
/** The folder the command runs in */
|
|
8
|
+
cwd: string;
|
|
9
|
+
/** Environment variables */
|
|
10
|
+
env: Record<string, string | undefined>;
|
|
11
|
+
/** Where messages go */
|
|
12
|
+
log: (message: string) => void;
|
|
13
|
+
/** Where errors and warnings go */
|
|
14
|
+
error: (message: string) => void;
|
|
15
|
+
/** Builds the site (default: buildBlog) */
|
|
16
|
+
build?: (options: BuildOptions) => Promise<BuildResult>;
|
|
17
|
+
/** Starts the editor (default: startEditor) */
|
|
18
|
+
editor?: (options: EditorServerOptions) => Promise<EditorServer>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* edaha.md's version, from its package.json.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* version(); // "0.1.0"
|
|
25
|
+
*/
|
|
26
|
+
export declare const version: () => string;
|
|
27
|
+
/**
|
|
28
|
+
* Read a port number from the command line.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* parsePort("5180"); // 5180
|
|
32
|
+
*/
|
|
33
|
+
export declare const parsePort: (value: string) => number;
|
|
34
|
+
/**
|
|
35
|
+
* Run the `edaha` command with its arguments (without `node` and the script). Returns the exit code; for `editor`, it
|
|
36
|
+
* returns once the editor is running.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* await runCli(["build", "--dir", "my-site"], { cwd: process.cwd(), env: process.env, log: console.log, error: console.error });
|
|
40
|
+
*/
|
|
41
|
+
export declare const runCli: (args: string[], context: CliContext) => Promise<number>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { buildBlog } from "../generator/build/index.js";
|
|
5
|
+
import { EDITOR_PORT, startEditor, } from "../editor/index.js";
|
|
6
|
+
/** How to use the `edaha` command */
|
|
7
|
+
export const USAGE = `Usage: edaha <command> [options]
|
|
8
|
+
|
|
9
|
+
Commands:
|
|
10
|
+
build Build the site into config.yml's outputDir (and copy it into publishDir, if set)
|
|
11
|
+
editor Run the local article editor (only reachable from this computer)
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
--dir <folder> The site folder, which holds config.yml and articles/ (default: the current folder)
|
|
15
|
+
--site-url <url> build: the website's absolute URL for feeds (default: SITE_URL, then config.yml's siteUrl)
|
|
16
|
+
--port <number> editor: the port to listen on (default: ${EDITOR_PORT})
|
|
17
|
+
-h, --help Show this help
|
|
18
|
+
-v, --version Show edaha.md's version
|
|
19
|
+
`;
|
|
20
|
+
/**
|
|
21
|
+
* edaha.md's version, from its package.json.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* version(); // "0.1.0"
|
|
25
|
+
*/
|
|
26
|
+
export const version = () => JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
|
|
27
|
+
/**
|
|
28
|
+
* Read a port number from the command line.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* parsePort("5180"); // 5180
|
|
32
|
+
*/
|
|
33
|
+
export const parsePort = (value) => {
|
|
34
|
+
const port = Number(value);
|
|
35
|
+
if (!/^\d+$/.test(value) || port < 1 || port > 65535)
|
|
36
|
+
throw new Error(`--port must be a number from 1 to 65535, got "${value}"`);
|
|
37
|
+
return port;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Run the `edaha` command with its arguments (without `node` and the script). Returns the exit code; for `editor`, it
|
|
41
|
+
* returns once the editor is running.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* await runCli(["build", "--dir", "my-site"], { cwd: process.cwd(), env: process.env, log: console.log, error: console.error });
|
|
45
|
+
*/
|
|
46
|
+
export const runCli = async (args, context) => {
|
|
47
|
+
let parsed;
|
|
48
|
+
try {
|
|
49
|
+
parsed = parse(args);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
context.error(`${error.message}\n\n${USAGE}`);
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
const { values, positionals } = parsed;
|
|
56
|
+
if (values.version) {
|
|
57
|
+
context.log(version());
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
const [command, ...rest] = positionals;
|
|
61
|
+
if (values.help || !command) {
|
|
62
|
+
context.log(USAGE);
|
|
63
|
+
return values.help ? 0 : 1;
|
|
64
|
+
}
|
|
65
|
+
if (rest.length) {
|
|
66
|
+
context.error(`Unexpected arguments: ${rest.join(" ")}\n\n${USAGE}`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
const siteDir = resolve(context.cwd, values.dir ?? ".");
|
|
70
|
+
try {
|
|
71
|
+
if (command === "build") {
|
|
72
|
+
const result = await (context.build ?? buildBlog)({
|
|
73
|
+
siteDir,
|
|
74
|
+
siteUrl: values["site-url"] ?? context.env.SITE_URL,
|
|
75
|
+
logger: { warn: context.error },
|
|
76
|
+
});
|
|
77
|
+
context.log(`Built ${result.articles.length} articles (${result.files.length} files) into ${result.outputDir}` +
|
|
78
|
+
(result.publishDir
|
|
79
|
+
? ` and copied them into ${result.publishDir}`
|
|
80
|
+
: ""));
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
if (command === "editor") {
|
|
84
|
+
const editor = await (context.editor ?? startEditor)({
|
|
85
|
+
siteDir,
|
|
86
|
+
port: values.port === undefined ? EDITOR_PORT : parsePort(values.port),
|
|
87
|
+
});
|
|
88
|
+
context.log(`Article editor for ${siteDir} running at ${editor.url} (press Ctrl+C to stop)`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
context.error(error.message);
|
|
94
|
+
return 1;
|
|
95
|
+
}
|
|
96
|
+
context.error(`Unknown command "${command}"\n\n${USAGE}`);
|
|
97
|
+
return 1;
|
|
98
|
+
};
|
|
99
|
+
/** Parse the command line's options */
|
|
100
|
+
const parse = (args) => parseArgs({
|
|
101
|
+
args,
|
|
102
|
+
allowPositionals: true,
|
|
103
|
+
options: {
|
|
104
|
+
dir: { type: "string" },
|
|
105
|
+
"site-url": { type: "string" },
|
|
106
|
+
port: { type: "string" },
|
|
107
|
+
help: { type: "boolean", short: "h" },
|
|
108
|
+
version: { type: "boolean", short: "v" },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blog-editor{grid-template-columns:16rem 1fr;gap:1rem;display:grid}blog-article form{grid-template-columns:1fr 20rem;gap:1rem;display:grid}blog-article-data-field{margin-block:.5rem;display:block}blog-article-data-field input,blog-article-data-field select,blog-article-data-field textarea{box-sizing:border-box;width:100%}.toasts{flex-direction:column;gap:.5rem;max-width:24rem;display:flex;position:fixed;bottom:1rem;right:1rem}.toast{background:canvas;border:1px solid;justify-content:space-between;align-items:center;gap:.5rem;padding:.5rem .75rem;display:flex}.toast.error{border-width:2px}.dialog-backdrop{background:#0006;place-items:center;display:grid;position:fixed;inset:0}.dialog{background:canvas;border:1px solid;padding:1rem}blog-article .preview{box-sizing:border-box;width:100%;height:40rem}.richtext-content .ProseMirror{min-height:20rem}.richtext-content img{max-width:100%}.richtext-content .readmore-block,.richtext-content .embed-block{cursor:pointer;border:1px dashed;margin-block:.5rem;padding:.5rem}.richtext-content .block-header{align-items:center;gap:.5rem;display:flex}.richtext-content .block-header span{flex:1}.richtext-content [data-type=details]{cursor:pointer;border:1px dashed;margin-block:.5rem;padding:.5rem}.richtext-content [data-type=details] summary,.richtext-content [data-type=detailsContent]{cursor:text}.richtext-content [data-type=details]>button{display:none}.richtext-content [data-type=details] summary,.richtext-content [data-type=detailsContent]{border:1px dotted;margin-block-start:.5rem;padding:.25rem .5rem;display:block}.richtext-content [data-type=detailsContent][hidden]{display:block}.richtext-content [data-type=details]:before,.richtext-content [data-type=details] summary:before,.richtext-content [data-type=detailsContent]:before{opacity:.6;font-size:.75em;font-weight:400;display:block}.richtext-content [data-type=details]:before{content:"Details"}.richtext-content [data-type=details] summary:before{content:"Summary"}.richtext-content [data-type=detailsContent]:before{content:"Content"}.richtext-content .embed-preview iframe{max-width:100%}.richtext-content .heading-id{opacity:.6;-webkit-user-select:all;user-select:all;margin-inline-start:.5em;font-size:.75em;font-weight:400}.richtext-content .ProseMirror-selectednode{outline:3px solid highlight}
|