@levino/shipyard-docs 0.2.1 → 0.3.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 +19 -5
- package/astro/Layout.astro +12 -5
- package/package.json +2 -2
- package/src/index.ts +5 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Layout from "./Layout.astro";
|
|
3
|
+
import { getCollection, render } from "astro:content";
|
|
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,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import Layout from "./Layout.astro";
|
|
3
3
|
import { getCollection, render } from "astro:content";
|
|
4
|
-
|
|
4
|
+
import config from "virtual:shipyard/config";
|
|
5
5
|
export async function getStaticPaths() {
|
|
6
6
|
const getParams = (slug: string) => {
|
|
7
7
|
const [locale, ...rest] = slug.split("/");
|
|
@@ -12,10 +12,24 @@ export async function getStaticPaths() {
|
|
|
12
12
|
};
|
|
13
13
|
const docs = await getCollection("docs");
|
|
14
14
|
|
|
15
|
-
return docs
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
return docs
|
|
16
|
+
.filter((entry) => {
|
|
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
|
+
}));
|
|
19
33
|
}
|
|
20
34
|
// 2. For your template, you can get the entry directly from the prop
|
|
21
35
|
const { entry } = Astro.props;
|
package/astro/Layout.astro
CHANGED
|
@@ -5,8 +5,13 @@ import { toSidebarEntries } from "../src/sidebarEntries";
|
|
|
5
5
|
import { path } from "ramda";
|
|
6
6
|
import type { NavigationTree } from "@levino/shipyard-base";
|
|
7
7
|
import { Array, Option } from "effect";
|
|
8
|
+
import config from "virtual:shipyard/config";
|
|
8
9
|
|
|
9
|
-
const locale = Astro.currentLocale as string;
|
|
10
|
+
const locale = (Astro.currentLocale as string) ?? config.defaultLocale;
|
|
11
|
+
const getPath = (id: string) =>
|
|
12
|
+
locale === config.defaultLocale
|
|
13
|
+
? `/docs/${id}`
|
|
14
|
+
: `/${locale}/docs/${id.slice(3)}`;
|
|
10
15
|
const docs = await getCollection("docs")
|
|
11
16
|
.then(
|
|
12
17
|
Array.map(async (doc) => {
|
|
@@ -18,7 +23,7 @@ const docs = await getCollection("docs")
|
|
|
18
23
|
},
|
|
19
24
|
} = doc;
|
|
20
25
|
return {
|
|
21
|
-
path:
|
|
26
|
+
path: getPath(id),
|
|
22
27
|
title:
|
|
23
28
|
label ??
|
|
24
29
|
title ??
|
|
@@ -35,9 +40,11 @@ const docs = await getCollection("docs")
|
|
|
35
40
|
)
|
|
36
41
|
.then(Promise.all.bind(Promise));
|
|
37
42
|
|
|
38
|
-
const entries =
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
const entries = (
|
|
44
|
+
locale == config.defaultLocale
|
|
45
|
+
? path(["docs", "subEntry"])
|
|
46
|
+
: path([locale, "subEntry", "docs", "subEntry"])
|
|
47
|
+
)(toSidebarEntries(docs)) as NavigationTree;
|
|
41
48
|
---
|
|
42
49
|
|
|
43
50
|
<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.3.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.4.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@tailwindcss/typography": "^0.5.16",
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,11 @@ 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
|
+
})
|
|
21
26
|
injectRoute({
|
|
22
27
|
pattern: `/[locale]/${path}/[...slug]`,
|
|
23
28
|
entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
|