@oneie/plugin-docs 0.1.0 → 0.1.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/package.json +2 -7
- package/src/DocsLayout.astro +25 -4
- package/src/index.ts +36 -8
- package/tsconfig.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/plugin-docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "ONE docs — Astro content collection with sidebar nav, search, code blocks, and versioning",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -15,17 +15,12 @@
|
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"astro": ">=6.0.0",
|
|
18
|
-
"@oneie/frontend": "
|
|
18
|
+
"@oneie/frontend": "^0.1.1",
|
|
19
19
|
"react": ">=19.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"astro": "^6.2.2",
|
|
23
23
|
"react": "^19.0.0",
|
|
24
24
|
"typescript": "^5.7.3"
|
|
25
|
-
},
|
|
26
|
-
"peerDependenciesMeta": {
|
|
27
|
-
"@oneie/frontend": {
|
|
28
|
-
"optional": true
|
|
29
|
-
}
|
|
30
25
|
}
|
|
31
26
|
}
|
package/src/DocsLayout.astro
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { CollectionEntry, MarkdownHeading } from 'astro:content'
|
|
3
|
+
import { getCollection, render } from 'astro:content'
|
|
3
4
|
import { SidebarDocs } from './SidebarDocs.tsx'
|
|
4
5
|
import { DocSearch } from './DocSearch.tsx'
|
|
5
6
|
|
|
6
7
|
export interface Props {
|
|
7
|
-
entry
|
|
8
|
-
|
|
8
|
+
/** Omit both `entry` and `entries` when this file is used directly as an
|
|
9
|
+
* injected route — it then self-resolves from Astro.params.slug and
|
|
10
|
+
* renders its own <Content/> in place of the default slot. Pass them
|
|
11
|
+
* explicitly when wrapping this layout in your own page. */
|
|
12
|
+
entry?: CollectionEntry<'docs'>
|
|
13
|
+
entries?: CollectionEntry<'docs'>[]
|
|
9
14
|
headings?: MarkdownHeading[]
|
|
10
15
|
editBaseUrl?: string
|
|
11
16
|
sidebar?: Array<{ folder: string; label: string; icon?: string }>
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
let { entry, entries, headings, editBaseUrl, sidebar } = Astro.props
|
|
20
|
+
let Content: (() => any) | undefined
|
|
21
|
+
|
|
22
|
+
if (!entry) {
|
|
23
|
+
const slug = Astro.params.slug as string
|
|
24
|
+
const all = await getCollection('docs')
|
|
25
|
+
const found = all.find((d) => d.id === slug)
|
|
26
|
+
if (!found) return Astro.redirect('/docs')
|
|
27
|
+
entry = found
|
|
28
|
+
entries = all
|
|
29
|
+
const rendered = await render(entry)
|
|
30
|
+
Content = rendered.Content
|
|
31
|
+
headings ??= rendered.headings
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
entries ??= []
|
|
35
|
+
headings ??= []
|
|
15
36
|
|
|
16
37
|
const searchQuery = Astro.url.searchParams.get('search') ?? ''
|
|
17
38
|
|
|
@@ -70,7 +91,7 @@ const tocHeadings = headings.filter((h) => h.depth === 2 || h.depth === 3)
|
|
|
70
91
|
<p class="mb-8 text-lg text-muted-foreground">{entry.data.description}</p>
|
|
71
92
|
)}
|
|
72
93
|
<div class="prose prose-slate dark:prose-invert max-w-none">
|
|
73
|
-
<slot />
|
|
94
|
+
{Content ? <Content /> : <slot />}
|
|
74
95
|
</div>
|
|
75
96
|
|
|
76
97
|
<!-- Edit this page -->
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro'
|
|
1
2
|
import type { OnePluginFactory } from '@oneie/frontend'
|
|
2
3
|
|
|
3
4
|
export interface SidebarFolder {
|
|
@@ -17,12 +18,39 @@ export interface OneDocsConfig {
|
|
|
17
18
|
editBaseUrl?: string
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const defaults: Required<Pick<OneDocsConfig, 'injectRoutes'>> = {
|
|
22
|
+
injectRoutes: true,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const docs: OnePluginFactory<OneDocsConfig> = (config = {}) => {
|
|
26
|
+
const resolved = { ...defaults, ...config }
|
|
27
|
+
|
|
28
|
+
const integration = (): AstroIntegration => ({
|
|
29
|
+
name: '@oneie/plugin-docs',
|
|
30
|
+
hooks: {
|
|
31
|
+
'astro:config:setup': ({ injectRoute }) => {
|
|
32
|
+
if (resolved.injectRoutes) {
|
|
33
|
+
injectRoute({
|
|
34
|
+
pattern: '/docs',
|
|
35
|
+
entrypoint: '@oneie/plugin-docs/DocsIndex.astro',
|
|
36
|
+
})
|
|
37
|
+
injectRoute({
|
|
38
|
+
pattern: '/docs/[slug]',
|
|
39
|
+
entrypoint: '@oneie/plugin-docs/DocsLayout.astro',
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: 'plugin-docs',
|
|
48
|
+
tier: 'free',
|
|
49
|
+
config: undefined,
|
|
50
|
+
integration,
|
|
51
|
+
entitlement: undefined,
|
|
52
|
+
serves: undefined,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
27
55
|
|
|
28
|
-
export type { OneDocsConfig as DocsConfig
|
|
56
|
+
export type { OneDocsConfig as DocsConfig }
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "../tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"jsx": "react-jsx",
|
|
5
5
|
"jsxImportSource": "react",
|
|
6
6
|
"paths": {
|
|
7
|
-
"@/*": ["../../
|
|
7
|
+
"@/*": ["../../template/site/src/*"]
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
"include": ["src"]
|