@risinghq/folio 0.0.0-stage → 0.0.1
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 +21 -0
- package/README.md +45 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +123 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +147 -0
- package/dist/highlight.d.ts +2 -0
- package/dist/highlight.js +82 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/layout.d.ts +39 -0
- package/dist/layout.js +203 -0
- package/dist/manual.d.ts +11 -0
- package/dist/manual.js +23 -0
- package/dist/markdown.d.ts +43 -0
- package/dist/markdown.js +144 -0
- package/dist/og.d.ts +19 -0
- package/dist/og.js +94 -0
- package/dist/options.d.ts +67 -0
- package/dist/options.js +50 -0
- package/dist/plugin.d.ts +20 -0
- package/dist/plugin.js +255 -0
- package/dist/site.d.ts +14 -0
- package/dist/site.js +53 -0
- package/package.json +74 -4
- package/theme/base.css +66 -0
- package/theme/components/code-block.css +53 -0
- package/theme/components/doc.css +61 -0
- package/theme/components/footer.css +18 -0
- package/theme/components/header.css +89 -0
- package/theme/components/home.css +14 -0
- package/theme/components/not-found.css +13 -0
- package/theme/components/pager.css +39 -0
- package/theme/components/prose.css +104 -0
- package/theme/components/sidebar.css +173 -0
- package/theme/components/toc.css +102 -0
- package/theme/controls.css +110 -0
- package/theme/fonts.css +24 -0
- package/theme/index.css +14 -0
- package/theme/tokens.css +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Duran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# folio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
folio builds a documentation site from a repository's `docs/` folder. Each
|
|
4
|
+
manual page becomes static HTML, and a page can mount a Solid island for a live
|
|
5
|
+
demo. Its own manual is built with it:
|
|
6
|
+
[folio.rising.sh](https://folio.rising.sh).
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bun add -d @risinghq/folio
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
bunx folio init # docs/README.md, docs/index.md and the docs:* scripts
|
|
20
|
+
bun run docs:dev # serve the site while editing
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`docs/README.md` orders the pages in its first list:
|
|
24
|
+
|
|
25
|
+
```md
|
|
26
|
+
- [Getting started](getting-started.md)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The title, version and GitHub link come from `package.json`.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- One static HTML page per manual page, numbered in the index's order.
|
|
34
|
+
- A home page from `docs/index.md`, and images served from the docs folder.
|
|
35
|
+
- Solid islands placed with `<!-- island NAME -->`, mounted as they near the
|
|
36
|
+
viewport.
|
|
37
|
+
- Shiki-highlighted code blocks with a copy button.
|
|
38
|
+
- A table of contents from each page's `##` and `###` headings.
|
|
39
|
+
- Links between `.md` pages become routes; other `.md` links open on GitHub.
|
|
40
|
+
- Light and dark themes; the choice persists across pages.
|
|
41
|
+
- A Vite plugin, `folio()`, for a project with its own Vite config.
|
|
42
|
+
|
|
43
|
+
## Links
|
|
44
|
+
|
|
45
|
+
- [Manual](https://folio.rising.sh/docs/getting-started)
|
|
46
|
+
- [Development and releases](docs/development.md)
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { build, createServer, preview } from "vite";
|
|
6
|
+
import { folio, readPackage } from "./plugin.js";
|
|
7
|
+
/** Where `folio build` writes the site; kept apart from a package's own `dist`. */
|
|
8
|
+
const outDir = ".folio";
|
|
9
|
+
const usage = `Usage: folio <command> [--base PATH] [--port N] [--host]
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
init Add a docs folder and the docs:* scripts to package.json
|
|
13
|
+
dev Serve the site while editing
|
|
14
|
+
build Write the static site to ${outDir}/
|
|
15
|
+
preview Serve the built site
|
|
16
|
+
|
|
17
|
+
folio reads its options from the "folio" field of package.json. A project
|
|
18
|
+
with its own Vite config adds folio() to its plugins and runs vite instead.`;
|
|
19
|
+
function viteConfig(root, base) {
|
|
20
|
+
return {
|
|
21
|
+
root,
|
|
22
|
+
base,
|
|
23
|
+
configFile: false,
|
|
24
|
+
publicDir: false,
|
|
25
|
+
plugins: [folio()],
|
|
26
|
+
build: { outDir, emptyOutDir: true },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function starterFiles(name, description) {
|
|
30
|
+
return {
|
|
31
|
+
"docs/README.md": `# ${name} manual\n\n- [Getting started](getting-started.md)\n`,
|
|
32
|
+
"docs/index.md": `# ${name}\n\n${description || `What ${name} does, in one line.`}\n\n[Get started](getting-started.md)\n`,
|
|
33
|
+
"docs/getting-started.md": `# Getting started\n\nThe first page of the manual. \`docs/README.md\` lists the pages in order.\n`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const scripts = {
|
|
37
|
+
"docs:dev": "folio dev",
|
|
38
|
+
"docs:build": "folio build",
|
|
39
|
+
"docs:preview": "folio preview",
|
|
40
|
+
};
|
|
41
|
+
/** Writes each starter file and script that does not exist yet, and says what it wrote. */
|
|
42
|
+
function init(root) {
|
|
43
|
+
const pkgPath = join(root, "package.json");
|
|
44
|
+
if (!existsSync(pkgPath)) {
|
|
45
|
+
throw new Error("folio init: no package.json here. Run it in a package.");
|
|
46
|
+
}
|
|
47
|
+
const pkg = readPackage(root);
|
|
48
|
+
const name = pkg.name?.replace(/^@[^/]+\//, "") ?? "Docs";
|
|
49
|
+
for (const [file, content] of Object.entries(starterFiles(name, pkg.description ?? ""))) {
|
|
50
|
+
const path = join(root, file);
|
|
51
|
+
if (existsSync(path))
|
|
52
|
+
continue;
|
|
53
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
54
|
+
writeFileSync(path, content);
|
|
55
|
+
console.log(`created ${file}`);
|
|
56
|
+
}
|
|
57
|
+
const raw = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
58
|
+
const missing = Object.entries(scripts).filter(([key]) => !raw.scripts?.[key]);
|
|
59
|
+
if (missing.length > 0) {
|
|
60
|
+
raw.scripts = { ...raw.scripts, ...Object.fromEntries(missing) };
|
|
61
|
+
writeFileSync(pkgPath, `${JSON.stringify(raw, null, 2)}\n`);
|
|
62
|
+
console.log(`added ${missing.map(([key]) => key).join(", ")} to package.json`);
|
|
63
|
+
}
|
|
64
|
+
const ignore = join(root, ".gitignore");
|
|
65
|
+
if (existsSync(ignore)) {
|
|
66
|
+
const lines = readFileSync(ignore, "utf8").split("\n");
|
|
67
|
+
if (!lines.some((line) => line.trim().replace(/^\/|\/$/g, "") === outDir)) {
|
|
68
|
+
writeFileSync(ignore, `${lines.join("\n").replace(/\n*$/, "\n")}${outDir}\n`);
|
|
69
|
+
console.log(`added ${outDir} to .gitignore`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log("\nRun the docs:dev script to see the site.");
|
|
73
|
+
}
|
|
74
|
+
async function main(argv) {
|
|
75
|
+
const { positionals, values } = parseArgs({
|
|
76
|
+
args: argv,
|
|
77
|
+
allowPositionals: true,
|
|
78
|
+
options: {
|
|
79
|
+
port: { type: "string" },
|
|
80
|
+
base: { type: "string" },
|
|
81
|
+
host: { type: "boolean" },
|
|
82
|
+
help: { type: "boolean", short: "h" },
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const [command] = positionals;
|
|
86
|
+
const root = process.cwd();
|
|
87
|
+
const config = viteConfig(root, values.base);
|
|
88
|
+
const server = {
|
|
89
|
+
port: values.port === undefined ? undefined : Number(values.port),
|
|
90
|
+
host: values.host,
|
|
91
|
+
};
|
|
92
|
+
if (values.help || command === undefined) {
|
|
93
|
+
console.log(usage);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
switch (command) {
|
|
97
|
+
case "init":
|
|
98
|
+
return init(root);
|
|
99
|
+
case "dev": {
|
|
100
|
+
const dev = await createServer({ ...config, server });
|
|
101
|
+
await dev.listen();
|
|
102
|
+
dev.printUrls();
|
|
103
|
+
dev.bindCLIShortcuts({ print: true });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
case "build":
|
|
107
|
+
await build(config);
|
|
108
|
+
console.log(`\nWrote the site to ${outDir}/`);
|
|
109
|
+
return;
|
|
110
|
+
case "preview": {
|
|
111
|
+
const served = await preview({ ...config, preview: server });
|
|
112
|
+
served.printUrls();
|
|
113
|
+
served.bindCLIShortcuts({ print: true });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
throw new Error(`folio: unknown command "${command}"\n\n${usage}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
121
|
+
console.error(error instanceof Error ? error.message : error);
|
|
122
|
+
process.exitCode = 1;
|
|
123
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Component } from "solid-js";
|
|
2
|
+
/** Maps an island name to a loader of the module whose default export it mounts. */
|
|
3
|
+
export type Islands = Record<string, () => Promise<{
|
|
4
|
+
default: Component;
|
|
5
|
+
}>>;
|
|
6
|
+
export declare function start(islands: Islands): void;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { render } from "@solidjs/web";
|
|
2
|
+
import { createComponent } from "solid-js";
|
|
3
|
+
const themeKey = "folio-theme";
|
|
4
|
+
async function copy(button, code) {
|
|
5
|
+
await navigator.clipboard.writeText(code);
|
|
6
|
+
button.textContent = "Copied";
|
|
7
|
+
setTimeout(() => (button.textContent = "Copy"), 1500);
|
|
8
|
+
}
|
|
9
|
+
function setupCopy() {
|
|
10
|
+
document.addEventListener("click", (event) => {
|
|
11
|
+
const button = event.target.closest("figure.code .copy");
|
|
12
|
+
const code = button?.closest("figure")?.querySelector("pre")?.textContent;
|
|
13
|
+
if (!button || code == null)
|
|
14
|
+
return;
|
|
15
|
+
void copy(button, code);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function setupTheme() {
|
|
19
|
+
const root = document.documentElement;
|
|
20
|
+
// A prerendered page read the theme on hover; the reader may have switched it since.
|
|
21
|
+
document.addEventListener("prerenderingchange", () => {
|
|
22
|
+
try {
|
|
23
|
+
const stored = localStorage.getItem(themeKey);
|
|
24
|
+
if (stored === "light" || stored === "dark")
|
|
25
|
+
root.dataset.theme = stored;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Storage is off; keep the theme the page started with.
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
for (const button of document.querySelectorAll(".theme-toggle")) {
|
|
32
|
+
button.addEventListener("click", () => {
|
|
33
|
+
const next = root.dataset.theme === "dark" ? "light" : "dark";
|
|
34
|
+
root.dataset.theme = next;
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(themeKey, next);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Storage is off in private modes; the choice lasts this page.
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function setupMenu() {
|
|
45
|
+
const button = document.querySelector(".menu-button");
|
|
46
|
+
const sidebar = document.getElementById("sidebar");
|
|
47
|
+
if (!button || !sidebar)
|
|
48
|
+
return;
|
|
49
|
+
const set = (open) => {
|
|
50
|
+
button.setAttribute("aria-expanded", String(open));
|
|
51
|
+
document.body.classList.toggle("menu-open", open);
|
|
52
|
+
};
|
|
53
|
+
button.addEventListener("click", () => set(button.getAttribute("aria-expanded") !== "true"));
|
|
54
|
+
sidebar.addEventListener("click", (event) => {
|
|
55
|
+
if (event.target.closest("a, .menu-close"))
|
|
56
|
+
set(false);
|
|
57
|
+
});
|
|
58
|
+
document.querySelector(".scrim")?.addEventListener("click", () => set(false));
|
|
59
|
+
document.addEventListener("keydown", (event) => {
|
|
60
|
+
if (event.key === "Escape")
|
|
61
|
+
set(false);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** Prefetches a same-site page on hover where speculation rules do not prerender it. */
|
|
65
|
+
function setupPrefetch() {
|
|
66
|
+
if (HTMLScriptElement.supports?.("speculationrules"))
|
|
67
|
+
return;
|
|
68
|
+
const fetched = new Set([location.pathname]);
|
|
69
|
+
document.addEventListener("pointerover", (event) => {
|
|
70
|
+
const link = event.target.closest?.("a[href]");
|
|
71
|
+
if (!link || link.origin !== location.origin)
|
|
72
|
+
return;
|
|
73
|
+
if (fetched.has(link.pathname))
|
|
74
|
+
return;
|
|
75
|
+
fetched.add(link.pathname);
|
|
76
|
+
const hint = document.createElement("link");
|
|
77
|
+
hint.rel = "prefetch";
|
|
78
|
+
hint.href = link.pathname;
|
|
79
|
+
document.head.append(hint);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Marks the TOC link of the last heading that has scrolled past the top band. */
|
|
83
|
+
function setupScrollSpy() {
|
|
84
|
+
const links = new Map();
|
|
85
|
+
for (const link of document.querySelectorAll(".toc a[href^='#']")) {
|
|
86
|
+
links.set(decodeURIComponent(link.hash.slice(1)), link);
|
|
87
|
+
}
|
|
88
|
+
const headings = [...links.keys()]
|
|
89
|
+
.map((id) => document.getElementById(id))
|
|
90
|
+
.filter((el) => el !== null);
|
|
91
|
+
if (headings.length === 0)
|
|
92
|
+
return;
|
|
93
|
+
const update = () => {
|
|
94
|
+
const line = window.innerHeight * 0.25;
|
|
95
|
+
let current = headings[0];
|
|
96
|
+
for (const heading of headings) {
|
|
97
|
+
if (heading.getBoundingClientRect().top <= line)
|
|
98
|
+
current = heading;
|
|
99
|
+
}
|
|
100
|
+
for (const [id, link] of links) {
|
|
101
|
+
if (id === current?.id)
|
|
102
|
+
link.setAttribute("aria-current", "location");
|
|
103
|
+
else
|
|
104
|
+
link.removeAttribute("aria-current");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
let frame = 0;
|
|
108
|
+
window.addEventListener("scroll", () => {
|
|
109
|
+
cancelAnimationFrame(frame);
|
|
110
|
+
frame = requestAnimationFrame(update);
|
|
111
|
+
}, { passive: true });
|
|
112
|
+
update();
|
|
113
|
+
}
|
|
114
|
+
async function mount(el, islands) {
|
|
115
|
+
const name = el.dataset.island ?? "";
|
|
116
|
+
const load = islands[name];
|
|
117
|
+
if (!load) {
|
|
118
|
+
console.error(`folio: no island named "${name}"`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const { default: island } = await load();
|
|
122
|
+
el.replaceChildren();
|
|
123
|
+
render(() => createComponent(island, {}), el);
|
|
124
|
+
el.dataset.mounted = "";
|
|
125
|
+
}
|
|
126
|
+
/** Mounts each island as it nears the viewport. */
|
|
127
|
+
function setupIslands(islands) {
|
|
128
|
+
const observer = new IntersectionObserver((entries) => {
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
if (!entry.isIntersecting)
|
|
131
|
+
continue;
|
|
132
|
+
observer.unobserve(entry.target);
|
|
133
|
+
void mount(entry.target, islands);
|
|
134
|
+
}
|
|
135
|
+
}, { rootMargin: "400px 0px" });
|
|
136
|
+
for (const el of document.querySelectorAll("[data-island]")) {
|
|
137
|
+
observer.observe(el);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function start(islands) {
|
|
141
|
+
setupCopy();
|
|
142
|
+
setupTheme();
|
|
143
|
+
setupMenu();
|
|
144
|
+
setupPrefetch();
|
|
145
|
+
setupScrollSpy();
|
|
146
|
+
setupIslands(islands);
|
|
147
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import css from "@shikijs/langs/css";
|
|
2
|
+
import json from "@shikijs/langs/json";
|
|
3
|
+
import shellscript from "@shikijs/langs/shellscript";
|
|
4
|
+
import tsx from "@shikijs/langs/tsx";
|
|
5
|
+
import { createHighlighterCoreSync } from "shiki/core";
|
|
6
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
7
|
+
const theme = {
|
|
8
|
+
name: "folio",
|
|
9
|
+
type: "light",
|
|
10
|
+
colors: { "editor.foreground": "var(--code-fg)" },
|
|
11
|
+
settings: [
|
|
12
|
+
{ settings: { foreground: "var(--code-fg)" } },
|
|
13
|
+
{
|
|
14
|
+
scope: ["comment", "punctuation.definition.comment"],
|
|
15
|
+
settings: { foreground: "var(--code-comment)" },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
scope: ["punctuation", "meta.brace", "keyword.operator"],
|
|
19
|
+
settings: { foreground: "var(--code-punct)" },
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
scope: [
|
|
23
|
+
"keyword",
|
|
24
|
+
"storage",
|
|
25
|
+
"keyword.control",
|
|
26
|
+
"constant.language",
|
|
27
|
+
"variable.language",
|
|
28
|
+
],
|
|
29
|
+
settings: { foreground: "var(--code-keyword)" },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
scope: ["string", "punctuation.definition.string"],
|
|
33
|
+
settings: { foreground: "var(--code-string)" },
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
scope: ["constant.numeric", "keyword.other.unit"],
|
|
37
|
+
settings: { foreground: "var(--code-number)" },
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
scope: [
|
|
41
|
+
"entity.name.function",
|
|
42
|
+
"support.function",
|
|
43
|
+
"meta.function-call entity.name.function",
|
|
44
|
+
],
|
|
45
|
+
settings: { foreground: "var(--code-fn)" },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
scope: [
|
|
49
|
+
"entity.name.tag",
|
|
50
|
+
"support.class.component",
|
|
51
|
+
"entity.name.type",
|
|
52
|
+
"support.type",
|
|
53
|
+
],
|
|
54
|
+
settings: { foreground: "var(--code-tag)" },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
scope: ["entity.other.attribute-name", "support.type.property-name"],
|
|
58
|
+
settings: { foreground: "var(--code-attr)" },
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const highlighter = createHighlighterCoreSync({
|
|
63
|
+
themes: [theme],
|
|
64
|
+
langs: [...tsx, ...css, ...json, ...shellscript],
|
|
65
|
+
engine: createJavaScriptRegexEngine(),
|
|
66
|
+
});
|
|
67
|
+
const aliases = {
|
|
68
|
+
ts: "tsx",
|
|
69
|
+
typescript: "tsx",
|
|
70
|
+
js: "tsx",
|
|
71
|
+
sh: "shellscript",
|
|
72
|
+
bash: "shellscript",
|
|
73
|
+
};
|
|
74
|
+
/** Highlighted `<pre>` markup. Unknown languages render as plain text. */
|
|
75
|
+
export function highlight(code, lang) {
|
|
76
|
+
const resolved = aliases[lang] ?? lang;
|
|
77
|
+
const known = highlighter.getLoadedLanguages().includes(resolved);
|
|
78
|
+
return highlighter.codeToHtml(code, {
|
|
79
|
+
lang: known ? resolved : "text",
|
|
80
|
+
theme: "folio",
|
|
81
|
+
});
|
|
82
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PageEntry } from "./manual.ts";
|
|
2
|
+
import { type RenderedPage } from "./markdown.ts";
|
|
3
|
+
import type { ResolvedOptions } from "./options.ts";
|
|
4
|
+
/** The routes of one site, under Vite's `base`. */
|
|
5
|
+
export interface Routes {
|
|
6
|
+
home: string;
|
|
7
|
+
page: (slug: string) => string;
|
|
8
|
+
/** A file of the docs folder, such as an image. */
|
|
9
|
+
file: (path: string) => string;
|
|
10
|
+
/** A page's social card, or the home page's with no slug. */
|
|
11
|
+
card: (slug?: string) => string;
|
|
12
|
+
/** A path as a full URL, or none when the site's address is unknown. */
|
|
13
|
+
absolute: (path: string) => string | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare function routesFor(base: string, url?: string): Routes;
|
|
16
|
+
/** What a built page links to: Vite's script and style tags for the client entry. */
|
|
17
|
+
export interface Assets {
|
|
18
|
+
head: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ManualPageInput {
|
|
21
|
+
options: ResolvedOptions;
|
|
22
|
+
routes: Routes;
|
|
23
|
+
pages: PageEntry[];
|
|
24
|
+
slug: string;
|
|
25
|
+
page: RenderedPage;
|
|
26
|
+
assets: Assets;
|
|
27
|
+
}
|
|
28
|
+
export declare function manualPage(input: ManualPageInput): string;
|
|
29
|
+
export interface HomePageInput {
|
|
30
|
+
options: ResolvedOptions;
|
|
31
|
+
routes: Routes;
|
|
32
|
+
pages: PageEntry[];
|
|
33
|
+
assets: Assets;
|
|
34
|
+
}
|
|
35
|
+
/** The home page: the docs folder's `index.md`, or a link to the manual. */
|
|
36
|
+
export declare function homePage(input: HomePageInput & {
|
|
37
|
+
home?: RenderedPage;
|
|
38
|
+
}): string;
|
|
39
|
+
export declare function notFoundPage(input: HomePageInput): string;
|