hyperbook 0.23.1 → 0.23.2
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/dist/index.js +1 -1
- package/dist/templates/default/.hyperbook/package.json +7 -7
- package/dist/templates/default/.hyperbook/src/pages/[[...page]].js +57 -1
- package/dist/templates/default/.hyperbook/src/pages/_app.js +126 -1
- package/dist/templates/default/.hyperbook/src/pages/_document.js +11 -1
- package/dist/templates/default/.hyperbook/src/pages/api/save.js +39 -1
- package/dist/templates/default/.hyperbook/src/pages/glossary/[...term].js +59 -1
- package/dist/templates/default/.hyperbook/src/pages/glossary/index.js +28 -1
- package/dist/templates/default/.hyperbook/src/useScrollHash.js +14 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforms/web",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"gray-matter": "4.0.3",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"redux": "4.2.1",
|
|
12
12
|
"redux-persist": "6.0.0",
|
|
13
13
|
"@hyperbook/drawer": "0.1.1",
|
|
14
|
-
"@hyperbook/element-audio": "0.2.0",
|
|
15
14
|
"@hyperbook/element-alert": "0.2.0",
|
|
15
|
+
"@hyperbook/element-audio": "0.2.0",
|
|
16
16
|
"@hyperbook/element-bitflow": "0.2.0",
|
|
17
17
|
"@hyperbook/element-bookmarks": "0.3.0",
|
|
18
18
|
"@hyperbook/element-collapsible": "0.4.0",
|
|
19
19
|
"@hyperbook/element-dl": "0.2.0",
|
|
20
20
|
"@hyperbook/element-embed": "0.2.0",
|
|
21
|
-
"@hyperbook/element-excalidraw": "0.5.
|
|
22
|
-
"@hyperbook/element-mermaid": "0.2.
|
|
21
|
+
"@hyperbook/element-excalidraw": "0.5.1",
|
|
22
|
+
"@hyperbook/element-mermaid": "0.2.1",
|
|
23
23
|
"@hyperbook/element-online-ide": "0.4.0",
|
|
24
24
|
"@hyperbook/element-plantuml": "0.2.0",
|
|
25
25
|
"@hyperbook/element-protect": "0.4.0",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"@hyperbook/element-term": "0.2.0",
|
|
32
32
|
"@hyperbook/element-youtube": "0.2.0",
|
|
33
33
|
"@hyperbook/fs": "0.10.0",
|
|
34
|
-
"@hyperbook/markdown": "0.9.
|
|
34
|
+
"@hyperbook/markdown": "0.9.2",
|
|
35
35
|
"@hyperbook/provider": "0.4.0",
|
|
36
|
-
"@hyperbook/shell": "0.7.
|
|
36
|
+
"@hyperbook/shell": "0.7.2",
|
|
37
37
|
"@hyperbook/store": "0.2.0",
|
|
38
38
|
"@hyperbook/styles": "0.3.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@hyperbook/next-watch": "0.5.
|
|
41
|
+
"@hyperbook/next-watch": "0.5.1"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"next:dev": "next-hyperbook-watch",
|
|
@@ -1 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Shell } from "@hyperbook/shell";
|
|
3
|
+
import { Markdown } from "@hyperbook/markdown";
|
|
4
|
+
import { useActivePageId, useLink } from "@hyperbook/provider";
|
|
5
|
+
import { Fragment } from "react";
|
|
6
|
+
import { vfile, hyperbook } from "@hyperbook/fs";
|
|
7
|
+
import { useScrollHash } from "../useScrollHash";
|
|
8
|
+
import path from "path";
|
|
9
|
+
function BookPage({ markdown, data, navigation }) {
|
|
10
|
+
const Link = useLink();
|
|
11
|
+
useActivePageId();
|
|
12
|
+
useScrollHash();
|
|
13
|
+
return /* @__PURE__ */ React.createElement(Fragment, null, /* @__PURE__ */ React.createElement(Shell, { navigation }, /* @__PURE__ */ React.createElement("article", null, /* @__PURE__ */ React.createElement(Markdown, { children: markdown, showToc: data.toc !== false })), !data.hide && /* @__PURE__ */ React.createElement("div", { className: "jump-container" }, navigation.previous ? /* @__PURE__ */ React.createElement(Link, { className: "jump previous", href: navigation.previous.href }, navigation.previous.name) : /* @__PURE__ */ React.createElement("div", { className: "flex" }), navigation.next ? /* @__PURE__ */ React.createElement(Link, { className: "jump next", href: navigation.next.href }, navigation.next.name) : /* @__PURE__ */ React.createElement("div", { className: "flex" }))));
|
|
14
|
+
}
|
|
15
|
+
const getStaticProps = async ({ params }) => {
|
|
16
|
+
const root = process.env.root ?? process.cwd();
|
|
17
|
+
let href = "";
|
|
18
|
+
if (params.page) {
|
|
19
|
+
href = path.join(...params.page);
|
|
20
|
+
}
|
|
21
|
+
const file = await vfile.get(root, "book", "/" + href);
|
|
22
|
+
const { content, data } = await vfile.getMarkdown(file);
|
|
23
|
+
const hyperbookJson = await hyperbook.getJson(root);
|
|
24
|
+
const navigation = await hyperbook.getNavigation(root, file);
|
|
25
|
+
return {
|
|
26
|
+
props: {
|
|
27
|
+
locale: data?.lang || hyperbookJson.language,
|
|
28
|
+
markdown: content,
|
|
29
|
+
data,
|
|
30
|
+
navigation
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const getStaticPaths = async () => {
|
|
35
|
+
const root = process.env.root ?? process.cwd();
|
|
36
|
+
const files = await vfile.listForFolder(root, "book");
|
|
37
|
+
const paths = files.map((f) => {
|
|
38
|
+
const page = f.path.href.slice(1).split("/");
|
|
39
|
+
if (f.name === "index" && f.path.directory === "") {
|
|
40
|
+
page.pop();
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
params: {
|
|
44
|
+
page
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
paths,
|
|
50
|
+
fallback: false
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
BookPage as default,
|
|
55
|
+
getStaticPaths,
|
|
56
|
+
getStaticProps
|
|
57
|
+
};
|
|
@@ -1 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import "../index.css";
|
|
3
|
+
import "@hyperbook/shell/index.css";
|
|
4
|
+
import "@hyperbook/drawer/index.css";
|
|
5
|
+
import "@hyperbook/markdown/katex.css";
|
|
6
|
+
import "@hyperbook/markdown/index.css";
|
|
7
|
+
import { Provider } from "@hyperbook/provider";
|
|
8
|
+
import elementTab from "@hyperbook/element-tabs";
|
|
9
|
+
import "@hyperbook/element-tabs/index.css";
|
|
10
|
+
import elementAudio from "@hyperbook/element-audio";
|
|
11
|
+
import "@hyperbook/element-audio/index.css";
|
|
12
|
+
import elementAlert from "@hyperbook/element-alert";
|
|
13
|
+
import "@hyperbook/element-alert/index.css";
|
|
14
|
+
import elementTerm from "@hyperbook/element-term";
|
|
15
|
+
import "@hyperbook/element-term/index.css";
|
|
16
|
+
import elementYoutube from "@hyperbook/element-youtube";
|
|
17
|
+
import "@hyperbook/element-youtube/index.css";
|
|
18
|
+
import elementPlantuml from "@hyperbook/element-plantuml";
|
|
19
|
+
import "@hyperbook/element-plantuml/index.css";
|
|
20
|
+
import elementProtect from "@hyperbook/element-protect";
|
|
21
|
+
import "@hyperbook/element-protect/index.css";
|
|
22
|
+
import elementCollapsible from "@hyperbook/element-collapsible";
|
|
23
|
+
import "@hyperbook/element-collapsible/index.css";
|
|
24
|
+
import elementDl from "@hyperbook/element-dl";
|
|
25
|
+
import "@hyperbook/element-dl/index.css";
|
|
26
|
+
import elementBookmarks from "@hyperbook/element-bookmarks";
|
|
27
|
+
import "@hyperbook/element-bookmarks/index.css";
|
|
28
|
+
import elementStruktog from "@hyperbook/element-struktog";
|
|
29
|
+
import "@hyperbook/element-struktog/index.css";
|
|
30
|
+
import elementQr from "@hyperbook/element-qr";
|
|
31
|
+
import "@hyperbook/element-qr/index.css";
|
|
32
|
+
import elementMermaid from "@hyperbook/element-mermaid";
|
|
33
|
+
import "@hyperbook/element-mermaid/index.css";
|
|
34
|
+
import elementExcalidraw from "@hyperbook/element-excalidraw";
|
|
35
|
+
import "@hyperbook/element-excalidraw/index.css";
|
|
36
|
+
import elementEmbed from "@hyperbook/element-embed";
|
|
37
|
+
import "@hyperbook/element-embed/index.css";
|
|
38
|
+
import elementOnlineIde from "@hyperbook/element-online-ide";
|
|
39
|
+
import "@hyperbook/element-online-ide/index.css";
|
|
40
|
+
import elementSqlIde from "@hyperbook/element-sql-ide";
|
|
41
|
+
import "@hyperbook/element-sql-ide/index.css";
|
|
42
|
+
import elementBitflow from "@hyperbook/element-bitflow";
|
|
43
|
+
import "@hyperbook/element-bitflow/index.css";
|
|
44
|
+
import elementScratchblock from "@hyperbook/element-scratchblock";
|
|
45
|
+
import "@hyperbook/element-scratchblock/index.css";
|
|
46
|
+
import Link from "next/link";
|
|
47
|
+
import Head from "next/head";
|
|
48
|
+
import { Styles } from "@hyperbook/styles";
|
|
49
|
+
import { localStorage, noopStorage } from "@hyperbook/store";
|
|
50
|
+
import { useRouter } from "next/router";
|
|
51
|
+
import { useEffect } from "react";
|
|
52
|
+
import hb from "../../hyperbook.json";
|
|
53
|
+
const MyLink = ({ ref, href, children, ...props }) => {
|
|
54
|
+
return /* @__PURE__ */ React.createElement(Link, { href, ...props }, children);
|
|
55
|
+
};
|
|
56
|
+
const makeUrl = ({ basePath }) => (path) => {
|
|
57
|
+
if (process.env.NODE_ENV === "production" && basePath && path?.startsWith("/")) {
|
|
58
|
+
if (basePath.endsWith("/")) {
|
|
59
|
+
path = basePath.slice(0, -1) + path;
|
|
60
|
+
} else {
|
|
61
|
+
path = basePath + path;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return path;
|
|
65
|
+
};
|
|
66
|
+
function MyApp({ Component, pageProps }) {
|
|
67
|
+
const router = useRouter();
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
document.documentElement.lang = pageProps.locale;
|
|
70
|
+
}, [pageProps.locale]);
|
|
71
|
+
return /* @__PURE__ */ React.createElement(
|
|
72
|
+
Provider,
|
|
73
|
+
{
|
|
74
|
+
Link: MyLink,
|
|
75
|
+
Head,
|
|
76
|
+
config: hb,
|
|
77
|
+
makeUrl,
|
|
78
|
+
env: process.env.NODE_ENV === "production" ? "production" : "development",
|
|
79
|
+
elements: [
|
|
80
|
+
elementTab,
|
|
81
|
+
elementAudio,
|
|
82
|
+
elementAlert,
|
|
83
|
+
elementTerm,
|
|
84
|
+
elementYoutube,
|
|
85
|
+
elementCollapsible,
|
|
86
|
+
elementPlantuml,
|
|
87
|
+
elementProtect,
|
|
88
|
+
elementDl,
|
|
89
|
+
elementEmbed,
|
|
90
|
+
elementBookmarks,
|
|
91
|
+
elementStruktog,
|
|
92
|
+
elementOnlineIde,
|
|
93
|
+
elementSqlIde,
|
|
94
|
+
elementQr,
|
|
95
|
+
elementMermaid,
|
|
96
|
+
elementExcalidraw,
|
|
97
|
+
elementScratchblock,
|
|
98
|
+
elementBitflow
|
|
99
|
+
],
|
|
100
|
+
router,
|
|
101
|
+
storage: typeof window !== "undefined" ? localStorage : noopStorage,
|
|
102
|
+
loadFile: () => async (path) => {
|
|
103
|
+
return fetch(path).then((res) => res.text());
|
|
104
|
+
},
|
|
105
|
+
saveFile: () => async (path, content, rootFolder) => {
|
|
106
|
+
await fetch("/api/save", {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: {
|
|
109
|
+
"Content-Type": "application/json"
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
path,
|
|
113
|
+
content,
|
|
114
|
+
rootFolder
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
getActivePageId: async () => router.asPath.split("#")?.[0] || "/"
|
|
119
|
+
},
|
|
120
|
+
/* @__PURE__ */ React.createElement(Styles, null),
|
|
121
|
+
/* @__PURE__ */ React.createElement(Component, { ...pageProps })
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
MyApp as default
|
|
126
|
+
};
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Document, { Html, Head, Main, NextScript } from "next/document";
|
|
3
|
+
class MyDocument extends Document {
|
|
4
|
+
render() {
|
|
5
|
+
return /* @__PURE__ */ React.createElement(Html, { lang: this.props.__NEXT_DATA__.props.pageProps.locale }, /* @__PURE__ */ React.createElement(Head, null), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement(Main, null), /* @__PURE__ */ React.createElement(NextScript, null)));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
var document_default = MyDocument;
|
|
9
|
+
export {
|
|
10
|
+
document_default as default
|
|
11
|
+
};
|
|
@@ -1 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
async function ensureDirectoryExistence(filePath) {
|
|
4
|
+
var dirname = path.dirname(filePath);
|
|
5
|
+
try {
|
|
6
|
+
await fs.access(dirname);
|
|
7
|
+
return true;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
fs.mkdir(dirname).then(async () => ensureDirectoryExistence(dirname));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const config = {
|
|
13
|
+
api: {
|
|
14
|
+
bodyParser: {
|
|
15
|
+
sizeLimit: "32mb"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
async function handler(req, res) {
|
|
20
|
+
if (process.env.NODE_ENV !== "development") {
|
|
21
|
+
res.status(404).json({ status: "failed" });
|
|
22
|
+
}
|
|
23
|
+
let { path: p, content, rootFolder } = req.body;
|
|
24
|
+
if (rootFolder) {
|
|
25
|
+
p = path.join(rootFolder, p);
|
|
26
|
+
}
|
|
27
|
+
p = path.join(__dirname, "..", "..", "..", "..", p);
|
|
28
|
+
try {
|
|
29
|
+
await ensureDirectoryExistence(p);
|
|
30
|
+
await fs.writeFile(p, content);
|
|
31
|
+
res.status(202).json({ status: "saved" });
|
|
32
|
+
} catch (e) {
|
|
33
|
+
res.status(400).json(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
config,
|
|
38
|
+
handler as default
|
|
39
|
+
};
|
|
@@ -1 +1,59 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Shell } from "@hyperbook/shell";
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { useActivePageId, useLink } from "@hyperbook/provider";
|
|
5
|
+
import { Markdown } from "@hyperbook/markdown";
|
|
6
|
+
import { hyperbook, vfile } from "@hyperbook/fs";
|
|
7
|
+
import { useScrollHash } from "../../useScrollHash";
|
|
8
|
+
function Term({
|
|
9
|
+
markdown,
|
|
10
|
+
navigation,
|
|
11
|
+
data,
|
|
12
|
+
references
|
|
13
|
+
}) {
|
|
14
|
+
const Link = useLink();
|
|
15
|
+
useActivePageId();
|
|
16
|
+
useScrollHash();
|
|
17
|
+
return /* @__PURE__ */ React.createElement(Shell, { navigation }, /* @__PURE__ */ React.createElement("article", null, /* @__PURE__ */ React.createElement(Markdown, { children: markdown, showToc: data.toc !== false }), /* @__PURE__ */ React.createElement("div", { className: "pages" }, references.map((p, i) => /* @__PURE__ */ React.createElement(Fragment, { key: p.path.href }, i > 0 && ", ", /* @__PURE__ */ React.createElement(Link, { href: p.path.href }, p.markdown?.data?.name ?? p.name))))));
|
|
18
|
+
}
|
|
19
|
+
const getStaticProps = async ({ params }) => {
|
|
20
|
+
const root = process.env.root ?? process.cwd();
|
|
21
|
+
const file = await vfile.get(
|
|
22
|
+
root,
|
|
23
|
+
"glossary",
|
|
24
|
+
"/glossary/" + params.term.join("/")
|
|
25
|
+
);
|
|
26
|
+
if (!file) {
|
|
27
|
+
throw Error(`Missing file ${file}`);
|
|
28
|
+
}
|
|
29
|
+
const { content, data } = await vfile.getMarkdown(file);
|
|
30
|
+
const hyperbookJson = await hyperbook.getJson(root);
|
|
31
|
+
const navigation = await hyperbook.getNavigation(root, file);
|
|
32
|
+
return {
|
|
33
|
+
props: {
|
|
34
|
+
locale: data?.lang || hyperbookJson.language,
|
|
35
|
+
markdown: content,
|
|
36
|
+
data,
|
|
37
|
+
references: file.references,
|
|
38
|
+
navigation
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const getStaticPaths = async () => {
|
|
43
|
+
const root = process.env.root ?? process.cwd();
|
|
44
|
+
const files = await vfile.listForFolder(root, "glossary");
|
|
45
|
+
const paths = files.map((f) => ({
|
|
46
|
+
params: {
|
|
47
|
+
term: f.path.href.slice(10).split("/")
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
paths,
|
|
52
|
+
fallback: false
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
Term as default,
|
|
57
|
+
getStaticPaths,
|
|
58
|
+
getStaticProps
|
|
59
|
+
};
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Shell } from "@hyperbook/shell";
|
|
3
|
+
import { useActivePageId, useLink } from "@hyperbook/provider";
|
|
4
|
+
import { hyperbook, vfile } from "@hyperbook/fs";
|
|
5
|
+
import { useScrollHash } from "../../useScrollHash";
|
|
6
|
+
function Glossary({ glossary, navigation }) {
|
|
7
|
+
const Link = useLink();
|
|
8
|
+
useActivePageId();
|
|
9
|
+
useScrollHash();
|
|
10
|
+
return /* @__PURE__ */ React.createElement(Shell, { navigation }, /* @__PURE__ */ React.createElement("article", { className: "glossary" }, Object.keys(glossary).map((letter) => /* @__PURE__ */ React.createElement("div", { key: letter, className: "container" }, /* @__PURE__ */ React.createElement("div", { className: "letter" }, letter), /* @__PURE__ */ React.createElement("ul", { className: "terms" }, glossary[letter].map((term) => /* @__PURE__ */ React.createElement("li", { key: term.href }, /* @__PURE__ */ React.createElement(Link, { className: "term", href: term.href }, term.name))))))));
|
|
11
|
+
}
|
|
12
|
+
const getStaticProps = async () => {
|
|
13
|
+
const root = process.env.root ?? process.cwd();
|
|
14
|
+
const glossaryData = await vfile.getGlossary(root);
|
|
15
|
+
const hyperbookJson = await hyperbook.getJson(root);
|
|
16
|
+
const navigation = await hyperbook.getNavigation(root);
|
|
17
|
+
return {
|
|
18
|
+
props: {
|
|
19
|
+
locale: hyperbookJson.language,
|
|
20
|
+
glossary: glossaryData,
|
|
21
|
+
navigation
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
Glossary as default,
|
|
27
|
+
getStaticProps
|
|
28
|
+
};
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import{useEffect
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const useScrollHash = () => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
const hash = window.location.hash;
|
|
5
|
+
if (hash) {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
document.querySelector(hash)?.scrollIntoView({ behavior: "smooth" });
|
|
8
|
+
}, 100);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
useScrollHash
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyperbook",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
4
4
|
"author": "Mike Barkmin",
|
|
5
5
|
"homepage": "https://github.com/openpatch/hyperbook#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"rimraf": "3.0.2",
|
|
45
45
|
"tar": "6.1.14",
|
|
46
46
|
"update-check": "1.5.4",
|
|
47
|
-
"@platforms/web": "0.23.
|
|
47
|
+
"@platforms/web": "0.23.2"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@hyperbook/fs": "0.10.0",
|