polen 0.10.0-next.4 → 0.10.0-next.6
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/README.md +2 -1
- package/build/api/config/load.js +5 -5
- package/build/api/config/load.js.map +1 -1
- package/build/api/config-resolver/resolve.js +2 -2
- package/build/api/config-resolver/resolve.js.map +1 -1
- package/build/api/content/$$.d.ts +5 -0
- package/build/api/content/$$.d.ts.map +1 -0
- package/build/api/content/$$.js +5 -0
- package/build/api/content/$$.js.map +1 -0
- package/build/api/content/$.d.ts +2 -0
- package/build/api/content/$.d.ts.map +1 -0
- package/build/api/content/$.js +2 -0
- package/build/api/content/$.js.map +1 -0
- package/build/api/content/metadata.d.ts +10 -0
- package/build/api/content/metadata.d.ts.map +1 -0
- package/build/api/content/metadata.js +9 -0
- package/build/api/content/metadata.js.map +1 -0
- package/build/api/content/page.d.ts +11 -0
- package/build/api/content/page.d.ts.map +1 -0
- package/build/api/content/page.js +2 -0
- package/build/api/content/page.js.map +1 -0
- package/build/api/content/scan.d.ts +19 -0
- package/build/api/content/scan.d.ts.map +1 -0
- package/build/api/content/scan.js +57 -0
- package/build/api/content/scan.js.map +1 -0
- package/build/{lib/file-router/sidebar/types.d.ts → api/content/sidebar.d.ts} +8 -1
- package/build/api/content/sidebar.d.ts.map +1 -0
- package/build/api/content/sidebar.js +90 -0
- package/build/api/content/sidebar.js.map +1 -0
- package/build/api/schema/data-sources/schema-directory/schema-directory.js +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
- package/build/api/vite/plugins/branding/index.js +4 -4
- package/build/api/vite/plugins/branding/index.js.map +1 -1
- package/build/api/vite/plugins/core.js +4 -4
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/pages.d.ts +6 -8
- package/build/api/vite/plugins/pages.d.ts.map +1 -1
- package/build/api/vite/plugins/pages.js +99 -155
- package/build/api/vite/plugins/pages.js.map +1 -1
- package/build/api/vite/plugins/serve.js +5 -5
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/cli/_/self-contained-mode.js +5 -5
- package/build/cli/_/self-contained-mode.js.map +1 -1
- package/build/exports/components.d.ts +2 -0
- package/build/exports/components.d.ts.map +1 -0
- package/build/exports/components.js +2 -0
- package/build/exports/components.js.map +1 -0
- package/build/lib/demos/config-schema.d.ts +14 -14
- package/build/lib/file-router/file-router.d.ts +0 -2
- package/build/lib/file-router/file-router.d.ts.map +1 -1
- package/build/lib/file-router/file-router.js +0 -2
- package/build/lib/file-router/file-router.js.map +1 -1
- package/build/lib/file-router/route.d.ts +2 -0
- package/build/lib/file-router/route.d.ts.map +1 -1
- package/build/lib/file-router/route.js.map +1 -1
- package/build/lib/file-router/scan.d.ts.map +1 -1
- package/build/lib/file-router/scan.js +16 -12
- package/build/lib/file-router/scan.js.map +1 -1
- package/build/singletons/debug.d.ts +1 -1
- package/build/singletons/debug.d.ts.map +1 -1
- package/build/singletons/debug.js +1 -1
- package/build/singletons/debug.js.map +1 -1
- package/build/template/components/ThemeToggle.d.ts +3 -0
- package/build/template/components/ThemeToggle.d.ts.map +1 -0
- package/build/template/components/ThemeToggle.jsx +10 -0
- package/build/template/components/ThemeToggle.jsx.map +1 -0
- package/build/template/components/content/$$.d.ts +2 -0
- package/build/template/components/content/$$.d.ts.map +1 -0
- package/build/template/components/content/$$.js +2 -0
- package/build/template/components/content/$$.js.map +1 -0
- package/build/template/components/sidebar/Sidebar.d.ts +2 -2
- package/build/template/components/sidebar/Sidebar.d.ts.map +1 -1
- package/build/template/components/sidebar/SidebarItem.d.ts +3 -3
- package/build/template/components/sidebar/SidebarItem.d.ts.map +1 -1
- package/build/template/components/sidebar/SidebarItem.jsx +1 -1
- package/build/template/components/sidebar/SidebarItem.jsx.map +1 -1
- package/build/template/contexts/ThemeContext.d.ts +12 -0
- package/build/template/contexts/ThemeContext.d.ts.map +1 -0
- package/build/template/contexts/ThemeContext.jsx +41 -0
- package/build/template/contexts/ThemeContext.jsx.map +1 -0
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.jsx +15 -9
- package/build/template/routes/root.jsx.map +1 -1
- package/package.json +10 -3
- package/src/api/config/load.ts +5 -5
- package/src/api/config-resolver/resolve.ts +2 -2
- package/src/api/content/$$.ts +4 -0
- package/src/api/content/$.test.ts +72 -0
- package/src/api/content/$.ts +1 -0
- package/src/api/content/metadata.ts +11 -0
- package/src/api/content/page.ts +12 -0
- package/src/api/content/scan.ts +82 -0
- package/src/api/content/sidebar.ts +136 -0
- package/src/api/schema/data-sources/schema-directory/schema-directory.ts +1 -1
- package/src/api/vite/plugins/branding/index.ts +4 -4
- package/src/api/vite/plugins/core.ts +4 -4
- package/src/api/vite/plugins/pages.ts +117 -171
- package/src/api/vite/plugins/serve.ts +5 -5
- package/src/cli/_/self-contained-mode.ts +5 -5
- package/src/exports/components.ts +1 -0
- package/src/lib/deployment/$$.ts +1 -1
- package/src/lib/deployment/$.test.ts +3 -3
- package/src/lib/deployment/$.ts +1 -1
- package/src/lib/file-router/file-router.ts +0 -2
- package/src/lib/file-router/linter.test.ts +2 -0
- package/src/lib/file-router/route.ts +2 -0
- package/src/lib/file-router/scan.ts +19 -13
- package/src/lib/task/$.test.ts +3 -3
- package/src/singletons/debug.ts +1 -1
- package/src/template/components/ThemeToggle.tsx +21 -0
- package/src/template/components/content/$$.ts +1 -0
- package/src/template/components/sidebar/Sidebar.tsx +2 -2
- package/src/template/components/sidebar/SidebarItem.tsx +8 -8
- package/src/template/contexts/ThemeContext.tsx +60 -0
- package/src/template/routes/root.tsx +15 -9
- package/build/lib/file-router/scan-tree.d.ts +0 -20
- package/build/lib/file-router/scan-tree.d.ts.map +0 -1
- package/build/lib/file-router/scan-tree.js +0 -158
- package/build/lib/file-router/scan-tree.js.map +0 -1
- package/build/lib/file-router/sidebar/index.d.ts +0 -3
- package/build/lib/file-router/sidebar/index.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/index.js +0 -4
- package/build/lib/file-router/sidebar/index.js.map +0 -1
- package/build/lib/file-router/sidebar/sidebar-tree.d.ts +0 -9
- package/build/lib/file-router/sidebar/sidebar-tree.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/sidebar-tree.js +0 -85
- package/build/lib/file-router/sidebar/sidebar-tree.js.map +0 -1
- package/build/lib/file-router/sidebar/types.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/types.js +0 -2
- package/build/lib/file-router/sidebar/types.js.map +0 -1
- package/build/lib/tree/index.d.ts +0 -3
- package/build/lib/tree/index.d.ts.map +0 -1
- package/build/lib/tree/index.js +0 -2
- package/build/lib/tree/index.js.map +0 -1
- package/build/lib/tree/tree.d.ts +0 -62
- package/build/lib/tree/tree.d.ts.map +0 -1
- package/build/lib/tree/tree.js +0 -134
- package/build/lib/tree/tree.js.map +0 -1
- package/src/lib/file-router/scan-tree.test.ts +0 -189
- package/src/lib/file-router/scan-tree.ts +0 -205
- package/src/lib/file-router/sidebar/index.ts +0 -3
- package/src/lib/file-router/sidebar/sidebar-tree.test.ts +0 -123
- package/src/lib/file-router/sidebar/sidebar-tree.ts +0 -110
- package/src/lib/file-router/sidebar/types.ts +0 -19
- package/src/lib/tree/index.ts +0 -2
- package/src/lib/tree/tree.test.ts +0 -117
- package/src/lib/tree/tree.ts +0 -183
@@ -0,0 +1,82 @@
|
|
1
|
+
import { FileRouter } from '#lib/file-router/index'
|
2
|
+
import { Fs, Path, Tree } from '@wollybeard/kit'
|
3
|
+
import matter from 'gray-matter'
|
4
|
+
import { MetadataSchema } from './metadata.ts'
|
5
|
+
import type { Page } from './page.ts'
|
6
|
+
|
7
|
+
export interface ScanResult {
|
8
|
+
list: Page[]
|
9
|
+
tree: Tree.Tree<Page>
|
10
|
+
diagnostics: FileRouter.Diagnostic[]
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Scan a directory for pages and extract metadata from their front matter
|
15
|
+
* By default, hidden pages are filtered out from both the pages list and route tree.
|
16
|
+
*/
|
17
|
+
export const scan = async (options: {
|
18
|
+
dir: string
|
19
|
+
glob?: string
|
20
|
+
/** Include hidden pages in the result (useful for debugging or admin interfaces) */
|
21
|
+
includeHidden?: boolean
|
22
|
+
}): Promise<ScanResult> => {
|
23
|
+
// Scan for routes
|
24
|
+
const routeScanResult = await FileRouter.scan({
|
25
|
+
dir: options.dir,
|
26
|
+
glob: options.glob ?? '**/*.{md,mdx}',
|
27
|
+
})
|
28
|
+
|
29
|
+
// Create pages with metadata (id/parentId now come from route)
|
30
|
+
const allPages = await Promise.all(
|
31
|
+
routeScanResult.routes.map(route => readRoute(route)),
|
32
|
+
)
|
33
|
+
|
34
|
+
// Apply filtering if needed
|
35
|
+
const pages = options.includeHidden
|
36
|
+
? allPages
|
37
|
+
: allPages.filter(page => !page.metadata.hidden)
|
38
|
+
|
39
|
+
// Build tree from pages using Tree.fromList
|
40
|
+
// Transform pages to include id/parentId at the top level for Tree.fromList
|
41
|
+
const pagesWithIds = pages.map(page => ({
|
42
|
+
...page,
|
43
|
+
id: page.route.id,
|
44
|
+
parentId: page.route.parentId,
|
45
|
+
}))
|
46
|
+
|
47
|
+
const tree = Tree.fromList(pagesWithIds)
|
48
|
+
|
49
|
+
return {
|
50
|
+
list: pages,
|
51
|
+
tree,
|
52
|
+
diagnostics: routeScanResult.diagnostics,
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Read a single route file and extract metadata from its front matter
|
58
|
+
*/
|
59
|
+
const readRoute = async (route: FileRouter.Route): Promise<Page> => {
|
60
|
+
const filePath = Path.format(route.file.path.absolute)
|
61
|
+
const fileContent = await Fs.read(filePath)
|
62
|
+
|
63
|
+
// Empty files still get default metadata (not hidden by default)
|
64
|
+
// This allows placeholder pages to exist in the navigation
|
65
|
+
if (!fileContent) {
|
66
|
+
return { route, metadata: { hidden: false } }
|
67
|
+
}
|
68
|
+
|
69
|
+
// Parse front matter
|
70
|
+
const { data } = matter(fileContent)
|
71
|
+
|
72
|
+
// Validate and parse the data
|
73
|
+
const parsed = MetadataSchema.safeParse(data)
|
74
|
+
|
75
|
+
if (!parsed.success) {
|
76
|
+
// Log warning but continue with defaults
|
77
|
+
console.warn(`Invalid front matter in ${filePath}:`, parsed.error.issues)
|
78
|
+
}
|
79
|
+
|
80
|
+
const metadata = parsed.success ? parsed.data : { hidden: false }
|
81
|
+
return { route, metadata }
|
82
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { FileRouter } from '#lib/file-router/index'
|
2
|
+
import { Tree } from '@wollybeard/kit'
|
3
|
+
import { Str } from '@wollybeard/kit'
|
4
|
+
import type { Page } from './page.ts'
|
5
|
+
|
6
|
+
export interface Sidebar {
|
7
|
+
items: Item[]
|
8
|
+
}
|
9
|
+
|
10
|
+
export type Item = ItemLink | ItemSection
|
11
|
+
|
12
|
+
export interface ItemLink {
|
13
|
+
type: `ItemLink`
|
14
|
+
title: string
|
15
|
+
pathExp: string
|
16
|
+
}
|
17
|
+
|
18
|
+
export interface ItemSection {
|
19
|
+
type: `ItemSection`
|
20
|
+
title: string
|
21
|
+
pathExp: string
|
22
|
+
isLinkToo: boolean
|
23
|
+
links: ItemLink[]
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Build sidebar from page tree structure
|
28
|
+
*/
|
29
|
+
export const buildFromPageTree = (pageTree: Tree.Tree<Page>, basePath: FileRouter.Path): Sidebar => {
|
30
|
+
const links: ItemLink[] = []
|
31
|
+
const sections: ItemSection[] = []
|
32
|
+
|
33
|
+
// Process only the children of the root node
|
34
|
+
if (pageTree.root) {
|
35
|
+
for (const child of pageTree.root.children) {
|
36
|
+
processPageNode(child, basePath, [], links, sections)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
const items = [...links, ...sections]
|
41
|
+
|
42
|
+
return {
|
43
|
+
items,
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
const processPageNode = (
|
48
|
+
node: Tree.Node<Page>,
|
49
|
+
basePath: FileRouter.Path,
|
50
|
+
parentPath: string[],
|
51
|
+
links: ItemLink[],
|
52
|
+
sections: ItemSection[],
|
53
|
+
): void => {
|
54
|
+
const page = node.value
|
55
|
+
const routeName = page.route.logical.path.slice(-1)[0] || 'index'
|
56
|
+
const currentPath = [...parentPath, routeName]
|
57
|
+
|
58
|
+
// If this page has children, treat it as a section
|
59
|
+
if (node.children.length > 0) {
|
60
|
+
const sectionPath = [...basePath, ...currentPath]
|
61
|
+
const sectionPathExp = FileRouter.pathToExpression(sectionPath)
|
62
|
+
const sectionTitle = Str.titlizeSlug(routeName)
|
63
|
+
|
64
|
+
// Check if any child is an index page
|
65
|
+
const hasIndexChild = node.children.some(child => isIndexPage(child.value))
|
66
|
+
|
67
|
+
const section: ItemSection = {
|
68
|
+
type: `ItemSection`,
|
69
|
+
title: sectionTitle,
|
70
|
+
pathExp: sectionPathExp.startsWith('/') ? sectionPathExp.slice(1) : sectionPathExp,
|
71
|
+
isLinkToo: hasIndexChild, // Section is linkable if it has an index page
|
72
|
+
links: [],
|
73
|
+
}
|
74
|
+
|
75
|
+
// Process all children as links for this section
|
76
|
+
for (const child of node.children) {
|
77
|
+
const childPage = child.value
|
78
|
+
|
79
|
+
if (child.children.length > 0) {
|
80
|
+
// This child has children - only collect its descendants, not the child itself
|
81
|
+
collectPagesFromNode(child, basePath, section.links)
|
82
|
+
} else if (!childPage.metadata.hidden && !isIndexPage(childPage)) {
|
83
|
+
// This is a leaf node - add it as a link
|
84
|
+
section.links.push(pageToItemLink(childPage, basePath))
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
sections.push(section)
|
89
|
+
} else {
|
90
|
+
// This is a standalone file - add as top-level link
|
91
|
+
if (!page.metadata.hidden && !isIndexPage(page)) {
|
92
|
+
links.push(pageToItemLink(page, basePath))
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
const collectPagesFromNode = (
|
98
|
+
node: Tree.Node<Page>,
|
99
|
+
basePath: FileRouter.Path,
|
100
|
+
links: ItemLink[],
|
101
|
+
): void => {
|
102
|
+
// Only process children, not the node itself (to avoid double-adding intermediate directories)
|
103
|
+
for (const child of node.children) {
|
104
|
+
const childPage = child.value
|
105
|
+
if (childPage && !childPage.metadata.hidden && !isIndexPage(childPage)) {
|
106
|
+
links.push(pageToItemLink(childPage, basePath))
|
107
|
+
}
|
108
|
+
|
109
|
+
// Recursively process grandchildren
|
110
|
+
if (child.children.length > 0) {
|
111
|
+
collectPagesFromNode(child, basePath, links)
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
const pageToItemLink = (page: Page, basePath: FileRouter.Path): ItemLink => {
|
117
|
+
const pagePathExp = FileRouter.routeToPathExpression(page.route)
|
118
|
+
const pageRelative = FileRouter.makeRelativeUnsafe(page.route, basePath)
|
119
|
+
const pageRelativePathExp = FileRouter.routeToPathExpression(pageRelative)
|
120
|
+
|
121
|
+
// Remove leading slash for title generation
|
122
|
+
const titlePath = pageRelativePathExp.startsWith('/') ? pageRelativePathExp.slice(1) : pageRelativePathExp
|
123
|
+
|
124
|
+
// Use only the last segment for the title
|
125
|
+
const titleSegment = pageRelative.logical.path[pageRelative.logical.path.length - 1] || titlePath
|
126
|
+
|
127
|
+
return {
|
128
|
+
type: `ItemLink`,
|
129
|
+
pathExp: pagePathExp.startsWith('/') ? pagePathExp.slice(1) : pagePathExp,
|
130
|
+
title: Str.titlizeSlug(titleSegment),
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
const isIndexPage = (page: Page): boolean => {
|
135
|
+
return page.route.file.path.relative.name === 'index'
|
136
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Grafaid } from '#lib/grafaid/index'
|
2
2
|
import { GraphqlChange } from '#lib/graphql-change/index'
|
3
3
|
import type { GraphqlChangeset } from '#lib/graphql-changeset/index'
|
4
|
-
import {
|
4
|
+
import { debugPolen } from '#singletons/debug'
|
5
5
|
import { Arr, Path } from '@wollybeard/kit'
|
6
6
|
import { glob } from 'tinyglobby'
|
7
7
|
import type { Schema } from '../../schema.ts'
|
@@ -2,7 +2,7 @@ import type { Config } from '#api/api'
|
|
2
2
|
import { polenVirtual } from '#api/vite/vi'
|
3
3
|
import type { Vite } from '#dep/vite/index'
|
4
4
|
import { type ExistenceDiff, getMutationType, MutationType } from '#lib/mutation-type'
|
5
|
-
import {
|
5
|
+
import { debugPolen } from '#singletons/debug'
|
6
6
|
import { Fs } from '@wollybeard/kit'
|
7
7
|
import type { Plugin } from 'vite'
|
8
8
|
|
@@ -15,8 +15,8 @@ const generateDefaultLogo = async () => {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
export function Branding(config: Config.Config): Plugin {
|
18
|
-
const
|
19
|
-
|
18
|
+
const debug = debugPolen.sub('vite-plugin:branding')
|
19
|
+
debug('initialized')
|
20
20
|
|
21
21
|
return {
|
22
22
|
name: 'polen:branding',
|
@@ -32,7 +32,7 @@ export function Branding(config: Config.Config): Plugin {
|
|
32
32
|
changedFile: file,
|
33
33
|
moduleId: viLogo.resolved,
|
34
34
|
server,
|
35
|
-
debug:
|
35
|
+
debug: debug,
|
36
36
|
})
|
37
37
|
},
|
38
38
|
|
@@ -6,7 +6,7 @@ import type { Vite } from '#dep/vite/index'
|
|
6
6
|
import { VitePluginJson } from '#lib/vite-plugin-json/index'
|
7
7
|
import { VitePluginReactiveData } from '#lib/vite-plugin-reactive-data/index'
|
8
8
|
import { ViteVirtual } from '#lib/vite-virtual/index'
|
9
|
-
import {
|
9
|
+
import { debugPolen } from '#singletons/debug'
|
10
10
|
import { superjson } from '#singletons/superjson'
|
11
11
|
import { Json, Str } from '@wollybeard/kit'
|
12
12
|
import type { ProjectData } from '../../../project-data.ts'
|
@@ -16,7 +16,7 @@ import { createLogger } from '../logger.ts'
|
|
16
16
|
import { polenVirtual } from '../vi.ts'
|
17
17
|
import { Pages } from './pages.ts'
|
18
18
|
|
19
|
-
const
|
19
|
+
const debug = debugPolen.sub(`vite-plugin-core`)
|
20
20
|
|
21
21
|
const viTemplateVariables = polenVirtual([`template`, `variables`])
|
22
22
|
const viTemplateSchemaAugmentations = polenVirtual([`template`, `schema-augmentations`])
|
@@ -87,7 +87,7 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
87
87
|
name: `polen:internal-import-alias`,
|
88
88
|
enforce: 'pre' as const,
|
89
89
|
resolveId(id, importer) {
|
90
|
-
const d =
|
90
|
+
const d = debugPolen.sub(`vite-plugin:internal-import-alias`)
|
91
91
|
|
92
92
|
const isPolenImporter = Boolean(
|
93
93
|
importer
|
@@ -183,7 +183,7 @@ export const Core = (config: Config.Config): Vite.PluginOption[] => {
|
|
183
183
|
{
|
184
184
|
identifier: viProjectData,
|
185
185
|
async loader() {
|
186
|
-
|
186
|
+
debug(`loadingViProjectDataVirtualModule`)
|
187
187
|
const schema = await readSchema()
|
188
188
|
|
189
189
|
// ━ Schema presence causes adding some navbar items
|