docus 2.1.0 → 3.0.0-beta.11

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.
Files changed (282) hide show
  1. package/README.md +6 -4
  2. package/package.json +39 -83
  3. package/theme/app/router.options.ts +18 -0
  4. package/theme/assets/css/fonts.css +84 -0
  5. package/theme/assets/css/main.css +104 -0
  6. package/theme/components/app/Container.vue +25 -0
  7. package/theme/components/app/Footer.vue +40 -0
  8. package/theme/components/app/MobileNav.vue +85 -0
  9. package/theme/components/app/Navbar.vue +37 -0
  10. package/theme/components/app/NavbarLogo.vue +33 -0
  11. package/theme/components/app/Page.vue +7 -0
  12. package/theme/components/app/PoweredByDocus.vue +11 -0
  13. package/theme/components/content/Alert.vue +124 -0
  14. package/theme/components/content/BlockHero.vue +54 -0
  15. package/theme/components/content/ButtonLink.vue +45 -0
  16. package/theme/components/content/Card.vue +46 -0
  17. package/theme/components/content/CardGrid.vue +23 -0
  18. package/theme/components/content/CodeBlock.vue +47 -0
  19. package/theme/components/content/CodeGroup.vue +135 -0
  20. package/theme/components/content/CopyButton.vue +49 -0
  21. package/{dist/runtime/app/components/prose/ProseOl.vue → theme/components/content/List.vue} +2 -2
  22. package/theme/components/content/NeedContribution.vue +23 -0
  23. package/theme/components/content/ReadMore.vue +25 -0
  24. package/theme/components/content/Sandbox.vue +102 -0
  25. package/theme/components/content/TabsHeader.vue +44 -0
  26. package/theme/components/content/Terminal.vue +64 -0
  27. package/theme/components/content/VideoPlayer.vue +115 -0
  28. package/theme/components/dev/Debug.vue +65 -0
  29. package/theme/components/docs/DocsAside.vue +21 -0
  30. package/theme/components/docs/DocsAsideTree.vue +104 -0
  31. package/theme/components/docs/DocsHero.vue +39 -0
  32. package/theme/components/docs/DocsPage.vue +21 -0
  33. package/theme/components/docs/DocsPageContent.vue +32 -0
  34. package/theme/components/docs/DocsToc.vue +77 -0
  35. package/theme/components/globals/Icon.vue +24 -0
  36. package/{dist/runtime/app/components/prose/ProseHr.vue → theme/components/globals/Logo.vue} +1 -1
  37. package/theme/components/globals/NuxtImg.vue +45 -0
  38. package/theme/components/globals/SocialIcons.vue +45 -0
  39. package/theme/components/globals/ThemeSelect.vue +35 -0
  40. package/theme/components/icons/IconAlgolia.vue +8 -0
  41. package/theme/components/icons/IconArrowLeft.vue +10 -0
  42. package/theme/components/icons/IconArrowRight.vue +10 -0
  43. package/theme/components/icons/IconBadgeCheck.vue +14 -0
  44. package/theme/components/icons/IconCheck.vue +10 -0
  45. package/theme/components/icons/IconCheckCircle.vue +10 -0
  46. package/theme/components/icons/IconChevronRight.vue +12 -0
  47. package/theme/components/icons/IconClipboardCheck.vue +14 -0
  48. package/theme/components/icons/IconClipboardCopy.vue +14 -0
  49. package/theme/components/icons/IconCodeSandbox.vue +8 -0
  50. package/theme/components/icons/IconCopy.vue +17 -0
  51. package/theme/components/icons/IconDots.vue +10 -0
  52. package/theme/components/icons/IconEdit.vue +18 -0
  53. package/theme/components/icons/IconExclamationCircle.vue +12 -0
  54. package/theme/components/icons/IconExclamationTriangle.vue +10 -0
  55. package/theme/components/icons/IconExternalLink.vue +12 -0
  56. package/theme/components/icons/IconGit.vue +7 -0
  57. package/theme/components/icons/IconGitHub.vue +10 -0
  58. package/theme/components/icons/IconHeart.vue +9 -0
  59. package/theme/components/icons/IconInformationCircle.vue +10 -0
  60. package/theme/components/icons/IconLighthouse.vue +83 -0
  61. package/theme/components/icons/IconLine.vue +10 -0
  62. package/theme/components/icons/IconMarkdown.vue +13 -0
  63. package/theme/components/icons/IconMenu.vue +12 -0
  64. package/theme/components/icons/IconMenuAlt.vue +10 -0
  65. package/theme/components/icons/IconMinus.vue +10 -0
  66. package/theme/components/icons/IconMoon.vue +10 -0
  67. package/theme/components/icons/IconNuxt.vue +14 -0
  68. package/theme/components/icons/IconNuxtContent.vue +20 -0
  69. package/theme/components/icons/IconNuxtLabs.vue +21 -0
  70. package/theme/components/icons/IconPlus.vue +10 -0
  71. package/theme/components/icons/IconPuzzle.vue +8 -0
  72. package/theme/components/icons/IconSSG.vue +7 -0
  73. package/theme/components/icons/IconSearch.vue +12 -0
  74. package/theme/components/icons/IconSun.vue +10 -0
  75. package/theme/components/icons/IconTailwind.vue +3 -0
  76. package/theme/components/icons/IconTocBack.vue +21 -0
  77. package/theme/components/icons/IconTocCurrent.vue +21 -0
  78. package/theme/components/icons/IconTocNext.vue +8 -0
  79. package/theme/components/icons/IconTranslate.vue +14 -0
  80. package/theme/components/icons/IconTwitter.vue +8 -0
  81. package/theme/components/icons/IconVite.vue +30 -0
  82. package/theme/components/icons/IconVue.vue +6 -0
  83. package/theme/components/icons/IconVueTelescope.vue +11 -0
  84. package/theme/components/icons/IconWindi.vue +17 -0
  85. package/theme/components/icons/IconX.vue +12 -0
  86. package/theme/components/icons/IconXCircle.vue +10 -0
  87. package/theme/components/icons/IconZap.vue +8 -0
  88. package/theme/components/prose/ProseA.vue +66 -0
  89. package/theme/components/prose/ProseBlockquote.vue +21 -0
  90. package/theme/components/prose/ProseCode.vue +67 -0
  91. package/theme/components/prose/ProseCodeInline.vue +38 -0
  92. package/theme/components/prose/ProseEm.vue +11 -0
  93. package/theme/components/prose/ProseH1.vue +22 -0
  94. package/theme/components/prose/ProseH2.vue +22 -0
  95. package/theme/components/prose/ProseH3.vue +24 -0
  96. package/theme/components/prose/ProseH4.vue +24 -0
  97. package/theme/components/prose/ProseHr.vue +13 -0
  98. package/theme/components/prose/ProseImg.vue +30 -0
  99. package/theme/components/prose/ProseLi.vue +31 -0
  100. package/theme/components/prose/ProseOl.vue +16 -0
  101. package/theme/components/prose/ProseP.vue +14 -0
  102. package/theme/components/prose/ProseStrong.vue +14 -0
  103. package/theme/components/prose/ProseTable.vue +13 -0
  104. package/{dist/runtime/app → theme}/components/prose/ProseTbody.vue +0 -0
  105. package/theme/components/prose/ProseTd.vue +11 -0
  106. package/theme/components/prose/ProseTh.vue +11 -0
  107. package/theme/components/prose/ProseThead.vue +11 -0
  108. package/theme/components/prose/ProseTr.vue +11 -0
  109. package/theme/components/prose/ProseUl.vue +15 -0
  110. package/theme/composables/useDocus.ts +43 -0
  111. package/theme/composables/useMenu.ts +7 -0
  112. package/theme/composables/useScrollToHeading.ts +35 -0
  113. package/theme/composables/useScrollspy.ts +46 -0
  114. package/theme/composables/useUserAgent.ts +7 -0
  115. package/theme/composables/utils.ts +4 -0
  116. package/theme/layouts/default.vue +29 -0
  117. package/theme/layouts/page.vue +19 -0
  118. package/theme/middleware/components.ts +26 -0
  119. package/theme/middleware/navigation.global.ts +12 -0
  120. package/theme/middleware/page.ts +8 -0
  121. package/theme/middleware/theme.global.ts +12 -0
  122. package/theme/nuxt.config.ts +171 -0
  123. package/theme/pages/[...slug].vue +64 -0
  124. package/theme/plugins/menu.ts +67 -0
  125. package/theme/plugins/user-agent.ts +27 -0
  126. package/theme/utils/components.ts +25 -0
  127. package/theme/utils/navigation.ts +49 -0
  128. package/theme/utils/plugin.ts +21 -0
  129. package/theme/utils/queries.ts +68 -0
  130. package/theme/utils/state.ts +33 -0
  131. package/theme/utils/theme.ts +66 -0
  132. package/LICENSE +0 -21
  133. package/dist/index.cjs +0 -549
  134. package/dist/index.d.ts +0 -25
  135. package/dist/index.mjs +0 -523
  136. package/dist/runtime/app/components/DocusContent.vue +0 -215
  137. package/dist/runtime/app/components/DocusContent.vue.d.ts +0 -25
  138. package/dist/runtime/app/components/Error.vue +0 -19
  139. package/dist/runtime/app/components/Error.vue.d.ts +0 -9
  140. package/dist/runtime/app/components/Markdown.vue +0 -56
  141. package/dist/runtime/app/components/Markdown.vue.d.ts +0 -25
  142. package/dist/runtime/app/components/Page.vue +0 -29
  143. package/dist/runtime/app/components/Page.vue.d.ts +0 -2
  144. package/dist/runtime/app/components/Props.vue +0 -130
  145. package/dist/runtime/app/components/Props.vue.d.ts +0 -80
  146. package/dist/runtime/app/components/prose/ProseA.vue +0 -41
  147. package/dist/runtime/app/components/prose/ProseA.vue.d.ts +0 -23
  148. package/dist/runtime/app/components/prose/ProseBlockquote.vue +0 -5
  149. package/dist/runtime/app/components/prose/ProseCode.vue +0 -5
  150. package/dist/runtime/app/components/prose/ProseCodeInline.vue +0 -5
  151. package/dist/runtime/app/components/prose/ProseEm.vue +0 -5
  152. package/dist/runtime/app/components/prose/ProseH1.vue +0 -3
  153. package/dist/runtime/app/components/prose/ProseH2.vue +0 -3
  154. package/dist/runtime/app/components/prose/ProseH3.vue +0 -3
  155. package/dist/runtime/app/components/prose/ProseH4.vue +0 -3
  156. package/dist/runtime/app/components/prose/ProseH5.vue +0 -3
  157. package/dist/runtime/app/components/prose/ProseH6.vue +0 -3
  158. package/dist/runtime/app/components/prose/ProseImg.vue +0 -32
  159. package/dist/runtime/app/components/prose/ProseImg.vue.d.ts +0 -21
  160. package/dist/runtime/app/components/prose/ProseLi.vue +0 -3
  161. package/dist/runtime/app/components/prose/ProseParagraph.vue +0 -3
  162. package/dist/runtime/app/components/prose/ProseStrong.vue +0 -5
  163. package/dist/runtime/app/components/prose/ProseTable.vue +0 -5
  164. package/dist/runtime/app/components/prose/ProseTd.vue +0 -5
  165. package/dist/runtime/app/components/prose/ProseTh.vue +0 -5
  166. package/dist/runtime/app/components/prose/ProseThead.vue +0 -5
  167. package/dist/runtime/app/components/prose/ProseTr.vue +0 -5
  168. package/dist/runtime/app/components/prose/ProseUl.vue +0 -5
  169. package/dist/runtime/app/composables/helpers.d.ts +0 -4
  170. package/dist/runtime/app/composables/helpers.js +0 -66
  171. package/dist/runtime/app/composables/helpers.mjs +0 -40
  172. package/dist/runtime/app/composables/index.d.ts +0 -90
  173. package/dist/runtime/app/composables/index.js +0 -108
  174. package/dist/runtime/app/composables/index.mjs +0 -63
  175. package/dist/runtime/app/composables/navigation.d.ts +0 -37
  176. package/dist/runtime/app/composables/navigation.js +0 -227
  177. package/dist/runtime/app/composables/navigation.mjs +0 -148
  178. package/dist/runtime/app/composables/store.d.ts +0 -7
  179. package/dist/runtime/app/composables/store.js +0 -52
  180. package/dist/runtime/app/composables/store.mjs +0 -35
  181. package/dist/runtime/app/composables/style.d.ts +0 -11
  182. package/dist/runtime/app/composables/style.js +0 -117
  183. package/dist/runtime/app/composables/style.mjs +0 -71
  184. package/dist/runtime/app/composables/theme-colors.d.ts +0 -30
  185. package/dist/runtime/app/composables/theme-colors.js +0 -80
  186. package/dist/runtime/app/composables/theme-colors.mjs +0 -48
  187. package/dist/runtime/app/composables/websocket.d.ts +0 -3
  188. package/dist/runtime/app/composables/websocket.js +0 -79
  189. package/dist/runtime/app/composables/websocket.mjs +0 -63
  190. package/dist/runtime/app/layouts/default.vue +0 -5
  191. package/dist/runtime/app/layouts/error.vue +0 -33
  192. package/dist/runtime/app/layouts/error.vue.d.ts +0 -21
  193. package/dist/runtime/app/pages/_.vue +0 -222
  194. package/dist/runtime/app/pages/_.vue.d.ts +0 -2
  195. package/dist/runtime/context.d.ts +0 -1
  196. package/dist/runtime/context.js +0 -17
  197. package/dist/runtime/context.mjs +0 -5
  198. package/dist/runtime/database/Query.d.ts +0 -18
  199. package/dist/runtime/database/Query.js +0 -68
  200. package/dist/runtime/database/Query.mjs +0 -49
  201. package/dist/runtime/database/index.d.ts +0 -4
  202. package/dist/runtime/database/index.js +0 -45
  203. package/dist/runtime/database/index.mjs +0 -25
  204. package/dist/runtime/database/providers/local/Query.d.ts +0 -14
  205. package/dist/runtime/database/providers/local/Query.js +0 -85
  206. package/dist/runtime/database/providers/local/Query.mjs +0 -60
  207. package/dist/runtime/database/providers/local/index.d.ts +0 -3
  208. package/dist/runtime/database/providers/local/index.js +0 -63
  209. package/dist/runtime/database/providers/local/index.mjs +0 -39
  210. package/dist/runtime/database/providers/local/operations.d.ts +0 -2
  211. package/dist/runtime/database/providers/local/operations.js +0 -83
  212. package/dist/runtime/database/providers/local/operations.mjs +0 -53
  213. package/dist/runtime/database/providers/local/utils.d.ts +0 -8
  214. package/dist/runtime/database/providers/local/utils.js +0 -28
  215. package/dist/runtime/database/providers/local/utils.mjs +0 -17
  216. package/dist/runtime/index.d.ts +0 -3
  217. package/dist/runtime/index.js +0 -44
  218. package/dist/runtime/index.mjs +0 -3
  219. package/dist/runtime/navigation.d.ts +0 -4
  220. package/dist/runtime/navigation.js +0 -176
  221. package/dist/runtime/navigation.mjs +0 -137
  222. package/dist/runtime/server/api/get.d.ts +0 -10
  223. package/dist/runtime/server/api/get.js +0 -24
  224. package/dist/runtime/server/api/get.mjs +0 -13
  225. package/dist/runtime/server/api/list.d.ts +0 -9
  226. package/dist/runtime/server/api/list.js +0 -34
  227. package/dist/runtime/server/api/list.mjs +0 -18
  228. package/dist/runtime/server/api/navigation.d.ts +0 -7
  229. package/dist/runtime/server/api/navigation.js +0 -20
  230. package/dist/runtime/server/api/navigation.mjs +0 -10
  231. package/dist/runtime/server/api/preview.d.ts +0 -3
  232. package/dist/runtime/server/api/preview.js +0 -54
  233. package/dist/runtime/server/api/preview.mjs +0 -31
  234. package/dist/runtime/server/api/reload.d.ts +0 -6
  235. package/dist/runtime/server/api/reload.js +0 -27
  236. package/dist/runtime/server/api/reload.mjs +0 -11
  237. package/dist/runtime/server/api/search.d.ts +0 -6
  238. package/dist/runtime/server/api/search.js +0 -27
  239. package/dist/runtime/server/api/search.mjs +0 -13
  240. package/dist/runtime/server/content.d.ts +0 -46
  241. package/dist/runtime/server/content.js +0 -175
  242. package/dist/runtime/server/content.mjs +0 -114
  243. package/dist/runtime/server/socket.d.ts +0 -9
  244. package/dist/runtime/server/socket.js +0 -33
  245. package/dist/runtime/server/socket.mjs +0 -20
  246. package/dist/runtime/server/utils/cache.d.ts +0 -19
  247. package/dist/runtime/server/utils/cache.js +0 -110
  248. package/dist/runtime/server/utils/cache.mjs +0 -75
  249. package/dist/runtime/server/utils/index.d.ts +0 -4
  250. package/dist/runtime/server/utils/index.js +0 -18
  251. package/dist/runtime/server/utils/index.mjs +0 -8
  252. package/dist/runtime/transformers/index.d.ts +0 -1
  253. package/dist/runtime/transformers/index.js +0 -26
  254. package/dist/runtime/transformers/index.mjs +0 -11
  255. package/dist/runtime/transformers/json.d.ts +0 -3
  256. package/dist/runtime/transformers/json.js +0 -15
  257. package/dist/runtime/transformers/json.mjs +0 -5
  258. package/dist/runtime/transformers/markdown/index.d.ts +0 -8
  259. package/dist/runtime/transformers/markdown/index.js +0 -25
  260. package/dist/runtime/transformers/markdown/index.mjs +0 -16
  261. package/dist/runtime/transformers/utils/index.d.ts +0 -1
  262. package/dist/runtime/transformers/utils/index.js +0 -18
  263. package/dist/runtime/transformers/utils/index.mjs +0 -1
  264. package/dist/runtime/transformers/utils/path.d.ts +0 -26
  265. package/dist/runtime/transformers/utils/path.js +0 -88
  266. package/dist/runtime/transformers/utils/path.mjs +0 -56
  267. package/dist/runtime/utils/index.d.ts +0 -1
  268. package/dist/runtime/utils/index.js +0 -18
  269. package/dist/runtime/utils/index.mjs +0 -1
  270. package/dist/runtime/utils/log.d.ts +0 -1
  271. package/dist/runtime/utils/log.js +0 -14
  272. package/dist/runtime/utils/log.mjs +0 -2
  273. package/dist/runtime/utils/object.d.ts +0 -9
  274. package/dist/runtime/utils/object.js +0 -22
  275. package/dist/runtime/utils/object.mjs +0 -4
  276. package/dist/templates/content.mjs +0 -50
  277. package/dist/templates/docus.mjs +0 -13
  278. package/dist/templates/hot.mjs +0 -16
  279. package/dist/templates/i18n.mjs +0 -23
  280. package/dist/templates/options.mjs +0 -46
  281. package/shims.d.ts +0 -24
  282. package/types.d.ts +0 -397
