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
package/dist/index.mjs DELETED
@@ -1,523 +0,0 @@
1
- import { resolveModule, useNuxt, addServerMiddleware, addPlugin, addTemplate, addPluginTemplate, resolveAlias, installModule, defineNuxtModule } from '@nuxt/kit';
2
- import { resolve, dirname, join } from 'pathe';
3
- import fetch from 'node-fetch';
4
- import { joinURL } from 'ufo';
5
- import { debounce } from 'debounce';
6
- import { createStorage } from 'unstorage';
7
- import fsDriver from 'unstorage/drivers/fs';
8
- import { Server } from 'ws';
9
- import consola from 'consola';
10
- import { fileURLToPath } from 'url';
11
- import fs from 'fs/promises';
12
- import fs$1, { existsSync } from 'fs';
13
- import jiti from 'jiti';
14
- import clearModule from 'clear-module';
15
- import _glob from 'glob';
16
- import defu from 'defu';
17
- import chalk from 'chalk';
18
- import { getContext } from 'unctx';
19
- import iso639 from 'iso-639-1';
20
-
21
- const useDefaultOptions = (nuxt) => ({
22
- apiBase: "_docus",
23
- dirs: ["content"],
24
- watch: nuxt.options.dev,
25
- locales: {
26
- codes: ["en"],
27
- defaultLocale: "en"
28
- },
29
- database: {
30
- provider: "local",
31
- options: {}
32
- },
33
- ignoreList: [],
34
- search: {
35
- inheritanceFields: ["layout"]
36
- },
37
- transformers: {
38
- markdown: {
39
- components: [],
40
- rehypePlugins: [],
41
- remarkPlugins: [],
42
- tagMap: {
43
- a: "prose-a",
44
- blockquote: "prose-blockquote",
45
- "code-inline": "prose-code-inline",
46
- code: "prose-code",
47
- em: "prose-em",
48
- h1: "prose-h1",
49
- h2: "prose-h2",
50
- h3: "prose-h3",
51
- h4: "prose-h4",
52
- h5: "prose-h5",
53
- h6: "prose-h6",
54
- hr: "prose-hr",
55
- img: "prose-img",
56
- li: "prose-li",
57
- ol: "prose-ol",
58
- p: "prose-paragraph",
59
- strong: "prose-strong",
60
- table: "prose-table",
61
- tbody: "prose-tbody",
62
- td: "prose-td",
63
- th: "prose-th",
64
- thead: "prose-thead",
65
- tr: "prose-tr",
66
- ul: "prose-ul"
67
- }
68
- }
69
- }
70
- });
71
-
72
- let wss;
73
- function useWebSocket() {
74
- if (!wss)
75
- wss = new Server({ noServer: true });
76
- const serve = (req, socket = req.socket, head = "") => wss.handleUpgrade(req, socket, head, (client) => wss.emit("connection", client, req));
77
- const broadcast = (data) => {
78
- data = JSON.stringify(data);
79
- for (const client of wss.clients) {
80
- try {
81
- client.send(data);
82
- } catch (err) {
83
- }
84
- }
85
- };
86
- return {
87
- serve,
88
- broadcast
89
- };
90
- }
91
-
92
- const logger = consola.withScope("@docus");
93
-
94
- const distDir = resolve(typeof __dirname === "undefined" ? dirname(fileURLToPath(import.meta.url)) : __dirname);
95
- const _makeResolve = (base) => {
96
- return (...p) => resolve(base, ...p);
97
- };
98
- const runtimeDir = resolve(distDir, "runtime");
99
- const resolveRuntimeDir = _makeResolve(runtimeDir);
100
- const templateDir = resolve(distDir, "templates");
101
- const appDir = resolve(runtimeDir, "app");
102
- const resolveAppDir = _makeResolve(appDir);
103
- resolve(appDir, "components");
104
-
105
- const THEME_CONFIG_FILE = "theme.config";
106
- const DOCUS_CONFIG_FILE = "docus.config";
107
-
108
- const defineThemeConfig = (config) => config;
109
- const defineDocusConfig = (config) => config;
110
- const loadConfig = (file, rootDir) => {
111
- const data = {
112
- configFile: false,
113
- configPath: resolve(rootDir, file)
114
- };
115
- if (existsSync(data.configPath + ".js"))
116
- data.configPath += ".js";
117
- else if (existsSync(data.configPath + ".ts"))
118
- data.configPath += ".ts";
119
- else
120
- return data;
121
- clearModule(data.configPath);
122
- try {
123
- data.configFile = jiti(distDir)(data.configPath);
124
- data.configFile = data.configFile?.default || data.configFile;
125
- } catch (err) {
126
- throw new Error(`Could not find ${file}, this file is needed for Docus.`);
127
- }
128
- return data;
129
- };
130
- const writeConfig = async (file, cacheDir, content) => {
131
- const jsonPath = join(cacheDir, `${file}.json`);
132
- if (!existsSync(cacheDir))
133
- await fs.mkdir(cacheDir, { recursive: true });
134
- if (existsSync(jsonPath))
135
- await fs.rm(jsonPath);
136
- await fs.writeFile(jsonPath, JSON.stringify(content.default || content), { encoding: "utf8" });
137
- };
138
- const loadTheme = (path, rootDir) => {
139
- let themeConfig = {};
140
- let themeConfigPath = resolveModule(join(path, THEME_CONFIG_FILE), { paths: rootDir });
141
- try {
142
- themeConfigPath = jiti(rootDir).resolve(themeConfigPath);
143
- } catch (err) {
144
- return themeConfig;
145
- }
146
- try {
147
- themeConfig = jiti(rootDir)(themeConfigPath);
148
- } catch (err) {
149
- logger.warn(`Could not load theme config: ${themeConfigPath}`, err);
150
- }
151
- themeConfig = themeConfig.default || themeConfig;
152
- return themeConfig;
153
- };
154
- const buildExternals = ["@nuxt/bridge", "@nuxt/kit", "#app", "@vue/composition-api"];
155
- const resolveApiRoute = (route) => {
156
- const nuxt = useNuxt();
157
- const apiBase = nuxt.options.content?.apiBase || useDefaultOptions(nuxt).apiBase;
158
- return joinURL("/api", apiBase, route);
159
- };
160
- async function loadNuxtIgnoreList(nuxt) {
161
- const ignore = ["**/-*.*", "**/node_modules/**", "**/.git/**", "**/.**"];
162
- const ignoreFile = resolve(nuxt.options.rootDir, ".nuxtignore");
163
- const ignoreContent = await fs.readFile(ignoreFile, { encoding: "utf-8" }).catch(() => "");
164
- if (ignoreContent) {
165
- ignore.push(...ignoreContent.split("\n").filter(Boolean));
166
- }
167
- const refinedList = ignore.map((pattern) => {
168
- if (typeof pattern === "string") {
169
- return pattern.replace(/\//g, ":");
170
- }
171
- return pattern;
172
- });
173
- return refinedList;
174
- }
175
-
176
- function setupDevTarget(options, nuxt) {
177
- const ws = useWebSocket();
178
- if (options.watch) {
179
- addServerMiddleware({
180
- route: resolveApiRoute("reload"),
181
- handle: resolveModule("./server/api/reload", { paths: runtimeDir }).replace(/\.js$/, ".mjs")
182
- });
183
- addPlugin(resolveModule("./hot", { paths: templateDir }));
184
- const storage = createStorage();
185
- loadNuxtIgnoreList(nuxt).then((ignoreList) => {
186
- options.dirs.forEach((dir) => {
187
- const [path, key] = Array.isArray(dir) ? dir : [dir, dir];
188
- storage.mount(key, fsDriver({
189
- base: resolve(nuxt.options.rootDir, path),
190
- ignore: ignoreList
191
- }));
192
- });
193
- });
194
- nuxt.server.listen(0).then(({ url, server }) => {
195
- nuxt.options.publicRuntimeConfig.$docus.wsUrl = url.replace("http", "ws");
196
- server.on("upgrade", (req, socket, head) => ws.serve(req, socket, head));
197
- storage.watch(createDebounceContentWatcher(async (event, key) => {
198
- await fetch(joinURL(url, "api", options.apiBase, "reload"), {
199
- method: "POST",
200
- body: JSON.stringify({ event, key })
201
- });
202
- ws.broadcast({ event, key });
203
- }));
204
- });
205
- }
206
- }
207
- function createDebounceContentWatcher(callback) {
208
- const handleEvent = debounce(callback, 200);
209
- return (event, key) => {
210
- if (key.endsWith(".md")) {
211
- handleEvent(event, key);
212
- switch (event) {
213
- case "remove":
214
- logger.info(`You removed ${key}`);
215
- return;
216
- case "update":
217
- logger.info(`You updated ${key}`);
218
- return;
219
- default:
220
- logger.info(`You updated ${key}`);
221
- }
222
- }
223
- };
224
- }
225
-
226
- const glob = (pattern, options = {}) => new Promise((resolve2, reject) => _glob(pattern, options, (err, matches) => {
227
- if (err)
228
- return reject(err);
229
- resolve2(matches);
230
- }));
231
- const setupAppModule = (nuxt, options) => {
232
- loadNuxtIgnoreList(nuxt).then((ignoreList) => options.ignoreList = ignoreList);
233
- nuxt.options.alias["#docus$"] = runtimeDir;
234
- nuxt.options.alias["#docus/composables"] = resolveAppDir("composables");
235
- nuxt.options.alias["#docus/database"] = resolveRuntimeDir("database/providers", options.database.provider);
236
- nuxt.options.alias["#docus/cache"] = join(nuxt.options.rootDir, "node_modules/.cache/docus");
237
- nuxt.options.meta = nuxt.options.meta || {};
238
- nuxt.options.head = nuxt.options.head || {};
239
- nuxt.options.head.meta = nuxt.options.head.meta || [];
240
- nuxt.options.head.meta.push({ charset: "utf-8" }, { name: "viewport", content: "width=device-width, initial-scale=1" });
241
- nuxt.options.bridge = nuxt.options.bridge || {};
242
- nuxt.options.bridge.autoImports = false;
243
- nuxt.options.bridge.postcss8 = true;
244
- nuxt.options.components = Array.isArray(nuxt.options.components) ? nuxt.options.components : [];
245
- nuxt.options.components.push({
246
- path: resolveAppDir("components"),
247
- isAsync: false,
248
- prefix: "",
249
- level: 999
250
- });
251
- nuxt.options.colorMode = nuxt.options.colorMode || {};
252
- nuxt.options.colorMode.classSuffix = "";
253
- nuxt.options.image = nuxt.options.image || {};
254
- nuxt.options.image.domains = nuxt.options.image.domains || [];
255
- nuxt.options.image.domains.push("https://i3.ytimg.com");
256
- nuxt.options.target = "server";
257
- nuxt.options.server = nuxt.options.server || {};
258
- nuxt.options.server.port = parseInt(process.env.PORT || "4000", 10);
259
- nuxt.options.generate = nuxt.options.generate || {};
260
- nuxt.options.generate.routes = nuxt.options.generate.routes || [];
261
- nuxt.options.generate.fallback = "404.html";
262
- nuxt.options.generate.routes.push("/");
263
- nuxt.options.nitro = nuxt.options.nitro || {};
264
- nuxt.options.nitro.experiments = nuxt.options.nitro.experiments || {};
265
- nuxt.options.nitro.experiments.wasm = true;
266
- nuxt.options.nitro.inlineDynamicImports = true;
267
- nuxt.options.nitro.externals = process.env.NITRO_PRESET === "cloudflare" ? false : {
268
- inline: ["docus", "ohmyfetch", "property-information", "@docus/mdc"],
269
- external: [
270
- "vue-docgen-api",
271
- "@nuxt/kit",
272
- "@nuxt/image",
273
- "@nuxtjs/i18n",
274
- "vue-meta",
275
- "vue-router",
276
- "vue-i18n",
277
- "ufo",
278
- "vue-client-only",
279
- "vue-no-ssr",
280
- "ohmyfetch"
281
- ]
282
- };
283
- nuxt.options.build = nuxt.options.build || {};
284
- nuxt.options.build.transpile = nuxt.options.build.transpile || [];
285
- nuxt.options.build.transpile.push("@docus/", "ohmyfetch", "property-information", "nuxt-component-meta", "@nuxt/bridge");
286
- nuxt.options.layouts.default = resolveAppDir("layouts/default.vue");
287
- nuxt.hook("build:extendRoutes", (routes) => {
288
- const hasRoute = (name) => routes.some((route) => route.name === name);
289
- if (!hasRoute("all")) {
290
- routes.push({
291
- path: "/*",
292
- name: "all",
293
- component: resolveAppDir("pages/_.vue")
294
- });
295
- }
296
- });
297
- nuxt.hook("build:before", async () => {
298
- const errorPagePath = resolve(nuxt.options.srcDir, nuxt.options.dir.layouts, "error.vue");
299
- const errorPageExists = await fs.stat(errorPagePath).catch(() => false);
300
- if (!errorPageExists)
301
- nuxt.options.ErrorPage = nuxt.options.ErrorPage || resolveAppDir("layouts/error.vue");
302
- const pagesDirPath = resolve(nuxt.options.srcDir, nuxt.options.dir.pages);
303
- const pagesDirExists = await fs.stat(pagesDirPath).catch(() => false);
304
- if (!pagesDirExists) {
305
- nuxt.options.build.createRoutes = () => [];
306
- nuxt.options.watch.push(pagesDirPath);
307
- }
308
- });
309
- nuxt.hook("components:dirs", async (dirs) => {
310
- const componentsDirPath = resolve(nuxt.options.rootDir, "components");
311
- const componentsDirStat = await fs.stat(componentsDirPath).catch(() => null);
312
- if (componentsDirStat && componentsDirStat.isDirectory()) {
313
- dirs.push({
314
- path: componentsDirPath,
315
- isAsync: false
316
- });
317
- const subDirs = await glob(componentsDirPath + "/**/");
318
- subDirs.forEach((path) => dirs.push({ path, isAsync: false }));
319
- } else {
320
- nuxt.options.watch.push(componentsDirPath);
321
- }
322
- });
323
- addTemplate({
324
- src: resolveModule("./options", { paths: templateDir }),
325
- filename: "docus/options.mjs",
326
- options
327
- });
328
- addPluginTemplate({
329
- src: resolveModule("./docus", { paths: templateDir })
330
- }, {
331
- append: true
332
- });
333
- nuxt.hook("modules:done", () => nuxt.callHook("docus:options", options));
334
- };
335
-
336
- const version = "2.1.0";
337
-
338
- const themeContext = getContext("docus:theme");
339
- const setThemeConfig = themeContext.set;
340
- themeContext.use;
341
- const configContext = getContext("docus:config");
342
- const setDocusConfig = configContext.set;
343
- const useDocusConfig = configContext.use;
344
-
345
- const setupThemeModule = (nuxt) => {
346
- const cacheDir = nuxt.options.alias["#docus/cache"];
347
- const docusConfig = useDocusConfig();
348
- let themeConfig = {};
349
- if (docusConfig?.theme) {
350
- const themePath = resolveAlias(docusConfig?.theme, nuxt.options.alias);
351
- themeConfig = loadTheme(themePath, nuxt.options.rootDir);
352
- }
353
- const { configFile, configPath } = loadConfig(THEME_CONFIG_FILE, nuxt.options.rootDir);
354
- themeConfig = defu(configFile || {}, themeConfig);
355
- setThemeConfig(themeConfig, true);
356
- nuxt.hook("modules:done", async () => await writeConfig(THEME_CONFIG_FILE, cacheDir, themeConfig));
357
- nuxt.options.cli.badgeMessages.push("", chalk.bold("\u{1F484} Theme: ") + chalk.underline.yellow(themeConfig?.name || "Blank"));
358
- nuxt.options.watch.push(configPath);
359
- };
360
-
361
- const defaultConfig = defineDocusConfig({
362
- title: "Docus",
363
- contentDir: "content",
364
- url: "http://localhost:3000",
365
- description: "A website built with Docus.",
366
- template: "page"
367
- });
368
- const setupConfigModule = (nuxt) => {
369
- const cacheDir = nuxt.options.alias["#docus/cache"];
370
- const { configFile: docusConfig, configPath } = loadConfig(DOCUS_CONFIG_FILE, nuxt.options.rootDir);
371
- const config = defu(docusConfig || {}, defaultConfig);
372
- nuxt.options.cli.badgeMessages.push(chalk.bold("\u{1F4DD} Docus: ") + chalk.underline.yellow(`v${version}`));
373
- setDocusConfig(config, true);
374
- setupThemeModule(nuxt);
375
- nuxt.options.meta.name = config.title;
376
- nuxt.options.meta.description = config.description;
377
- nuxt.hook("modules:done", async () => await writeConfig(DOCUS_CONFIG_FILE, cacheDir, config));
378
- nuxt.options.watch.push(configPath);
379
- };
380
-
381
- const defaultI18nConfig = {
382
- baseUrl: (nuxt) => nuxt.app?.$docus?.config?.value?.url || "",
383
- locales: [],
384
- defaultLocale: "en",
385
- parsePages: false,
386
- vuex: false,
387
- vueI18n: {
388
- fallbackLocale: "en",
389
- dateTimeFormats: {
390
- en: {
391
- long: {
392
- year: "numeric",
393
- month: "short",
394
- day: "numeric",
395
- weekday: "short"
396
- }
397
- },
398
- fr: {
399
- long: {
400
- year: "numeric",
401
- month: "long",
402
- day: "numeric",
403
- weekday: "short"
404
- }
405
- }
406
- }
407
- }
408
- };
409
- const setupI18nModule = async (nuxt) => {
410
- const config = useDocusConfig();
411
- nuxt.options.i18n = defu(nuxt.options.i18n, defaultI18nConfig);
412
- const i18nConfig = nuxt.options.i18n;
413
- try {
414
- if (!nuxt.options.i18n?.locales?.length) {
415
- const contentDir = resolve(nuxt.options.srcDir, config?.contentDir || "content");
416
- const contentDirectories = fs$1.readdirSync(contentDir);
417
- i18nConfig.locales = contentDirectories.filter((lang) => !!iso639.getName(lang)).map((code) => ({ code, iso: code, name: iso639.getName(code) }));
418
- if (!i18nConfig.locales.length)
419
- throw new Error("No locales detected from `contentDir`! Using fallback.");
420
- }
421
- } catch (e) {
422
- const defaultLocale = i18nConfig.defaultLocale || "en";
423
- i18nConfig.locales = [
424
- {
425
- code: defaultLocale,
426
- iso: defaultLocale,
427
- name: iso639.getName(defaultLocale) || defaultLocale
428
- }
429
- ];
430
- }
431
- addPlugin(resolveModule("./i18n", { paths: templateDir }));
432
- const localesList = i18nConfig.locales?.map(({ code }) => code).join(", ") || "en";
433
- nuxt.options.cli.badgeMessages.push("", chalk.bold("\u{1F4D9} Languages: ") + chalk.underline.yellow(localesList));
434
- await installModule(nuxt, "@nuxtjs/i18n");
435
- nuxt.hook("docus:context", (docusContext) => {
436
- const codes = nuxt.options.i18n?.locales.map((locale) => locale.code || locale);
437
- docusContext.locales.codes = codes || docusContext.locales.codes;
438
- docusContext.locales.defaultLocale = nuxt.options.i18n?.defaultLocale || docusContext.locales.defaultLocale;
439
- });
440
- nuxt.hook("build:extendRoutes", (routes) => {
441
- const index = routes.findIndex((route) => route.path === "/*");
442
- const [all] = routes.splice(index, 1);
443
- routes.push(all);
444
- });
445
- };
446
-
447
- async function setupComponentMetaModule(nuxt) {
448
- const markdownTemplateHanlder = (documentation, ast) => {
449
- if (ast.tag === "Markdown") {
450
- const useValue = ast.props?.find((prop) => prop.name === "use")?.value;
451
- const slotName = (typeof useValue === "object" ? useValue.content : useValue) ?? "default";
452
- documentation.getSlotDescriptor(slotName);
453
- }
454
- };
455
- await installModule(nuxt, {
456
- src: "nuxt-component-meta/module",
457
- options: {
458
- parserOptions: {
459
- addTemplateHandlers: [markdownTemplateHanlder]
460
- }
461
- }
462
- });
463
- }
464
-
465
- const setupContentModule = (nuxt, options) => {
466
- nuxt.hook("nitro:context", (ctx) => {
467
- if (ctx.preset === "dev") {
468
- for (const dir of options.dirs) {
469
- const [path, key] = Array.isArray(dir) ? dir : [dir, dir.replace(/[/:]/g, "_")];
470
- ctx.storage.mounts[`docus:source:${key}`] = {
471
- driver: "fs",
472
- driverOptions: {
473
- base: resolve(nuxt.options.rootDir, path)
474
- }
475
- };
476
- }
477
- ctx.storage.mounts["assets:docus:build"] = {
478
- driver: "fs",
479
- driverOptions: {
480
- base: resolve(nuxt.options.buildDir, "docus/build")
481
- }
482
- };
483
- } else {
484
- ctx.assets.dirs["docus:build"] = {
485
- dir: resolve(nuxt.options.buildDir, "docus/build"),
486
- meta: true
487
- };
488
- }
489
- if (!ctx.storage.mounts["docus:preview"]) {
490
- ctx.storage.mounts["docus:preview"] = {
491
- driver: "memory"
492
- };
493
- }
494
- });
495
- for (const api of ["get", "list", "search", "navigation", "preview"]) {
496
- addServerMiddleware({
497
- route: resolveApiRoute(api),
498
- handle: resolveModule(`./server/api/${api}`, { paths: runtimeDir }).replace(/\.js$/, ".mjs")
499
- });
500
- }
501
- nuxt.options.publicRuntimeConfig.$docus = {
502
- apiBase: options.apiBase,
503
- tagMap: options.transformers.markdown.tagMap
504
- };
505
- addPlugin(resolveModule("./content", { paths: templateDir }));
506
- };
507
-
508
- const index = defineNuxtModule((nuxt) => ({
509
- configKey: "content",
510
- defaults: useDefaultOptions(nuxt),
511
- async setup(options, nuxt2) {
512
- if (nuxt2.options.dev)
513
- setupDevTarget(options, nuxt2);
514
- setupAppModule(nuxt2, options);
515
- setupContentModule(nuxt2, options);
516
- setupConfigModule(nuxt2);
517
- await setupI18nModule(nuxt2);
518
- await setupComponentMetaModule(nuxt2);
519
- await installModule(nuxt2, "@nuxt/image");
520
- }
521
- }));
522
-
523
- export { buildExternals, index as default, defineDocusConfig, defineThemeConfig, loadConfig, loadNuxtIgnoreList, loadTheme, resolveApiRoute, writeConfig };