@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.
@@ -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>
@@ -1,25 +1,25 @@
1
1
  ---
2
- import Layout from "./Layout.astro";
3
- import { getCollection, render } from "astro:content";
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("/") : undefined,
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>
@@ -1,43 +1,44 @@
1
1
  ---
2
- import { getCollection, render } from "astro:content";
3
- import BaseLayout from "@levino/shipyard-base/layouts/Page.astro";
4
- import { toSidebarEntries } from "../src/sidebarEntries";
5
- import { path } from "ramda";
6
- import type { NavigationTree } from "@levino/shipyard-base";
7
- import { Array, Option } from "effect";
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 locale = Astro.currentLocale as string;
10
- const docs = await getCollection("docs")
9
+ const getPath = (id: string) => `/${Astro.currentLocale}/docs/${id.slice(3)}`
10
+
11
+ const docs = await getCollection('docs')
11
12
  .then(
12
- Array.map(async (doc) => {
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: `/${locale}/docs/${id.slice(3)}`,
22
+ path: getPath(id),
22
23
  title:
23
24
  label ??
24
25
  title ??
25
26
  Option.getOrUndefined(
26
- Array.findFirst(
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.bind(Promise));
37
+ .then((promises) => Promise.all(promises))
37
38
 
38
- const entries = path([locale, "subEntry", "docs", "subEntry"])(
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.2.1",
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.3.0"
16
+ "@levino/shipyard-base": "^0.5.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@tailwindcss/typography": "^0.5.16",
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, test } from 'vitest'
2
2
  import { toSidebarEntries } from './sidebarEntries'
3
+
3
4
  describe('Sidebar subEntry helpers', () => {
4
5
  test.each([
5
6
  [
@@ -1,5 +1,6 @@
1
1
  import type { Entry } from '@levino/shipyard-base'
2
2
  import { mergeDeepLeft } from 'ramda'
3
+
3
4
  interface DocsData {
4
5
  title: string
5
6
  path: string