@junejs/server 1.0.0-dev.25 → 1.0.0-dev.28
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/assets/icon-latin.LICENSE.txt +92 -0
- package/assets/icon-latin.ttf +0 -0
- package/dist/app.js +22 -2
- package/dist/build.js +20 -3
- package/dist/config-freeze.js +5 -2
- package/dist/content.d.ts +16 -2
- package/dist/content.js +43 -3
- package/dist/favicon.d.ts +38 -0
- package/dist/favicon.js +248 -0
- package/dist/icon-letter.d.ts +4 -0
- package/dist/icon-letter.js +8 -0
- package/dist/pipeline.js +18 -3
- package/dist/rsc-runtime/rsc-worker.js +11 -8
- package/dist/web-manifest.d.ts +6 -0
- package/dist/web-manifest.js +46 -0
- package/package.json +5 -3
- package/src/app.ts +39 -0
- package/src/build.ts +25 -3
- package/src/config-freeze.ts +6 -1
- package/src/content.ts +55 -4
- package/src/favicon.ts +325 -0
- package/src/icon-letter.ts +14 -0
- package/src/pipeline.ts +37 -4
- package/src/rsc-runtime/rsc-worker.tsx +5 -4
- package/src/web-manifest.ts +42 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
-----------------------------------------------------------
|
|
8
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
PREAMBLE
|
|
12
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
13
|
+
development of collaborative font projects, to support the font creation
|
|
14
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
15
|
+
open framework in which fonts may be shared and improved in partnership
|
|
16
|
+
with others.
|
|
17
|
+
|
|
18
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
19
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
20
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
21
|
+
redistributed and/or sold with any software provided that any reserved
|
|
22
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
23
|
+
however, cannot be released under any other type of license. The
|
|
24
|
+
requirement for fonts to remain under this license does not apply
|
|
25
|
+
to any document created using the fonts or their derivatives.
|
|
26
|
+
|
|
27
|
+
DEFINITIONS
|
|
28
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
29
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
30
|
+
include source files, build scripts and documentation.
|
|
31
|
+
|
|
32
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
33
|
+
copyright statement(s).
|
|
34
|
+
|
|
35
|
+
"Original Version" refers to the collection of Font Software components as
|
|
36
|
+
distributed by the Copyright Holder(s).
|
|
37
|
+
|
|
38
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
39
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
40
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
41
|
+
new environment.
|
|
42
|
+
|
|
43
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
44
|
+
writer or other person who contributed to the Font Software.
|
|
45
|
+
|
|
46
|
+
PERMISSION AND CONDITIONS
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
49
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
50
|
+
Software, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
1) Neither the Font Software nor any of its individual components,
|
|
53
|
+
in Original or Modified Versions, may be sold by itself.
|
|
54
|
+
|
|
55
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
56
|
+
redistributed and/or sold with any software, provided that each copy
|
|
57
|
+
contains the above copyright notice and this license. These can be
|
|
58
|
+
included either as stand-alone text files, human-readable headers or
|
|
59
|
+
in the appropriate machine-readable metadata fields within text or
|
|
60
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
61
|
+
|
|
62
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
63
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
64
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
65
|
+
presented to the users.
|
|
66
|
+
|
|
67
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
68
|
+
Software shall not be used to promote, endorse or advertise any
|
|
69
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
70
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
71
|
+
permission.
|
|
72
|
+
|
|
73
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
74
|
+
must be distributed entirely under this license, and must not be
|
|
75
|
+
distributed under any other license. The requirement for fonts to
|
|
76
|
+
remain under this license does not apply to any document created
|
|
77
|
+
using the Font Software.
|
|
78
|
+
|
|
79
|
+
TERMINATION
|
|
80
|
+
This license becomes null and void if any of the above conditions are
|
|
81
|
+
not met.
|
|
82
|
+
|
|
83
|
+
DISCLAIMER
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
88
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
package/dist/app.js
CHANGED
|
@@ -9,12 +9,13 @@ import { CLIENT_SCRIPT_URL, bundleClientSplit, findClientEntry } from "./client-
|
|
|
9
9
|
import { generateIslandRegistry } from "./island-registry.js";
|
|
10
10
|
import { STYLES_URL, findGlobalCss, globalCssUsesTailwind, processCssCached } from "./css.js";
|
|
11
11
|
import { contentTypeFor, safeRelativePath } from "./static-files.js";
|
|
12
|
+
import { GENERATED_ICONS, googleFontFetcher, publicFileCheck, renderIcons, resolveIcons } from "./favicon.js";
|
|
12
13
|
import { existsSync, lstatSync, realpathSync } from "node:fs";
|
|
13
14
|
import { readFile } from "node:fs/promises";
|
|
14
15
|
import { dirname, join, resolve } from "node:path";
|
|
15
16
|
import { pathToFileURL } from "node:url";
|
|
16
17
|
import { routeFromModule } from "@junejs/core/route";
|
|
17
|
-
import { resolveAgent, resolveClientRouter, resolveSpeculationRules } from "@junejs/core/config";
|
|
18
|
+
import { deployOrigin, resolveAgent, resolveClientRouter, resolveSpeculationRules } from "@junejs/core/config";
|
|
18
19
|
import { runWithTrace } from "@junejs/core/instrumentation";
|
|
19
20
|
import { anthropic } from "@junejs/core/agent-models";
|
|
20
21
|
//#region src/app.ts
|
|
@@ -68,19 +69,31 @@ function createApp({ appDir: appDirInput, config = {} }) {
|
|
|
68
69
|
try {
|
|
69
70
|
if (lstatSync(publicDir).isDirectory()) publicRoot = realpathSync(publicDir);
|
|
70
71
|
} catch {}
|
|
72
|
+
const iconPlan = resolveIcons(config.site ?? {}, publicFileCheck(publicDir));
|
|
73
|
+
let iconsPromise;
|
|
74
|
+
const getIcons = () => iconsPromise ??= renderIcons({
|
|
75
|
+
site: config.site ?? {},
|
|
76
|
+
fetchFont: googleFontFetcher(join(dirname(appDir), "node_modules", ".cache", "june", "fonts")),
|
|
77
|
+
warn: (msg) => console.warn(msg)
|
|
78
|
+
}).catch((err) => {
|
|
79
|
+
iconsPromise = void 0;
|
|
80
|
+
throw err;
|
|
81
|
+
});
|
|
71
82
|
const agent = resolveAgent(config.agent);
|
|
72
83
|
const speculation = config.speculation;
|
|
73
84
|
const clientEntry = findClientEntry(appDir) ?? findClientEntry(join(dirname(appDir), ".june", "routes"));
|
|
74
85
|
const cssEntry = findGlobalCss(appDir);
|
|
75
86
|
const docConfig = {
|
|
76
87
|
site: config.site ?? {},
|
|
88
|
+
deployOrigin: deployOrigin(config),
|
|
77
89
|
speculationRules: resolveSpeculationRules(speculation ?? void 0),
|
|
78
90
|
speculationDelivery: speculation ? speculation.delivery ?? "inline" : "inline",
|
|
79
91
|
viewTransitions: config.viewTransitions ?? true,
|
|
80
92
|
cssReset: config.cssReset ?? !globalCssUsesTailwind(appDir),
|
|
81
93
|
clientRouter: resolveClientRouter(config.clientRouter),
|
|
82
94
|
clientScript: clientEntry ? CLIENT_SCRIPT_URL : null,
|
|
83
|
-
styles: cssEntry ? STYLES_URL : null
|
|
95
|
+
styles: cssEntry ? STYLES_URL : null,
|
|
96
|
+
icons: iconPlan.icons
|
|
84
97
|
};
|
|
85
98
|
let moduleCssPromise;
|
|
86
99
|
const getModuleCss = () => moduleCssPromise ??= buildModuleCss(appDir, dirname(appDir));
|
|
@@ -233,6 +246,13 @@ function createApp({ appDir: appDirInput, config = {} }) {
|
|
|
233
246
|
}
|
|
234
247
|
}
|
|
235
248
|
}
|
|
249
|
+
if (iconPlan.generate && (request.method === "GET" || request.method === "HEAD")) {
|
|
250
|
+
const name = new URL(request.url).pathname.slice(1);
|
|
251
|
+
if (GENERATED_ICONS.includes(name)) return getIcons().then((icons) => new Response(request.method === "HEAD" ? null : icons[name], { headers: {
|
|
252
|
+
"content-type": contentTypeFor(name),
|
|
253
|
+
"cache-control": "public, max-age=0, must-revalidate"
|
|
254
|
+
} }), () => toPipeline());
|
|
255
|
+
}
|
|
236
256
|
return toPipeline();
|
|
237
257
|
},
|
|
238
258
|
async warmup() {
|
package/dist/build.js
CHANGED
|
@@ -7,6 +7,7 @@ import { bundleClientToFile, findClientEntry } from "./client-bundle.js";
|
|
|
7
7
|
import { generateIslandRegistry } from "./island-registry.js";
|
|
8
8
|
import { cssTargets, minifyCss, processCss } from "./css.js";
|
|
9
9
|
import { RESERVED_PREFIX } from "./static-files.js";
|
|
10
|
+
import { GENERATED_ICONS, googleFontFetcher, publicFileCheck, renderIcons, resolveIcons } from "./favicon.js";
|
|
10
11
|
import { loadJuneConfig } from "./config-loader.js";
|
|
11
12
|
import { freezeConfig, normalizeBase, resolveDeployAdapter, workerName } from "./config-freeze.js";
|
|
12
13
|
import { generateContent } from "./content-freeze.js";
|
|
@@ -17,6 +18,7 @@ import { buildRsc, findRscRoutes } from "./rsc-build.js";
|
|
|
17
18
|
import { existsSync, lstatSync } from "node:fs";
|
|
18
19
|
import { copyFile, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
19
20
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
21
|
+
import { PRERENDER_ORIGIN } from "@junejs/core/document";
|
|
20
22
|
import { buildLinkHeader } from "@junejs/core/discovery";
|
|
21
23
|
import { localeHref } from "@junejs/core/i18n";
|
|
22
24
|
import { createHash } from "node:crypto";
|
|
@@ -287,6 +289,20 @@ ${doClass}`;
|
|
|
287
289
|
}
|
|
288
290
|
if (publicFiles.length) hasAssets = true;
|
|
289
291
|
}
|
|
292
|
+
const site = frozen.document.site;
|
|
293
|
+
if (resolveIcons(site, publicFileCheck(publicDir)).generate) {
|
|
294
|
+
const icons = await renderIcons({
|
|
295
|
+
site,
|
|
296
|
+
fetchFont: googleFontFetcher(join(appRoot, "node_modules", ".cache", "june", "fonts")),
|
|
297
|
+
warn: (msg) => console.warn(msg)
|
|
298
|
+
});
|
|
299
|
+
await mkdir(assetsDir, { recursive: true });
|
|
300
|
+
for (const file of GENERATED_ICONS) {
|
|
301
|
+
await writeFile(join(assetsDir, file), icons[file]);
|
|
302
|
+
publicFiles.push(file);
|
|
303
|
+
}
|
|
304
|
+
hasAssets = true;
|
|
305
|
+
}
|
|
290
306
|
const isStatic = adapter.capabilities.runtime === "static";
|
|
291
307
|
const i18n = frozen.i18n;
|
|
292
308
|
const prerenderOne = async (reqPath, def) => {
|
|
@@ -301,7 +317,7 @@ ${doClass}`;
|
|
|
301
317
|
if (def.md !== false) targets.push([mdReq, mdFile]);
|
|
302
318
|
if (typeof def.json === "function") targets.push([jsonReq, jsonFile]);
|
|
303
319
|
for (const [rp, file] of targets) {
|
|
304
|
-
const res = await worker.fetch(new Request(
|
|
320
|
+
const res = await worker.fetch(new Request(`${PRERENDER_ORIGIN}${rp}`));
|
|
305
321
|
if (!res.ok) throw new Error(`prerender ${rp} → ${res.status}`);
|
|
306
322
|
const dest = join(assetsDir, file);
|
|
307
323
|
await mkdir(dirname(dest), { recursive: true });
|
|
@@ -326,15 +342,16 @@ ${doClass}`;
|
|
|
326
342
|
}
|
|
327
343
|
for (const [reqPath, file] of [
|
|
328
344
|
["/favicon.svg", "favicon.svg"],
|
|
345
|
+
["/manifest.webmanifest", "manifest.webmanifest"],
|
|
329
346
|
["/llms.txt", "llms.txt"],
|
|
330
347
|
["/sitemap.xml", "sitemap.xml"]
|
|
331
348
|
]) {
|
|
332
|
-
const res = await worker.fetch(new Request(
|
|
349
|
+
const res = await worker.fetch(new Request(`${PRERENDER_ORIGIN}${reqPath}`));
|
|
333
350
|
if (!res.ok) continue;
|
|
334
351
|
await writeFile(join(assetsDir, file), Buffer.from(await res.arrayBuffer()));
|
|
335
352
|
hasAssets = true;
|
|
336
353
|
}
|
|
337
|
-
const nf = await worker.fetch(new Request(
|
|
354
|
+
const nf = await worker.fetch(new Request(`${PRERENDER_ORIGIN}/__june_not_found__`));
|
|
338
355
|
await writeFile(join(assetsDir, "404.html"), Buffer.from(await nf.arrayBuffer()));
|
|
339
356
|
hasAssets = true;
|
|
340
357
|
}
|
package/dist/config-freeze.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { deno, staticSite, vercel, workers } from "./adapter.js";
|
|
2
2
|
import { CLIENT_SCRIPT_URL, findClientEntry } from "./client-bundle.js";
|
|
3
3
|
import { STYLES_URL, findGlobalCss, globalCssUsesTailwind } from "./css.js";
|
|
4
|
+
import { publicFileCheck, resolveIcons } from "./favicon.js";
|
|
4
5
|
import { loadJuneConfig } from "./config-loader.js";
|
|
5
6
|
import { join } from "node:path";
|
|
6
|
-
import { resolveAgent, resolveClientRouter, resolveSpeculationRules } from "@junejs/core/config";
|
|
7
|
+
import { deployOrigin, resolveAgent, resolveClientRouter, resolveSpeculationRules } from "@junejs/core/config";
|
|
7
8
|
//#region src/config-freeze.ts
|
|
8
9
|
function resolveDeployAdapter(deploy) {
|
|
9
10
|
if (deploy?.adapter) return deploy.adapter;
|
|
@@ -24,6 +25,7 @@ async function freezeConfig(appRoot) {
|
|
|
24
25
|
return {
|
|
25
26
|
document: {
|
|
26
27
|
site: cfg.site ?? {},
|
|
28
|
+
deployOrigin: deployOrigin(cfg),
|
|
27
29
|
speculationRules: resolveSpeculationRules(cfg.speculation ?? void 0),
|
|
28
30
|
speculationDelivery: "inline",
|
|
29
31
|
viewTransitions: cfg.viewTransitions ?? true,
|
|
@@ -31,7 +33,8 @@ async function freezeConfig(appRoot) {
|
|
|
31
33
|
clientRouter: resolveClientRouter(cfg.clientRouter),
|
|
32
34
|
clientScript: hasClient ? CLIENT_SCRIPT_URL : null,
|
|
33
35
|
styles: hasCss ? STYLES_URL : null,
|
|
34
|
-
basePath: normalizeBase(cfg.basePath)
|
|
36
|
+
basePath: normalizeBase(cfg.basePath),
|
|
37
|
+
icons: resolveIcons(cfg.site ?? {}, publicFileCheck(join(appRoot, "public"))).icons
|
|
35
38
|
},
|
|
36
39
|
agent: resolveAgent(cfg.agent),
|
|
37
40
|
i18n: cfg.i18n,
|
package/dist/content.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { ContentSource } from "@junejs/core/config";
|
|
2
2
|
//#region src/content.d.ts
|
|
3
|
+
type Heading = {
|
|
4
|
+
depth: number;
|
|
5
|
+
text: string;
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
declare function headingIds(html: string): {
|
|
9
|
+
html: string;
|
|
10
|
+
headings: Heading[];
|
|
11
|
+
};
|
|
3
12
|
type ContentEntry = {
|
|
4
13
|
slug: string;
|
|
5
14
|
file: string;
|
|
@@ -9,8 +18,13 @@ type ContentEntry = {
|
|
|
9
18
|
body: string;
|
|
10
19
|
/** The authored file, verbatim — the agent-facing .md projection. */
|
|
11
20
|
original: string;
|
|
12
|
-
/** The body rendered to HTML (CommonMark + GFM, via @momiji-rs/sparkdown/gfm wasm).
|
|
21
|
+
/** The body rendered to HTML (CommonMark + GFM, via @momiji-rs/sparkdown/gfm wasm).
|
|
22
|
+
* Every heading carries a GitHub-compatible `id` (see @junejs/core/slug) and nothing
|
|
23
|
+
* else — no injected links or classes; how an anchor looks is the app's call. */
|
|
13
24
|
html: string;
|
|
25
|
+
/** The headings of `html`, in document order: their depth (1–6), plain text, and the
|
|
26
|
+
* `id` each carries in `html` — for a table of contents, or a structured projection. */
|
|
27
|
+
headings: Heading[];
|
|
14
28
|
/** The locale this entry was authored in — set for files under a `<locale>/`
|
|
15
29
|
* subdir, undefined for the flat (default-locale) files. */
|
|
16
30
|
locale?: string;
|
|
@@ -36,4 +50,4 @@ declare function generateContentModule(contentDir: string, knownLocales?: readon
|
|
|
36
50
|
names: string[];
|
|
37
51
|
};
|
|
38
52
|
//#endregion
|
|
39
|
-
export { ContentEntry, ScannedCollection, collection, entry, generateContentModule, scanCollection };
|
|
53
|
+
export { ContentEntry, Heading, ScannedCollection, collection, entry, generateContentModule, headingIds, scanCollection };
|
package/dist/content.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { initSync, toHtmlSync } from "@momiji-rs/sparkdown/gfm";
|
|
4
|
+
import { createSlugger } from "@junejs/core/slug";
|
|
4
5
|
//#region src/content.ts
|
|
5
6
|
let wasmReady = false;
|
|
6
7
|
const ensureWasm = () => {
|
|
@@ -9,6 +10,42 @@ const ensureWasm = () => {
|
|
|
9
10
|
wasmReady = true;
|
|
10
11
|
}
|
|
11
12
|
};
|
|
13
|
+
const NAMED = {
|
|
14
|
+
amp: "&",
|
|
15
|
+
lt: "<",
|
|
16
|
+
gt: ">",
|
|
17
|
+
quot: "\"",
|
|
18
|
+
apos: "'"
|
|
19
|
+
};
|
|
20
|
+
const decodeEntities = (s) => s.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e) => e[0] === "#" ? String.fromCodePoint(e[1] === "x" || e[1] === "X" ? parseInt(e.slice(2), 16) : Number(e.slice(1))) : NAMED[e.toLowerCase()] ?? m);
|
|
21
|
+
const ID_ATTR = /\sid\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
|
|
22
|
+
function headingIds(html) {
|
|
23
|
+
const slug = createSlugger();
|
|
24
|
+
const taken = /* @__PURE__ */ new Set();
|
|
25
|
+
for (const m of html.matchAll(new RegExp(ID_ATTR.source, "gi"))) taken.add(m[1] ?? m[2]);
|
|
26
|
+
const headings = [];
|
|
27
|
+
return {
|
|
28
|
+
html: html.replace(/<h([1-6])(\s[^>]*)?>([\s\S]*?)<\/h\1>/gi, (_m, depth, attrs, inner) => {
|
|
29
|
+
const text = decodeEntities(inner.replace(/<[^>]*>/g, "")).trim();
|
|
30
|
+
const own = attrs ? ID_ATTR.exec(attrs) : null;
|
|
31
|
+
const authored = own ? own[1] ?? own[2] : void 0;
|
|
32
|
+
let id = authored;
|
|
33
|
+
if (!id) {
|
|
34
|
+
do
|
|
35
|
+
id = slug(text);
|
|
36
|
+
while (taken.has(id));
|
|
37
|
+
taken.add(id);
|
|
38
|
+
}
|
|
39
|
+
headings.push({
|
|
40
|
+
depth: Number(depth),
|
|
41
|
+
text,
|
|
42
|
+
id
|
|
43
|
+
});
|
|
44
|
+
return authored ? _m : `<h${depth}${(attrs ?? "").replace(ID_ATTR, "")} id="${id}">${inner}</h${depth}>`;
|
|
45
|
+
}),
|
|
46
|
+
headings
|
|
47
|
+
};
|
|
48
|
+
}
|
|
12
49
|
function parseFrontmatter(raw) {
|
|
13
50
|
if (!raw.startsWith("---")) return {
|
|
14
51
|
data: {},
|
|
@@ -48,13 +85,15 @@ function loadEntry(file, slug, locale) {
|
|
|
48
85
|
if (h1?.[1]) data.title = h1[1];
|
|
49
86
|
}
|
|
50
87
|
ensureWasm();
|
|
88
|
+
const { html, headings } = headingIds(toHtmlSync(body));
|
|
51
89
|
const entry = {
|
|
52
90
|
slug,
|
|
53
91
|
file,
|
|
54
92
|
data,
|
|
55
93
|
body,
|
|
56
94
|
original,
|
|
57
|
-
html
|
|
95
|
+
html,
|
|
96
|
+
headings,
|
|
58
97
|
...locale ? { locale } : {}
|
|
59
98
|
};
|
|
60
99
|
memo.set(key, {
|
|
@@ -160,6 +199,7 @@ function generateContentModule(contentDir, knownLocales, sources) {
|
|
|
160
199
|
body: e.body,
|
|
161
200
|
original: e.original,
|
|
162
201
|
html: e.html,
|
|
202
|
+
headings: e.headings,
|
|
163
203
|
...e.locale ? { locale: e.locale } : {}
|
|
164
204
|
});
|
|
165
205
|
const collections = /* @__PURE__ */ new Map();
|
|
@@ -193,9 +233,9 @@ function generateContentModule(contentDir, knownLocales, sources) {
|
|
|
193
233
|
names.push(name);
|
|
194
234
|
}
|
|
195
235
|
return {
|
|
196
|
-
code: "// AUTO-GENERATED by `june build` — edit content/**/*.md, not this file.\n" + (anyLocale ? "export type ContentEntry = { slug: string; data: Record<string, string | string[]>; body: string; original: string; html: string; locale?: string };\n" : "export type ContentEntry = { slug: string; data: Record<string, string | string[]>; body: string; original: string; html: string };\n") + body,
|
|
236
|
+
code: "// AUTO-GENERATED by `june build` — edit content/**/*.md, not this file.\n" + (anyLocale ? "export type ContentEntry = { slug: string; data: Record<string, string | string[]>; body: string; original: string; html: string; headings: Array<{ depth: number; text: string; id: string }>; locale?: string };\n" : "export type ContentEntry = { slug: string; data: Record<string, string | string[]>; body: string; original: string; html: string; headings: Array<{ depth: number; text: string; id: string }> };\n") + body,
|
|
197
237
|
names
|
|
198
238
|
};
|
|
199
239
|
}
|
|
200
240
|
//#endregion
|
|
201
|
-
export { collection, entry, generateContentModule, scanCollection };
|
|
241
|
+
export { collection, entry, generateContentModule, headingIds, scanCollection };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DocumentConfig } from "@junejs/core/document";
|
|
2
|
+
//#region src/favicon.d.ts
|
|
3
|
+
type Site = DocumentConfig["site"];
|
|
4
|
+
declare const ICON_BG = "#1d1d1f";
|
|
5
|
+
declare const ICON_FG = "#fbfbf8";
|
|
6
|
+
declare const GENERATED_ICONS: readonly ["apple-touch-icon.png", "icon.png", "favicon.ico", "icon-192.png", "icon-512.png"];
|
|
7
|
+
type GeneratedIconFile = (typeof GENERATED_ICONS)[number];
|
|
8
|
+
declare function publicFileCheck(publicDir: string): (file: string) => boolean;
|
|
9
|
+
declare function resolveIcons(site: Site, inPublic: (file: string) => boolean): {
|
|
10
|
+
generate: boolean;
|
|
11
|
+
icons: NonNullable<DocumentConfig["icons"]>;
|
|
12
|
+
};
|
|
13
|
+
declare function hanFamily(lang: string | undefined): string;
|
|
14
|
+
declare function iconFamily(ch: string, lang: string | undefined): string | null | undefined;
|
|
15
|
+
type FontFetcher = (family: string, text: string) => Promise<Uint8Array | null>;
|
|
16
|
+
declare function googleFontFetcher(cacheDir: string, opts?: {
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}): FontFetcher;
|
|
20
|
+
declare const INK_H = 28;
|
|
21
|
+
declare const INK_W = 40;
|
|
22
|
+
declare function pngToIco(png: Uint8Array, size: number): Uint8Array<ArrayBuffer>;
|
|
23
|
+
type GeneratedIcons = {
|
|
24
|
+
"apple-touch-icon.png": Uint8Array<ArrayBuffer>;
|
|
25
|
+
"icon.png": Uint8Array<ArrayBuffer>;
|
|
26
|
+
"favicon.ico": Uint8Array<ArrayBuffer>;
|
|
27
|
+
"icon-192.png": Uint8Array<ArrayBuffer>;
|
|
28
|
+
"icon-512.png": Uint8Array<ArrayBuffer>;
|
|
29
|
+
letter: string;
|
|
30
|
+
family: string | null;
|
|
31
|
+
};
|
|
32
|
+
declare function renderIcons(opts: {
|
|
33
|
+
site: Site;
|
|
34
|
+
fetchFont: FontFetcher;
|
|
35
|
+
warn?: (msg: string) => void;
|
|
36
|
+
}): Promise<GeneratedIcons>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { FontFetcher, GENERATED_ICONS, GeneratedIconFile, GeneratedIcons, ICON_BG, ICON_FG, INK_H, INK_W, googleFontFetcher, hanFamily, iconFamily, pngToIco, publicFileCheck, renderIcons, resolveIcons };
|
package/dist/favicon.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { iconLetter } from "./icon-letter.js";
|
|
2
|
+
import { existsSync, lstatSync } from "node:fs";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
//#region src/favicon.ts
|
|
8
|
+
const ICON_BG = "#1d1d1f";
|
|
9
|
+
const ICON_FG = "#fbfbf8";
|
|
10
|
+
const GENERATED_ICONS = [
|
|
11
|
+
"apple-touch-icon.png",
|
|
12
|
+
"icon.png",
|
|
13
|
+
"favicon.ico",
|
|
14
|
+
"icon-192.png",
|
|
15
|
+
"icon-512.png"
|
|
16
|
+
];
|
|
17
|
+
const PRIMARY_ICON_FILES = [
|
|
18
|
+
"favicon.svg",
|
|
19
|
+
"icon.svg",
|
|
20
|
+
"favicon.png",
|
|
21
|
+
"icon.png",
|
|
22
|
+
"favicon.ico"
|
|
23
|
+
];
|
|
24
|
+
const CUSTOM_ICON_FILES = [...PRIMARY_ICON_FILES, "apple-touch-icon.png"];
|
|
25
|
+
const MANIFEST_FILES = [
|
|
26
|
+
"manifest.webmanifest",
|
|
27
|
+
"manifest.json",
|
|
28
|
+
"site.webmanifest"
|
|
29
|
+
];
|
|
30
|
+
function publicFileCheck(publicDir) {
|
|
31
|
+
let real = false;
|
|
32
|
+
try {
|
|
33
|
+
real = lstatSync(publicDir).isDirectory();
|
|
34
|
+
} catch {}
|
|
35
|
+
return (file) => real && existsSync(join(publicDir, file));
|
|
36
|
+
}
|
|
37
|
+
function resolveIcons(site, inPublic) {
|
|
38
|
+
const ownManifest = MANIFEST_FILES.find(inPublic);
|
|
39
|
+
if (!(Boolean(site.icon) || CUSTOM_ICON_FILES.some(inPublic))) return {
|
|
40
|
+
generate: true,
|
|
41
|
+
icons: {
|
|
42
|
+
png: "/icon.png",
|
|
43
|
+
appleTouch: "/apple-touch-icon.png",
|
|
44
|
+
manifest: ownManifest ? `/${ownManifest}` : "/manifest.webmanifest",
|
|
45
|
+
generated: !ownManifest
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const primary = PRIMARY_ICON_FILES.find(inPublic);
|
|
49
|
+
return {
|
|
50
|
+
generate: false,
|
|
51
|
+
icons: {
|
|
52
|
+
primary: primary ? `/${primary}` : void 0,
|
|
53
|
+
png: inPublic("icon.png") ? "/icon.png" : void 0,
|
|
54
|
+
appleTouch: inPublic("apple-touch-icon.png") ? "/apple-touch-icon.png" : void 0,
|
|
55
|
+
manifest: ownManifest ? `/${ownManifest}` : void 0
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const is = (re) => (ch) => re.test(ch);
|
|
60
|
+
const isBundled = is(/^[\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}0-9•]/u);
|
|
61
|
+
const isEmoji = is(/^\p{Extended_Pictographic}/u);
|
|
62
|
+
const isKana = is(/^[\p{Script=Hiragana}\p{Script=Katakana}]/u);
|
|
63
|
+
const isHangul = is(/^\p{Script=Hangul}/u);
|
|
64
|
+
const isHan = is(/^\p{Script=Han}/u);
|
|
65
|
+
const NOTO_SCRIPT_RES = [
|
|
66
|
+
"Arabic",
|
|
67
|
+
"Armenian",
|
|
68
|
+
"Bengali",
|
|
69
|
+
"Devanagari",
|
|
70
|
+
"Ethiopic",
|
|
71
|
+
"Georgian",
|
|
72
|
+
"Gujarati",
|
|
73
|
+
"Gurmukhi",
|
|
74
|
+
"Hebrew",
|
|
75
|
+
"Kannada",
|
|
76
|
+
"Khmer",
|
|
77
|
+
"Lao",
|
|
78
|
+
"Malayalam",
|
|
79
|
+
"Myanmar",
|
|
80
|
+
"Sinhala",
|
|
81
|
+
"Tamil",
|
|
82
|
+
"Telugu",
|
|
83
|
+
"Thai"
|
|
84
|
+
].map((s) => [s, new RegExp(`^\\p{Script=${s}}`, "u")]);
|
|
85
|
+
function hanFamily(lang) {
|
|
86
|
+
let loc;
|
|
87
|
+
try {
|
|
88
|
+
loc = new Intl.Locale(lang || "und").maximize();
|
|
89
|
+
} catch {
|
|
90
|
+
return "Noto Sans SC";
|
|
91
|
+
}
|
|
92
|
+
if (loc.script === "Jpan") return "Noto Sans JP";
|
|
93
|
+
if (loc.script === "Kore") return "Noto Sans KR";
|
|
94
|
+
if (loc.script === "Hant") return loc.region === "HK" || loc.region === "MO" ? "Noto Sans HK" : "Noto Sans TC";
|
|
95
|
+
return "Noto Sans SC";
|
|
96
|
+
}
|
|
97
|
+
function iconFamily(ch, lang) {
|
|
98
|
+
if (!ch) return void 0;
|
|
99
|
+
if (isBundled(ch)) return null;
|
|
100
|
+
if (isEmoji(ch)) return "Noto Emoji";
|
|
101
|
+
if (isKana(ch)) return "Noto Sans JP";
|
|
102
|
+
if (isHangul(ch)) return "Noto Sans KR";
|
|
103
|
+
if (isHan(ch)) return hanFamily(lang);
|
|
104
|
+
const script = NOTO_SCRIPT_RES.find(([, re]) => re.test(ch))?.[0];
|
|
105
|
+
return script ? `Noto Sans ${script}` : void 0;
|
|
106
|
+
}
|
|
107
|
+
const LEGACY_UA = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1";
|
|
108
|
+
function googleFontFetcher(cacheDir, opts = {}) {
|
|
109
|
+
const doFetch = opts.fetch ?? fetch;
|
|
110
|
+
const timeoutMs = opts.timeoutMs ?? 3e3;
|
|
111
|
+
return async (family, text) => {
|
|
112
|
+
const cssUrl = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(family)}:wght@600&text=${encodeURIComponent(text)}`;
|
|
113
|
+
const file = join(cacheDir, createHash("sha256").update(cssUrl).digest("hex").slice(0, 32) + ".ttf");
|
|
114
|
+
try {
|
|
115
|
+
return new Uint8Array(await readFile(file));
|
|
116
|
+
} catch {}
|
|
117
|
+
try {
|
|
118
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
119
|
+
const cssRes = await doFetch(cssUrl, {
|
|
120
|
+
headers: { "User-Agent": LEGACY_UA },
|
|
121
|
+
signal
|
|
122
|
+
});
|
|
123
|
+
if (!cssRes.ok) return null;
|
|
124
|
+
const url = (await cssRes.text()).match(/src: url\((.+?)\)/)?.[1];
|
|
125
|
+
if (!url) return null;
|
|
126
|
+
const fontRes = await doFetch(url, { signal });
|
|
127
|
+
if (!fontRes.ok) return null;
|
|
128
|
+
const bytes = new Uint8Array(await fontRes.arrayBuffer());
|
|
129
|
+
await mkdir(cacheDir, { recursive: true });
|
|
130
|
+
await writeFile(file, bytes);
|
|
131
|
+
return bytes;
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
let resvgReady;
|
|
138
|
+
function loadResvg() {
|
|
139
|
+
return resvgReady ??= (async () => {
|
|
140
|
+
const mod = await import("@resvg/resvg-wasm");
|
|
141
|
+
const wasmPath = createRequire(import.meta.url).resolve("@resvg/resvg-wasm/index_bg.wasm");
|
|
142
|
+
await mod.initWasm(await readFile(wasmPath));
|
|
143
|
+
return mod;
|
|
144
|
+
})();
|
|
145
|
+
}
|
|
146
|
+
let bundledFont;
|
|
147
|
+
const loadBundledFont = () => bundledFont ??= readFile(new URL("../assets/icon-latin.ttf", import.meta.url)).then((b) => new Uint8Array(b));
|
|
148
|
+
const BUNDLED_FAMILY = "Inter";
|
|
149
|
+
const escapeXml = (s) => s.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
150
|
+
const PROBE = 1e3;
|
|
151
|
+
const INK_H = 28;
|
|
152
|
+
const INK_W = 40;
|
|
153
|
+
function inkBox(resvg, ch, family, font) {
|
|
154
|
+
const probe = `<svg xmlns="http://www.w3.org/2000/svg" width="${PROBE}" height="${PROBE}"><text x="${PROBE / 2}" y="${PROBE * .7}" font-family="${family}" font-size="${PROBE * .6}">${escapeXml(ch)}</text></svg>`;
|
|
155
|
+
const r = new resvg.Resvg(probe, { font: {
|
|
156
|
+
fontBuffers: [font],
|
|
157
|
+
loadSystemFonts: false,
|
|
158
|
+
defaultFontFamily: family
|
|
159
|
+
} });
|
|
160
|
+
const bbox = r.getBBox();
|
|
161
|
+
const box = bbox && bbox.width > 0 && bbox.height > 0 ? {
|
|
162
|
+
x: bbox.x,
|
|
163
|
+
y: bbox.y,
|
|
164
|
+
width: bbox.width,
|
|
165
|
+
height: bbox.height
|
|
166
|
+
} : null;
|
|
167
|
+
bbox?.free();
|
|
168
|
+
r.free();
|
|
169
|
+
return box;
|
|
170
|
+
}
|
|
171
|
+
const NOTDEF_PROBE = "";
|
|
172
|
+
function place(resvg, ch, family, font) {
|
|
173
|
+
const bbox = inkBox(resvg, ch, family, font);
|
|
174
|
+
if (!bbox) return null;
|
|
175
|
+
const notdef = inkBox(resvg, NOTDEF_PROBE, family, font);
|
|
176
|
+
if (notdef && notdef.x === bbox.x && notdef.y === bbox.y && notdef.width === bbox.width && notdef.height === bbox.height) return null;
|
|
177
|
+
const scale = Math.min(28 / bbox.height, 40 / bbox.width);
|
|
178
|
+
const cx = bbox.x + bbox.width / 2 - PROBE / 2;
|
|
179
|
+
const cy = bbox.y + bbox.height / 2 - PROBE * .7;
|
|
180
|
+
return {
|
|
181
|
+
family,
|
|
182
|
+
font,
|
|
183
|
+
size: PROBE * .6 * scale,
|
|
184
|
+
x: 32 - cx * scale,
|
|
185
|
+
y: 32 - cy * scale
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function iconSvg(ch, p, rounded) {
|
|
189
|
+
const glyph = p ? `<text x="${p.x.toFixed(2)}" y="${p.y.toFixed(2)}" font-family="${p.family}" font-size="${p.size.toFixed(2)}" fill="${ICON_FG}">${escapeXml(ch)}</text>` : "";
|
|
190
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><rect width="64" height="64"${rounded ? ` rx="12"` : ""} fill="${ICON_BG}"/>${glyph}</svg>`;
|
|
191
|
+
}
|
|
192
|
+
function pngToIco(png, size) {
|
|
193
|
+
const out = new Uint8Array(22 + png.length);
|
|
194
|
+
const v = new DataView(out.buffer);
|
|
195
|
+
v.setUint16(2, 1, true);
|
|
196
|
+
v.setUint16(4, 1, true);
|
|
197
|
+
out[6] = size >= 256 ? 0 : size;
|
|
198
|
+
out[7] = size >= 256 ? 0 : size;
|
|
199
|
+
v.setUint16(10, 1, true);
|
|
200
|
+
v.setUint16(12, 32, true);
|
|
201
|
+
v.setUint32(14, png.length, true);
|
|
202
|
+
v.setUint32(18, 22, true);
|
|
203
|
+
out.set(png, 22);
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
async function renderIcons(opts) {
|
|
207
|
+
const resvg = await loadResvg();
|
|
208
|
+
const ch = iconLetter(opts.site.name);
|
|
209
|
+
const family = iconFamily(ch, opts.site.lang);
|
|
210
|
+
let placement = null;
|
|
211
|
+
if (family === null) placement = place(resvg, ch, BUNDLED_FAMILY, await loadBundledFont());
|
|
212
|
+
else if (family !== void 0) {
|
|
213
|
+
const font = await opts.fetchFont(family, ch);
|
|
214
|
+
if (font) placement = place(resvg, ch, family, font);
|
|
215
|
+
}
|
|
216
|
+
if (ch && !placement) opts.warn?.(`[june] default icon: no font for "${ch}"${family ? ` (${family} unavailable — offline?)` : ""}; drew the square without it. Set site.icon or add public/icon.png to use your own.`);
|
|
217
|
+
const fonts = placement ? [placement.font] : [];
|
|
218
|
+
const render = (size, rounded) => {
|
|
219
|
+
const r = new resvg.Resvg(iconSvg(ch, placement, rounded), {
|
|
220
|
+
fitTo: {
|
|
221
|
+
mode: "width",
|
|
222
|
+
value: size
|
|
223
|
+
},
|
|
224
|
+
font: {
|
|
225
|
+
fontBuffers: fonts,
|
|
226
|
+
loadSystemFonts: false,
|
|
227
|
+
defaultFontFamily: placement?.family ?? BUNDLED_FAMILY
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const image = r.render();
|
|
231
|
+
const png = image.asPng();
|
|
232
|
+
image.free();
|
|
233
|
+
r.free();
|
|
234
|
+
return png;
|
|
235
|
+
};
|
|
236
|
+
const icon32 = render(32, true);
|
|
237
|
+
return {
|
|
238
|
+
"apple-touch-icon.png": render(180, false),
|
|
239
|
+
"icon.png": icon32,
|
|
240
|
+
"favicon.ico": pngToIco(icon32, 32),
|
|
241
|
+
"icon-192.png": render(192, false),
|
|
242
|
+
"icon-512.png": render(512, false),
|
|
243
|
+
letter: ch,
|
|
244
|
+
family: placement?.family ?? null
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
export { GENERATED_ICONS, ICON_BG, ICON_FG, INK_H, INK_W, googleFontFetcher, hanFamily, iconFamily, pngToIco, publicFileCheck, renderIcons, resolveIcons };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/icon-letter.ts
|
|
2
|
+
function iconLetter(name) {
|
|
3
|
+
const trimmed = (name ?? "").trim();
|
|
4
|
+
if (!trimmed) return "";
|
|
5
|
+
return (new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(trimmed)[Symbol.iterator]().next().value?.segment ?? "").toUpperCase();
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { iconLetter };
|