@levino/shipyard-docs 0.3.0 → 0.4.1
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 +6 -6
- package/astro/DocsEntry.astro +15 -29
- package/astro/Layout.astro +17 -23
- package/package.json +2 -2
- package/src/index.ts +0 -5
- package/src/sidebarEntries.test.ts +1 -0
- package/src/sidebarEntries.ts +1 -0
|
@@ -1,18 +1,18 @@
|
|
|
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(
|
|
6
|
+
const docs = await getCollection('docs')
|
|
7
7
|
|
|
8
8
|
return docs.map((entry) => ({
|
|
9
9
|
params: { slug: entry.id },
|
|
10
10
|
props: { entry },
|
|
11
|
-
}))
|
|
11
|
+
}))
|
|
12
12
|
}
|
|
13
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)
|
|
14
|
+
const { entry } = Astro.props
|
|
15
|
+
const { Content } = await render(entry)
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
<Layout>
|
package/astro/DocsEntry.astro
CHANGED
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
---
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { getCollection, render } from 'astro:content'
|
|
3
|
+
import Layout from './Layout.astro'
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const [, locale] = entry.id.split("/");
|
|
18
|
-
if (!locale) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (locale === config.defaultLocale) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (config.locales.includes(locale)) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
})
|
|
29
|
-
.map((entry) => ({
|
|
30
|
-
params: getParams(entry.id),
|
|
31
|
-
props: { entry },
|
|
32
|
-
}));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return docs.map((entry) => ({
|
|
15
|
+
params: getParams(entry.id),
|
|
16
|
+
props: { entry },
|
|
17
|
+
}))
|
|
33
18
|
}
|
|
19
|
+
|
|
34
20
|
// 2. For your template, you can get the entry directly from the prop
|
|
35
|
-
const { entry } = Astro.props
|
|
36
|
-
const { Content } = await render(entry)
|
|
21
|
+
const { entry } = Astro.props
|
|
22
|
+
const { Content } = await render(entry)
|
|
37
23
|
---
|
|
38
24
|
|
|
39
25
|
<Layout>
|
package/astro/Layout.astro
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { getCollection, render } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import config from "virtual:shipyard/config";
|
|
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'
|
|
9
8
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
? `/docs/${id}`
|
|
14
|
-
: `/${locale}/docs/${id.slice(3)}`;
|
|
15
|
-
const docs = await getCollection("docs")
|
|
9
|
+
const getPath = (id: string) => `/${Astro.currentLocale}/docs/${id.slice(3)}`
|
|
10
|
+
|
|
11
|
+
const docs = await getCollection('docs')
|
|
16
12
|
.then(
|
|
17
|
-
|
|
13
|
+
EffectArray.map(async (doc) => {
|
|
18
14
|
const {
|
|
19
15
|
id,
|
|
20
16
|
data: {
|
|
21
17
|
title,
|
|
22
18
|
sidebar: { render: shouldBeRendered, label },
|
|
23
19
|
},
|
|
24
|
-
} = doc
|
|
20
|
+
} = doc
|
|
25
21
|
return {
|
|
26
22
|
path: getPath(id),
|
|
27
23
|
title:
|
|
28
24
|
label ??
|
|
29
25
|
title ??
|
|
30
26
|
Option.getOrUndefined(
|
|
31
|
-
|
|
27
|
+
EffectArray.findFirst(
|
|
32
28
|
(await render(doc)).headings,
|
|
33
29
|
({ depth }) => depth === 1,
|
|
34
30
|
),
|
|
35
31
|
)?.text ??
|
|
36
32
|
id,
|
|
37
33
|
link: shouldBeRendered,
|
|
38
|
-
}
|
|
34
|
+
}
|
|
39
35
|
}),
|
|
40
36
|
)
|
|
41
|
-
.then(Promise.all
|
|
37
|
+
.then((promises) => Promise.all(promises))
|
|
42
38
|
|
|
43
|
-
const entries = (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
: path([locale, "subEntry", "docs", "subEntry"])
|
|
47
|
-
)(toSidebarEntries(docs)) as NavigationTree;
|
|
39
|
+
const entries = path([Astro.currentLocale, 'subEntry', 'docs', 'subEntry'])(
|
|
40
|
+
toSidebarEntries(docs),
|
|
41
|
+
) as NavigationTree
|
|
48
42
|
---
|
|
49
43
|
|
|
50
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.1",
|
|
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.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@tailwindcss/typography": "^0.5.16",
|
package/src/index.ts
CHANGED
|
@@ -18,11 +18,6 @@ export default (docsPaths: string[]): AstroIntegration => ({
|
|
|
18
18
|
hooks: {
|
|
19
19
|
'astro:config:setup': ({ injectRoute }) => {
|
|
20
20
|
docsPaths.forEach((path) => {
|
|
21
|
-
injectRoute({
|
|
22
|
-
pattern: `/${path}/[...slug]`,
|
|
23
|
-
entrypoint:
|
|
24
|
-
`@levino/shipyard-docs/astro/DefaultLocaleDocsEntry.astro`,
|
|
25
|
-
})
|
|
26
21
|
injectRoute({
|
|
27
22
|
pattern: `/[locale]/${path}/[...slug]`,
|
|
28
23
|
entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
|