@levino/shipyard-docs 0.4.1 → 0.4.3

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.
@@ -1,16 +1,26 @@
1
1
  ---
2
+ import { i18n } from 'astro:config/server'
2
3
  import { getCollection, render } from 'astro:content'
3
4
  import Layout from './Layout.astro'
4
5
 
5
6
  export async function getStaticPaths() {
6
7
  const docs = await getCollection('docs')
8
+
7
9
  const getParams = (slug: string) => {
8
- const [locale, ...rest] = slug.split('/')
9
- return {
10
- slug: rest.length ? rest.join('/') : undefined,
11
- locale,
10
+ if (i18n) {
11
+ const [locale, ...rest] = slug.split('/')
12
+ return {
13
+ slug: rest.length ? rest.join('/') : undefined,
14
+ locale,
15
+ }
16
+ } else {
17
+ // For non-i18n, treat the entire slug as the path
18
+ return {
19
+ slug: slug || undefined,
20
+ }
12
21
  }
13
22
  }
23
+
14
24
  return docs.map((entry) => ({
15
25
  params: getParams(entry.id),
16
26
  props: { entry },
@@ -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) => `/${Astro.currentLocale}/docs/${id.slice(3)}`
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([Astro.currentLocale, 'subEntry', 'docs', 'subEntry'])(
40
- toSidebarEntries(docs),
41
- ) as NavigationTree
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.1",
3
+ "version": "0.4.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -8,17 +8,17 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "peerDependencies": {
11
- "astro": "^5"
11
+ "astro": "^5.7"
12
12
  },
13
13
  "dependencies": {
14
14
  "effect": "^3.12.5",
15
- "ramda": "^0.29.1",
16
- "@levino/shipyard-base": "^0.5.1"
15
+ "ramda": "^0.31",
16
+ "@levino/shipyard-base": "^0.5.4"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@tailwindcss/typography": "^0.5.16",
20
- "@types/ramda": "^0.29.9",
21
- "astro": "^5",
20
+ "@types/ramda": "^0.31",
21
+ "astro": "^5.7",
22
22
  "vitest": "^2.1.8"
23
23
  },
24
24
  "exports": {
package/src/index.ts CHANGED
@@ -13,16 +13,23 @@ export const docsSchema = z.object({
13
13
  description: z.string().optional(),
14
14
  })
15
15
 
16
- export default (docsPaths: string[]): AstroIntegration => ({
16
+ export default (): AstroIntegration => ({
17
17
  name: 'shipyard-docs',
18
18
  hooks: {
19
- 'astro:config:setup': ({ injectRoute }) => {
20
- docsPaths.forEach((path) => {
19
+ 'astro:config:setup': ({ injectRoute, config }) => {
20
+ if (config.i18n) {
21
+ // With i18n: use locale prefix
21
22
  injectRoute({
22
- pattern: `/[locale]/${path}/[...slug]`,
23
+ pattern: `/[locale]/docs/[...slug]`,
23
24
  entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
24
25
  })
25
- })
26
+ } else {
27
+ // Without i18n: direct path
28
+ injectRoute({
29
+ pattern: `/docs/[...slug]`,
30
+ entrypoint: `@levino/shipyard-docs/astro/DocsEntry.astro`,
31
+ })
32
+ }
26
33
  },
27
34
  },
28
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>