@levino/shipyard-docs 0.4.2 → 0.4.5
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/astro/DocsEntry.astro +4 -7
- package/astro/Layout.astro +8 -4
- package/package.json +8 -4
- package/src/index.ts +14 -16
- package/astro/DefaultLocaleDocsEntry.astro +0 -20
package/astro/DocsEntry.astro
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
---
|
|
2
|
+
import { i18n } from 'astro:config/server'
|
|
2
3
|
import { getCollection, render } from 'astro:content'
|
|
3
|
-
import config from 'virtual:shipyard/config'
|
|
4
4
|
import Layout from './Layout.astro'
|
|
5
5
|
|
|
6
6
|
export async function getStaticPaths() {
|
|
7
7
|
const docs = await getCollection('docs')
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const getParams = (slug: string, hasI18n: boolean) => {
|
|
13
|
-
if (hasI18n) {
|
|
9
|
+
const getParams = (slug: string) => {
|
|
10
|
+
if (i18n) {
|
|
14
11
|
const [locale, ...rest] = slug.split('/')
|
|
15
12
|
return {
|
|
16
13
|
slug: rest.length ? rest.join('/') : undefined,
|
|
@@ -25,7 +22,7 @@ export async function getStaticPaths() {
|
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
return docs.map((entry) => ({
|
|
28
|
-
params: getParams(entry.id
|
|
25
|
+
params: getParams(entry.id),
|
|
29
26
|
props: { entry },
|
|
30
27
|
}))
|
|
31
28
|
}
|
package/astro/Layout.astro
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
+
import { i18n } from 'astro:config/server'
|
|
2
3
|
import { getCollection, render } from 'astro:content'
|
|
3
4
|
import type { NavigationTree } from '@levino/shipyard-base'
|
|
4
5
|
import BaseLayout from '@levino/shipyard-base/layouts/Page.astro'
|
|
@@ -6,7 +7,8 @@ import { Array as EffectArray, Option } from 'effect'
|
|
|
6
7
|
import { path } from 'ramda'
|
|
7
8
|
import { toSidebarEntries } from '../src/sidebarEntries'
|
|
8
9
|
|
|
9
|
-
const getPath = (id: string) =>
|
|
10
|
+
const getPath = (id: string) =>
|
|
11
|
+
i18n ? `/${Astro.currentLocale}/docs/${id.slice(3)}` : `/docs/${id}`
|
|
10
12
|
|
|
11
13
|
const docs = await getCollection('docs')
|
|
12
14
|
.then(
|
|
@@ -36,9 +38,11 @@ const docs = await getCollection('docs')
|
|
|
36
38
|
)
|
|
37
39
|
.then((promises) => Promise.all(promises))
|
|
38
40
|
|
|
39
|
-
const entries = path(
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const entries = path(
|
|
42
|
+
i18n
|
|
43
|
+
? [Astro.currentLocale, 'subEntry', 'docs', 'subEntry']
|
|
44
|
+
: ['docs', 'subEntry'],
|
|
45
|
+
)(toSidebarEntries(docs)) as NavigationTree
|
|
42
46
|
---
|
|
43
47
|
|
|
44
48
|
<BaseLayout sidebarNavigation={entries}>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@levino/shipyard-docs",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -12,15 +12,19 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"effect": "^3.12.5",
|
|
15
|
-
"ramda": "^0.
|
|
16
|
-
"@levino/shipyard-base": "^0.5.
|
|
15
|
+
"ramda": "^0.31",
|
|
16
|
+
"@levino/shipyard-base": "^0.5.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@tailwindcss/typography": "^0.5.16",
|
|
20
|
-
"@types/ramda": "^0.
|
|
20
|
+
"@types/ramda": "^0.31",
|
|
21
21
|
"astro": "^5.7",
|
|
22
22
|
"vitest": "^2.1.8"
|
|
23
23
|
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/levino/shipyard"
|
|
27
|
+
},
|
|
24
28
|
"exports": {
|
|
25
29
|
".": "./src/index.ts",
|
|
26
30
|
"./layout": "./astro/Layout.astro",
|
package/src/index.ts
CHANGED
|
@@ -13,25 +13,23 @@ export const docsSchema = z.object({
|
|
|
13
13
|
description: z.string().optional(),
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
export default (
|
|
16
|
+
export default (): AstroIntegration => ({
|
|
17
17
|
name: 'shipyard-docs',
|
|
18
18
|
hooks: {
|
|
19
19
|
'astro:config:setup': ({ injectRoute, config }) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
})
|
|
20
|
+
if (config.i18n) {
|
|
21
|
+
// With i18n: use locale prefix
|
|
22
|
+
injectRoute({
|
|
23
|
+
pattern: `/[locale]/docs/[...slug]`,
|
|
24
|
+
entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
|
|
25
|
+
})
|
|
26
|
+
} else {
|
|
27
|
+
// Without i18n: direct path
|
|
28
|
+
injectRoute({
|
|
29
|
+
pattern: `/docs/[...slug]`,
|
|
30
|
+
entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
35
33
|
},
|
|
36
34
|
},
|
|
37
35
|
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { getCollection, render } from 'astro:content'
|
|
3
|
-
import Layout from './Layout.astro'
|
|
4
|
-
|
|
5
|
-
export async function getStaticPaths() {
|
|
6
|
-
const docs = await getCollection('docs')
|
|
7
|
-
|
|
8
|
-
return docs.map((entry) => ({
|
|
9
|
-
params: { slug: entry.id },
|
|
10
|
-
props: { entry },
|
|
11
|
-
}))
|
|
12
|
-
}
|
|
13
|
-
// 2. For your template, you can get the entry directly from the prop
|
|
14
|
-
const { entry } = Astro.props
|
|
15
|
-
const { Content } = await render(entry)
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
<Layout>
|
|
19
|
-
<Content />
|
|
20
|
-
</Layout>
|