undocs 0.2.24 → 0.2.26

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 (23) hide show
  1. package/app/modules/og-image/runtime/handler.ts +6 -1
  2. package/app/pages/[...slug].vue +2 -2
  3. package/app/server/plugins/content.ts +13 -0
  4. package/cli/setup.mjs +22 -0
  5. package/package.json +1 -1
  6. package/schema/config.d.ts +1 -0
  7. package/schema/config.json +4 -0
  8. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-200-normal.woff +0 -0
  9. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-300-normal.woff +0 -0
  10. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-400-normal.woff +0 -0
  11. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-500-normal.woff +0 -0
  12. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-600-normal.woff +0 -0
  13. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-700-normal.woff +0 -0
  14. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-800-normal.woff +0 -0
  15. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-900-normal.woff +0 -0
  16. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-200-normal.woff +0 -0
  17. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-300-normal.woff +0 -0
  18. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-400-normal.woff +0 -0
  19. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-500-normal.woff +0 -0
  20. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-600-normal.woff +0 -0
  21. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-700-normal.woff +0 -0
  22. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-800-normal.woff +0 -0
  23. package/app/modules/og-image/runtime/assets/fonts/nunito-latin-ext-900-normal.woff +0 -0
@@ -7,7 +7,12 @@ export default defineLazyEventHandler(async () => {
7
7
 
8
8
  // Read server assets
9
9
  const storage = useStorage()
10
- const fontNames = await storage.getKeys('assets:og-image:fonts:')
10
+ // https://github.com/unjs/unstorage/issues/477
11
+ // const fontNames = await storage.getKeys('assets:og-image:fonts:')
12
+ const fontNames = ['200', '300', '400', '500', '600', '700', '800', '900'].flatMap((weight) => [
13
+ `assets:og-image:fonts:nunito-latin-${weight}-normal.woff2`,
14
+ `assets:og-image:fonts:nunito-latin-ext-${weight}-normal.woff2`,
15
+ ])
11
16
  const fontBuffers = await Promise.all(fontNames.map((name) => storage.getItemRaw(name)))
12
17
 
13
18
  // Load icon
@@ -110,8 +110,8 @@ onMounted(() => {
110
110
  :links="[
111
111
  {
112
112
  icon: 'i-ph-pen-duotone',
113
- label: 'Edit this page on GitHub',
114
- to: `https://github.com/${appConfig.docs.github}/edit/main/docs/${page._file}`,
113
+ label: `Edit this page ${page.automd ? '(some contents are generated with automd from source)' : ''}`,
114
+ to: `https://github.com/${appConfig.docs.github}/edit/${appConfig.docs.branch || 'main'}/docs/${page._file}`,
115
115
  target: '_blank',
116
116
  },
117
117
  ]"
@@ -1,5 +1,18 @@
1
1
  // @ts-ignore
2
2
  export default defineNitroPlugin((nitroApp) => {
3
+ nitroApp.hooks.hook('content:file:beforeParse', (file) => {
4
+ if (typeof file.body !== 'string') {
5
+ return // can be json meta
6
+ }
7
+ if (file.body.includes('<!-- automd:')) {
8
+ // Add meta
9
+ if (file.body.startsWith('---')) {
10
+ file.body = file.body.replace('---', '---\nautomd: true\n')
11
+ } else {
12
+ file.body = `---\nautomd: true\n---\n${file.body}`
13
+ }
14
+ }
15
+ })
3
16
  nitroApp.hooks.hook('content:file:afterParse', (file: ContentFile) => {
4
17
  // Filter out non-markdown files
5
18
  if (!file._id?.endsWith('.md')) {
package/cli/setup.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { fileURLToPath } from 'node:url'
2
2
  import { resolve } from 'node:path'
3
+ import { execSync } from 'node:child_process'
3
4
  import { loadConfig, watchConfig } from 'c12'
4
5
 
5
6
  const appDir = fileURLToPath(new URL('../app', import.meta.url))
@@ -62,6 +63,7 @@ export async function setupDocs(docsDir, opts = {}) {
62
63
  },
63
64
  docs: {
64
65
  github: docsconfig.github,
66
+ branch: docsconfig.branch || getGitBranch() || 'main',
65
67
  },
66
68
  },
67
69
  nitro: {
@@ -97,3 +99,23 @@ function inferSiteURL() {
97
99
  process.env.CF_PAGES_URL // Cloudflare Pages
98
100
  )
99
101
  }
102
+
103
+ function getGitBranch() {
104
+ const envName =
105
+ process.env.CF_PAGES_BRANCH ||
106
+ process.env.CI_COMMIT_BRANCH ||
107
+ process.env.VERCEL_BRANCH_URL ||
108
+ process.env.BRANCH ||
109
+ process.env.GITHUB_REF_NAME
110
+ if (envName && envName !== 'HEAD') {
111
+ return envName
112
+ }
113
+ try {
114
+ const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
115
+ if (branch && branch !== 'HEAD') {
116
+ return branch
117
+ }
118
+ } catch {
119
+ // Ignore
120
+ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undocs",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "repository": "unjs/undocs",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -5,6 +5,7 @@ export interface DocsConfig {
5
5
  shortDescription?: string
6
6
  url?: string
7
7
  github?: string
8
+ branch?: string
8
9
  themeColor?: string
9
10
  redirects?: Record<string, string>
10
11
  automd?: unknown
@@ -30,6 +30,10 @@
30
30
  "type": "string",
31
31
  "description": "The GitHub repository for the documentation site."
32
32
  },
33
+ "branch": {
34
+ "type": "string",
35
+ "description": "The branch of the GitHub repository for the documentation site."
36
+ },
33
37
  "themeColor": {
34
38
  "type": "string",
35
39
  "description": "The theme color of the documentation site.\nIt will be used as the `theme-color` meta tag and a full palette of colors will be generated from it."