@levino/shipyard-docs 0.2.1 → 0.4.0
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/DefaultLocaleDocsEntry.astro +20 -0
- package/astro/DocsEntry.astro +11 -11
- package/astro/Layout.astro +17 -16
- package/package.json +2 -2
- package/src/sidebarEntries.test.ts +1 -0
- package/src/sidebarEntries.ts +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
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>
|
package/astro/DocsEntry.astro
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
---
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { getCollection, render } from 'astro:content'
|
|
3
|
+
import Layout from './Layout.astro'
|
|
4
4
|
|
|
5
5
|
export async function getStaticPaths() {
|
|
6
|
+
const docs = await getCollection('docs')
|
|
6
7
|
const getParams = (slug: string) => {
|
|
7
|
-
const [locale, ...rest] = slug.split(
|
|
8
|
+
const [locale, ...rest] = slug.split('/')
|
|
8
9
|
return {
|
|
9
|
-
slug: rest.length ? rest.join(
|
|
10
|
+
slug: rest.length ? rest.join('/') : undefined,
|
|
10
11
|
locale,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const docs = await getCollection("docs");
|
|
14
|
-
|
|
12
|
+
}
|
|
13
|
+
}
|
|
15
14
|
return docs.map((entry) => ({
|
|
16
15
|
params: getParams(entry.id),
|
|
17
16
|
props: { entry },
|
|
18
|
-
}))
|
|
17
|
+
}))
|
|
19
18
|
}
|
|
19
|
+
|
|
20
20
|
// 2. For your template, you can get the entry directly from the prop
|
|
21
|
-
const { entry } = Astro.props
|
|
22
|
-
const { Content } = await render(entry)
|
|
21
|
+
const { entry } = Astro.props
|
|
22
|
+
const { Content } = await render(entry)
|
|
23
23
|
---
|
|
24
24
|
|
|
25
25
|
<Layout>
|
package/astro/Layout.astro
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { getCollection, render } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
2
|
+
import { getCollection, render } from 'astro:content'
|
|
3
|
+
import type { NavigationTree } from '@levino/shipyard-base'
|
|
4
|
+
import BaseLayout from '@levino/shipyard-base/layouts/Page.astro'
|
|
5
|
+
import { Array as EffectArray, Option } from 'effect'
|
|
6
|
+
import { path } from 'ramda'
|
|
7
|
+
import { toSidebarEntries } from '../src/sidebarEntries'
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const getPath = (id: string) => `/${Astro.currentLocale}/docs/${id.slice(3)}`
|
|
10
|
+
|
|
11
|
+
const docs = await getCollection('docs')
|
|
11
12
|
.then(
|
|
12
|
-
|
|
13
|
+
EffectArray.map(async (doc) => {
|
|
13
14
|
const {
|
|
14
15
|
id,
|
|
15
16
|
data: {
|
|
16
17
|
title,
|
|
17
18
|
sidebar: { render: shouldBeRendered, label },
|
|
18
19
|
},
|
|
19
|
-
} = doc
|
|
20
|
+
} = doc
|
|
20
21
|
return {
|
|
21
|
-
path:
|
|
22
|
+
path: getPath(id),
|
|
22
23
|
title:
|
|
23
24
|
label ??
|
|
24
25
|
title ??
|
|
25
26
|
Option.getOrUndefined(
|
|
26
|
-
|
|
27
|
+
EffectArray.findFirst(
|
|
27
28
|
(await render(doc)).headings,
|
|
28
29
|
({ depth }) => depth === 1,
|
|
29
30
|
),
|
|
30
31
|
)?.text ??
|
|
31
32
|
id,
|
|
32
33
|
link: shouldBeRendered,
|
|
33
|
-
}
|
|
34
|
+
}
|
|
34
35
|
}),
|
|
35
36
|
)
|
|
36
|
-
.then(Promise.all
|
|
37
|
+
.then((promises) => Promise.all(promises))
|
|
37
38
|
|
|
38
|
-
const entries = path([
|
|
39
|
+
const entries = path([Astro.currentLocale, 'subEntry', 'docs', 'subEntry'])(
|
|
39
40
|
toSidebarEntries(docs),
|
|
40
|
-
) as NavigationTree
|
|
41
|
+
) as NavigationTree
|
|
41
42
|
---
|
|
42
43
|
|
|
43
44
|
<BaseLayout sidebarNavigation={entries}>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@levino/shipyard-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"effect": "^3.12.5",
|
|
15
15
|
"ramda": "^0.29.1",
|
|
16
|
-
"@levino/shipyard-base": "^0.
|
|
16
|
+
"@levino/shipyard-base": "^0.5.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@tailwindcss/typography": "^0.5.16",
|