@@ -1,46 +0,0 @@
1
- import type { Storage } from 'unstorage';
2
- import type { MDCRoot } from 'types';
3
- interface DocusContent {
4
- body: MDCRoot;
5
- meta: Record<string, any>;
6
- }
7
- export declare const contentStorage: Storage;
8
- export declare const buildStorage: Storage;
9
- export declare const previewStorage: Storage;
10
- /**
11
- * Read content form source file, generate and cache the content
12
- *
13
- * @param id Content ID
14
- * @param previewKey Preview id
15
- * @returns Transformed content
16
- */
17
- export declare function buildContent(id: string, previewKey?: string): Promise<DocusContent>;
18
- /**
19
- * Return transformed conntent if it exists in cache or build it on demand
20
- *
21
- * @param id Content ID
22
- * @param previewKey Preview ID
23
- * @returns Transformed content
24
- */
25
- export declare function getContent(id: string, previewKey?: string): Promise<DocusContent>;
26
- /**
27
- * Find list of contents
28
- *
29
- * @param id Base if for lookup
30
- * @param previewKey Preview ID
31
- * @returns List of content in given base path
32
- */
33
- export declare function getList(id?: string, previewKey?: string): Promise<{
34
- id: string;
35
- }[]>;
36
- /**
37
- * Search content database for a given query
38
- *
39
- * @param to Base path for search
40
- * @param body Search options
41
- * @param previewKey Preview ID
42
- * @returns Single content of list of contents that matchs the search
43
- */
44
- export declare function searchContent(to: string, body: any, previewKey?: string): Promise<any>;
45
- export declare const getNavigation: (previewKey?: string) => Promise<any>;
46
- export {};
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildContent = buildContent;
7
- exports.contentStorage = exports.buildStorage = void 0;
8
- exports.getContent = getContent;
9
- exports.getList = getList;
10
- exports.previewStorage = exports.getNavigation = void 0;
11
- exports.searchContent = searchContent;
12
-
13
- var _unstorage = require("unstorage");
14
-
15
- var _micromatch = _interopRequireDefault(require("micromatch"));
16
-
17
- var _transformers = require("../transformers");
18
-
19
- var _database = require("../database");
20
-
21
- var _navigation = require("../navigation");
22
-
23
- var _context = require("../context");
24
-
25
- var _cache = require("./utils/cache");
26
-
27
- var _storage = require("#storage");
28
-
29
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
- function prefixStorage(storage2, base) {
32
- const nsStorage = (0, _unstorage.prefixStorage)(storage2, base);
33
- const prefixRegex = new RegExp(`^${base}:`);
34
-
35
- nsStorage.getKeys = (id = "") => {
36
- return storage2.getKeys(base + ":" + id).then(keys => keys.map(key => key.replace(prefixRegex, "")));
37
- };
38
-
39
- return nsStorage;
40
- }
41
-
42
- const contentStorage = prefixStorage(_storage.storage, "docus:source");
43
- exports.contentStorage = contentStorage;
44
- const buildStorage = prefixStorage(_storage.storage, "assets:docus:build");
45
- exports.buildStorage = buildStorage;
46
- const previewStorage = prefixStorage(_storage.storage, "docus:preview");
47
- exports.previewStorage = previewStorage;
48
- const isProduction = process.env.NODE_ENV === "production";
49
-
50
- const withCache = (name, fn) => isProduction ? (0, _cache.cachify)(fn, {
51
- name,
52
- swr: true,
53
- ttl: 6e4,
54
- integrity: "docus"
55
- }) : fn;
56
-
57
- async function getData(id, previewKey) {
58
- let body;
59
- let meta;
60
-
61
- if (previewKey) {
62
- body = await previewStorage.getItem(`${previewKey}:${id}`);
63
- meta = await previewStorage.getMeta(`${previewKey}:${id}`);
64
- }
65
-
66
- if (!body) {
67
- body = await contentStorage.getItem(id);
68
- meta = await contentStorage.getMeta(id);
69
- }
70
-
71
- if (body && typeof body === "object") {
72
- body = JSON.stringify(typeof body.default !== "undefined" ? body.default : body);
73
- }
74
-
75
- if (typeof body !== "string") {
76
- body = body + "";
77
- }
78
-
79
- return {
80
- body,
81
- meta
82
- };
83
- }
84
-
85
- const getContentKeys = async id => {
86
- let keys = await buildStorage.getKeys(id);
87
-
88
- if (keys.length === 0) {
89
- keys = await contentStorage.getKeys(id);
90
- const context = (0, _context.useDocusContext)();
91
- keys = _micromatch.default.not(keys, context?.ignoreList || []);
92
- }
93
-
94
- return keys;
95
- };
96
-
97
- const getPreviewKeys = async (id, previewKey) => {
98
- let keys = (await previewStorage.getKeys(id ? `${previewKey}:${id}` : previewKey)).map(key => key.replace(`${previewKey}:`, ""));
99
- const context = (0, _context.useDocusContext)();
100
- keys = _micromatch.default.not(keys, context?.ignoreList || []);
101
- return keys;
102
- };
103
-
104
- async function getKeys(id, previewKey) {
105
- let keys = await getContentKeys(id);
106
-
107
- if (previewKey) {
108
- const previewKeys = await getPreviewKeys(id, previewKey);
109
- keys = keys.filter(key => !previewKeys.includes(key));
110
- keys.push(...previewKeys);
111
- }
112
-
113
- return keys;
114
- }
115
-
116
- async function buildContent(id, previewKey) {
117
- const data = await getData(id, previewKey);
118
-
119
- if (typeof data.body === "undefined" || data.body === null) {
120
- throw new Error(`Content not found: ${id}`);
121
- }
122
-
123
- const transformResult = await (0, _transformers.getTransformer)(id)(id, data.body);
124
- const content = {
125
- meta: { ...data.meta,
126
- ...transformResult.meta
127
- },
128
- body: transformResult.body
129
- };
130
-
131
- if (!previewKey) {
132
- await buildStorage.setItem(id, content);
133
- }
134
-
135
- return content;
136
- }
137
-
138
- async function getContent(id, previewKey) {
139
- let content = !previewKey && (await buildStorage.getItem(id));
140
-
141
- if (!content) {
142
- content = await buildContent(id, previewKey);
143
- }
144
-
145
- return content;
146
- }
147
-
148
- async function getList(id, previewKey) {
149
- const keys = await getKeys(id, previewKey);
150
- return Promise.all(keys.map(async key => {
151
- const content = await getContent(key, previewKey);
152
- return {
153
- id: key,
154
- ...content.meta
155
- };
156
- }));
157
- }
158
-
159
- async function searchContent(to, body, previewKey) {
160
- const navigation = await getNavigation(previewKey);
161
- const db = await (0, _database.createDatabase)(navigation);
162
- return db.search(to, body);
163
- }
164
-
165
- const getNavigationCached = withCache("navigation", async () => (0, _navigation.generateNavigation)(await getList()));
166
-
167
- const getNavigation = async previewKey => {
168
- if (!previewKey) {
169
- return getNavigationCached();
170
- }
171
-
172
- return (0, _navigation.generateNavigation)(await getList(void 0, previewKey));
173
- };
174
-
175
- exports.getNavigation = getNavigation;
@@ -1,114 +0,0 @@
1
- import { prefixStorage as unstoragePrefixStorage } from "unstorage";
2
- import micromatch from "micromatch";
3
- import { getTransformer } from "../transformers/index.mjs";
4
- import { createDatabase } from "../database/index.mjs";
5
- import { generateNavigation } from "../navigation.mjs";
6
- import { useDocusContext } from "../context.mjs";
7
- import { cachify } from "./utils/cache.mjs";
8
- import { storage } from "#storage";
9
- function prefixStorage(storage2, base) {
10
- const nsStorage = unstoragePrefixStorage(storage2, base);
11
- const prefixRegex = new RegExp(`^${base}:`);
12
- nsStorage.getKeys = (id = "") => {
13
- return storage2.getKeys(base + ":" + id).then((keys) => keys.map((key) => key.replace(prefixRegex, "")));
14
- };
15
- return nsStorage;
16
- }
17
- export const contentStorage = prefixStorage(storage, "docus:source");
18
- export const buildStorage = prefixStorage(storage, "assets:docus:build");
19
- export const previewStorage = prefixStorage(storage, "docus:preview");
20
- const isProduction = process.env.NODE_ENV === "production";
21
- const withCache = (name, fn) => isProduction ? cachify(fn, { name, swr: true, ttl: 6e4, integrity: "docus" }) : fn;
22
- async function getData(id, previewKey) {
23
- let body;
24
- let meta;
25
- if (previewKey) {
26
- body = await previewStorage.getItem(`${previewKey}:${id}`);
27
- meta = await previewStorage.getMeta(`${previewKey}:${id}`);
28
- }
29
- if (!body) {
30
- body = await contentStorage.getItem(id);
31
- meta = await contentStorage.getMeta(id);
32
- }
33
- if (body && typeof body === "object") {
34
- body = JSON.stringify(typeof body.default !== "undefined" ? body.default : body);
35
- }
36
- if (typeof body !== "string") {
37
- body = body + "";
38
- }
39
- return {
40
- body,
41
- meta
42
- };
43
- }
44
- const getContentKeys = async (id) => {
45
- let keys = await buildStorage.getKeys(id);
46
- if (keys.length === 0) {
47
- keys = await contentStorage.getKeys(id);
48
- const context = useDocusContext();
49
- keys = micromatch.not(keys, context?.ignoreList || []);
50
- }
51
- return keys;
52
- };
53
- const getPreviewKeys = async (id, previewKey) => {
54
- let keys = (await previewStorage.getKeys(id ? `${previewKey}:${id}` : previewKey)).map((key) => key.replace(`${previewKey}:`, ""));
55
- const context = useDocusContext();
56
- keys = micromatch.not(keys, context?.ignoreList || []);
57
- return keys;
58
- };
59
- async function getKeys(id, previewKey) {
60
- let keys = await getContentKeys(id);
61
- if (previewKey) {
62
- const previewKeys = await getPreviewKeys(id, previewKey);
63
- keys = keys.filter((key) => !previewKeys.includes(key));
64
- keys.push(...previewKeys);
65
- }
66
- return keys;
67
- }
68
- export async function buildContent(id, previewKey) {
69
- const data = await getData(id, previewKey);
70
- if (typeof data.body === "undefined" || data.body === null) {
71
- throw new Error(`Content not found: ${id}`);
72
- }
73
- const transformResult = await getTransformer(id)(id, data.body);
74
- const content = {
75
- meta: {
76
- ...data.meta,
77
- ...transformResult.meta
78
- },
79
- body: transformResult.body
80
- };
81
- if (!previewKey) {
82
- await buildStorage.setItem(id, content);
83
- }
84
- return content;
85
- }
86
- export async function getContent(id, previewKey) {
87
- let content = !previewKey && await buildStorage.getItem(id);
88
- if (!content) {
89
- content = await buildContent(id, previewKey);
90
- }
91
- return content;
92
- }
93
- export async function getList(id, previewKey) {
94
- const keys = await getKeys(id, previewKey);
95
- return Promise.all(keys.map(async (key) => {
96
- const content = await getContent(key, previewKey);
97
- return {
98
- id: key,
99
- ...content.meta
100
- };
101
- }));
102
- }
103
- export async function searchContent(to, body, previewKey) {
104
- const navigation = await getNavigation(previewKey);
105
- const db = await createDatabase(navigation);
106
- return db.search(to, body);
107
- }
108
- const getNavigationCached = withCache("navigation", async () => generateNavigation(await getList()));
109
- export const getNavigation = async (previewKey) => {
110
- if (!previewKey) {
111
- return getNavigationCached();
112
- }
113
- return generateNavigation(await getList(void 0, previewKey));
114
- };
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- import type { IncomingMessage } from 'http';
3
- /**
4
- * WebSocket server useful for live content reload.
5
- */
6
- export declare function useWebSocket(): {
7
- serve: (req: IncomingMessage, socket?: import("net").Socket, head?: any) => void;
8
- broadcast: (data: any) => void;
9
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useWebSocket = useWebSocket;
7
-
8
- var _ws = require("ws");
9
-
10
- let wss;
11
-
12
- function useWebSocket() {
13
- if (!wss) wss = new _ws.Server({
14
- noServer: true
15
- });
16
-
17
- const serve = (req, socket = req.socket, head = "") => wss.handleUpgrade(req, socket, head, client => wss.emit("connection", client, req));
18
-
19
- const broadcast = data => {
20
- data = JSON.stringify(data);
21
-
22
- for (const client of wss.clients) {
23
- try {
24
- client.send(data);
25
- } catch (err) {}
26
- }
27
- };
28
-
29
- return {
30
- serve,
31
- broadcast
32
- };
33
- }
@@ -1,20 +0,0 @@
1
- import { Server } from "ws";
2
- let wss;
3
- export function useWebSocket() {
4
- if (!wss)
5
- wss = new Server({ noServer: true });
6
- const serve = (req, socket = req.socket, head = "") => wss.handleUpgrade(req, socket, head, (client) => wss.emit("connection", client, req));
7
- const broadcast = (data) => {
8
- data = JSON.stringify(data);
9
- for (const client of wss.clients) {
10
- try {
11
- client.send(data);
12
- } catch (err) {
13
- }
14
- }
15
- };
16
- return {
17
- serve,
18
- broadcast
19
- };
20
- }
@@ -1,19 +0,0 @@
1
- import type { Handle } from 'h3';
2
- export interface CacheEntry {
3
- value?: any;
4
- expires?: number;
5
- mtime?: number;
6
- integrity?: string;
7
- }
8
- export interface CachifyOptions {
9
- name: string;
10
- getKey?: (...args: any[]) => string;
11
- transform?: (entry: CacheEntry, ...args: any[]) => any;
12
- group?: string;
13
- integrity?: any;
14
- ttl?: number;
15
- swr?: boolean;
16
- base?: string;
17
- }
18
- export declare function cachify(fn: (...args: any[]) => any, opts: CachifyOptions): (...args: any[]) => Promise<any>;
19
- export declare function cachifyHandle(handle: Handle, opts: Omit<CachifyOptions, 'getKey'>): (...args: any[]) => Promise<any>;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.cachify = cachify;
7
- exports.cachifyHandle = cachifyHandle;
8
-
9
- var _murmurhashEs = require("murmurhash-es");
10
-
11
- var _storage = require("#storage");
12
-
13
- function cachify(fn, opts) {
14
- const pending = {};
15
- opts.base = process.env.NODE_ENV === "development" ? "/root/node_modules/.cache/cachify" : "/cache";
16
- const group = opts.group || "";
17
- const name = opts.name || fn.name || "_";
18
- const integrity = (0, _murmurhashEs.murmurHashV3)(JSON.stringify(opts.integrity || fn)) + "-" + name;
19
-
20
- async function get(key, resolver) {
21
- const cacheKey = [opts.base, group, name, key].filter(Boolean).join(":");
22
- const entry = (await _storage.storage.getItem(cacheKey)) || {};
23
- const ttl = (opts.ttl ?? opts.ttl ?? 0) * 1e3;
24
-
25
- if (ttl) {
26
- entry.expires = Date.now() + ttl;
27
- }
28
-
29
- const expired = entry.integrity !== integrity || ttl && Date.now() - (entry.mtime || 0) > ttl;
30
-
31
- const _resolve = async () => {
32
- if (!pending[key]) {
33
- pending[key] = resolver();
34
- }
35
-
36
- entry.value = await pending[key];
37
- entry.mtime = Date.now();
38
- entry.integrity = integrity;
39
- delete pending[key];
40
-
41
- _storage.storage.setItem(cacheKey, entry).catch(console.error);
42
- };
43
-
44
- const _resolvePromise = expired ? _resolve() : Promise.resolve();
45
-
46
- if (opts.swr && entry.value) {
47
- _resolvePromise.catch(console.error);
48
-
49
- return Promise.resolve(entry);
50
- }
51
-
52
- return _resolvePromise.then(() => entry);
53
- }
54
-
55
- return async (...args) => {
56
- const key = (opts.getKey || getKey)(...args);
57
- const entry = await get(key, () => fn(...args));
58
- let value = entry.value;
59
-
60
- if (opts.transform) {
61
- value = (await opts.transform(entry, ...args)) || value;
62
- }
63
-
64
- return value;
65
- };
66
- }
67
-
68
- function getKey(...args) {
69
- return "args" + (0, _murmurhashEs.murmurHashV3)(JSON.stringify(args));
70
- }
71
-
72
- function cachifyHandle(handle, opts) {
73
- const _opts = {
74
- getKey: req => req.originalUrl || req.url,
75
-
76
- transform(entry, _req, res) {
77
- for (const header in entry.value.headers) {
78
- res.setHeader(header, entry.value.headers[header]);
79
- }
80
-
81
- const cacheControl = [];
82
-
83
- if (opts.swr) {
84
- if (opts.ttl) {
85
- cacheControl.push(`s-maxage=${opts.ttl / 1e3}`);
86
- }
87
-
88
- cacheControl.push("stale-while-revalidate");
89
- } else if (opts.ttl) {
90
- cacheControl.push(`max-age=${opts.ttl / 1e3}`);
91
- }
92
-
93
- if (cacheControl.length) {
94
- res.setHeader("Cache-Control", cacheControl.join(", "));
95
- }
96
-
97
- return entry.value.body;
98
- },
99
-
100
- ...opts
101
- };
102
- return cachify(async (req, res) => {
103
- const body = await handle(req, res);
104
- const headers = res.getHeaders();
105
- return {
106
- body,
107
- headers
108
- };
109
- }, _opts);
110
- }
@@ -1,75 +0,0 @@
1
- import { murmurHashV3 } from "murmurhash-es";
2
- import { storage } from "#storage";
3
- export function cachify(fn, opts) {
4
- const pending = {};
5
- opts.base = process.env.NODE_ENV === "development" ? "/root/node_modules/.cache/cachify" : "/cache";
6
- const group = opts.group || "";
7
- const name = opts.name || fn.name || "_";
8
- const integrity = murmurHashV3(JSON.stringify(opts.integrity || fn)) + "-" + name;
9
- async function get(key, resolver) {
10
- const cacheKey = [opts.base, group, name, key].filter(Boolean).join(":");
11
- const entry = await storage.getItem(cacheKey) || {};
12
- const ttl = (opts.ttl ?? opts.ttl ?? 0) * 1e3;
13
- if (ttl) {
14
- entry.expires = Date.now() + ttl;
15
- }
16
- const expired = entry.integrity !== integrity || ttl && Date.now() - (entry.mtime || 0) > ttl;
17
- const _resolve = async () => {
18
- if (!pending[key]) {
19
- pending[key] = resolver();
20
- }
21
- entry.value = await pending[key];
22
- entry.mtime = Date.now();
23
- entry.integrity = integrity;
24
- delete pending[key];
25
- storage.setItem(cacheKey, entry).catch(console.error);
26
- };
27
- const _resolvePromise = expired ? _resolve() : Promise.resolve();
28
- if (opts.swr && entry.value) {
29
- _resolvePromise.catch(console.error);
30
- return Promise.resolve(entry);
31
- }
32
- return _resolvePromise.then(() => entry);
33
- }
34
- return async (...args) => {
35
- const key = (opts.getKey || getKey)(...args);
36
- const entry = await get(key, () => fn(...args));
37
- let value = entry.value;
38
- if (opts.transform) {
39
- value = await opts.transform(entry, ...args) || value;
40
- }
41
- return value;
42
- };
43
- }
44
- function getKey(...args) {
45
- return "args" + murmurHashV3(JSON.stringify(args));
46
- }
47
- export function cachifyHandle(handle, opts) {
48
- const _opts = {
49
- getKey: (req) => req.originalUrl || req.url,
50
- transform(entry, _req, res) {
51
- for (const header in entry.value.headers) {
52
- res.setHeader(header, entry.value.headers[header]);
53
- }
54
- const cacheControl = [];
55
- if (opts.swr) {
56
- if (opts.ttl) {
57
- cacheControl.push(`s-maxage=${opts.ttl / 1e3}`);
58
- }
59
- cacheControl.push("stale-while-revalidate");
60
- } else if (opts.ttl) {
61
- cacheControl.push(`max-age=${opts.ttl / 1e3}`);
62
- }
63
- if (cacheControl.length) {
64
- res.setHeader("Cache-Control", cacheControl.join(", "));
65
- }
66
- return entry.value.body;
67
- },
68
- ...opts
69
- };
70
- return cachify(async (req, res) => {
71
- const body = await handle(req, res);
72
- const headers = res.getHeaders();
73
- return { body, headers };
74
- }, _opts);
75
- }
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- export declare function usePreview(req: IncomingMessage): string;
4
- export declare function useKey(req: IncomingMessage): string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useKey = useKey;
7
- exports.usePreview = usePreview;
8
-
9
- var _h = require("h3");
10
-
11
- function usePreview(req) {
12
- const query = (0, _h.useQuery)(req);
13
- return (query.preview || "").replace(/\//g, ":");
14
- }
15
-
16
- function useKey(req) {
17
- return (req.url || "").split("?")[0].replace(/^\//, "");
18
- }
@@ -1,8 +0,0 @@
1
- import { useQuery } from "h3";
2
- export function usePreview(req) {
3
- const query = useQuery(req);
4
- return (query.preview || "").replace(/\//g, ":");
5
- }
6
- export function useKey(req) {
7
- return (req.url || "").split("?")[0].replace(/^\//, "");
8
- }
@@ -1 +0,0 @@
1
- export declare function getTransformer(id: string): (id: string, body: string) => any;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTransformer = getTransformer;
7
-
8
- var _markdown = _interopRequireDefault(require("./markdown"));
9
-
10
- var _json = _interopRequireDefault(require("./json"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const transformers = {
15
- default: (_id = "", body = "") => ({
16
- body,
17
- meta: {}
18
- }),
19
- ".md": _markdown.default,
20
- ".json": _json.default
21
- };
22
- const exts = Object.keys(transformers);
23
-
24
- function getTransformer(id) {
25
- return transformers[exts.find(ext => id.endsWith(ext)) || "default"];
26
- }
@@ -1,11 +0,0 @@
1
- import markdown from "./markdown/index.mjs";
2
- import json from "./json.mjs";
3
- const transformers = {
4
- default: (_id = "", body = "") => ({ body, meta: {} }),
5
- ".md": markdown,
6
- ".json": json
7
- };
8
- const exts = Object.keys(transformers);
9
- export function getTransformer(id) {
10
- return transformers[exts.find((ext) => id.endsWith(ext)) || "default"];
11
- }
@@ -1,3 +0,0 @@
1
- export default function transformJSON(_id: string, input: string | object): {
2
- body: any;
3
- };