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.
Files changed (147) hide show
  1. package/README.md +2 -1
  2. package/build/api/config/load.js +5 -5
  3. package/build/api/config/load.js.map +1 -1
  4. package/build/api/config-resolver/resolve.js +2 -2
  5. package/build/api/config-resolver/resolve.js.map +1 -1
  6. package/build/api/content/$$.d.ts +5 -0
  7. package/build/api/content/$$.d.ts.map +1 -0
  8. package/build/api/content/$$.js +5 -0
  9. package/build/api/content/$$.js.map +1 -0
  10. package/build/api/content/$.d.ts +2 -0
  11. package/build/api/content/$.d.ts.map +1 -0
  12. package/build/api/content/$.js +2 -0
  13. package/build/api/content/$.js.map +1 -0
  14. package/build/api/content/metadata.d.ts +10 -0
  15. package/build/api/content/metadata.d.ts.map +1 -0
  16. package/build/api/content/metadata.js +9 -0
  17. package/build/api/content/metadata.js.map +1 -0
  18. package/build/api/content/page.d.ts +11 -0
  19. package/build/api/content/page.d.ts.map +1 -0
  20. package/build/api/content/page.js +2 -0
  21. package/build/api/content/page.js.map +1 -0
  22. package/build/api/content/scan.d.ts +19 -0
  23. package/build/api/content/scan.d.ts.map +1 -0
  24. package/build/api/content/scan.js +57 -0
  25. package/build/api/content/scan.js.map +1 -0
  26. package/build/{lib/file-router/sidebar/types.d.ts → api/content/sidebar.d.ts} +8 -1
  27. package/build/api/content/sidebar.d.ts.map +1 -0
  28. package/build/api/content/sidebar.js +90 -0
  29. package/build/api/content/sidebar.js.map +1 -0
  30. package/build/api/schema/data-sources/schema-directory/schema-directory.js +1 -1
  31. package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
  32. package/build/api/vite/plugins/branding/index.js +4 -4
  33. package/build/api/vite/plugins/branding/index.js.map +1 -1
  34. package/build/api/vite/plugins/core.js +4 -4
  35. package/build/api/vite/plugins/core.js.map +1 -1
  36. package/build/api/vite/plugins/pages.d.ts +6 -8
  37. package/build/api/vite/plugins/pages.d.ts.map +1 -1
  38. package/build/api/vite/plugins/pages.js +99 -155
  39. package/build/api/vite/plugins/pages.js.map +1 -1
  40. package/build/api/vite/plugins/serve.js +5 -5
  41. package/build/api/vite/plugins/serve.js.map +1 -1
  42. package/build/cli/_/self-contained-mode.js +5 -5
  43. package/build/cli/_/self-contained-mode.js.map +1 -1
  44. package/build/exports/components.d.ts +2 -0
  45. package/build/exports/components.d.ts.map +1 -0
  46. package/build/exports/components.js +2 -0
  47. package/build/exports/components.js.map +1 -0
  48. package/build/lib/demos/config-schema.d.ts +14 -14
  49. package/build/lib/file-router/file-router.d.ts +0 -2
  50. package/build/lib/file-router/file-router.d.ts.map +1 -1
  51. package/build/lib/file-router/file-router.js +0 -2
  52. package/build/lib/file-router/file-router.js.map +1 -1
  53. package/build/lib/file-router/route.d.ts +2 -0
  54. package/build/lib/file-router/route.d.ts.map +1 -1
  55. package/build/lib/file-router/route.js.map +1 -1
  56. package/build/lib/file-router/scan.d.ts.map +1 -1
  57. package/build/lib/file-router/scan.js +16 -12
  58. package/build/lib/file-router/scan.js.map +1 -1
  59. package/build/singletons/debug.d.ts +1 -1
  60. package/build/singletons/debug.d.ts.map +1 -1
  61. package/build/singletons/debug.js +1 -1
  62. package/build/singletons/debug.js.map +1 -1
  63. package/build/template/components/ThemeToggle.d.ts +3 -0
  64. package/build/template/components/ThemeToggle.d.ts.map +1 -0
  65. package/build/template/components/ThemeToggle.jsx +10 -0
  66. package/build/template/components/ThemeToggle.jsx.map +1 -0
  67. package/build/template/components/content/$$.d.ts +2 -0
  68. package/build/template/components/content/$$.d.ts.map +1 -0
  69. package/build/template/components/content/$$.js +2 -0
  70. package/build/template/components/content/$$.js.map +1 -0
  71. package/build/template/components/sidebar/Sidebar.d.ts +2 -2
  72. package/build/template/components/sidebar/Sidebar.d.ts.map +1 -1
  73. package/build/template/components/sidebar/SidebarItem.d.ts +3 -3
  74. package/build/template/components/sidebar/SidebarItem.d.ts.map +1 -1
  75. package/build/template/components/sidebar/SidebarItem.jsx +1 -1
  76. package/build/template/components/sidebar/SidebarItem.jsx.map +1 -1
  77. package/build/template/contexts/ThemeContext.d.ts +12 -0
  78. package/build/template/contexts/ThemeContext.d.ts.map +1 -0
  79. package/build/template/contexts/ThemeContext.jsx +41 -0
  80. package/build/template/contexts/ThemeContext.jsx.map +1 -0
  81. package/build/template/routes/root.d.ts.map +1 -1
  82. package/build/template/routes/root.jsx +15 -9
  83. package/build/template/routes/root.jsx.map +1 -1
  84. package/package.json +10 -3
  85. package/src/api/config/load.ts +5 -5
  86. package/src/api/config-resolver/resolve.ts +2 -2
  87. package/src/api/content/$$.ts +4 -0
  88. package/src/api/content/$.test.ts +72 -0
  89. package/src/api/content/$.ts +1 -0
  90. package/src/api/content/metadata.ts +11 -0
  91. package/src/api/content/page.ts +12 -0
  92. package/src/api/content/scan.ts +82 -0
  93. package/src/api/content/sidebar.ts +136 -0
  94. package/src/api/schema/data-sources/schema-directory/schema-directory.ts +1 -1
  95. package/src/api/vite/plugins/branding/index.ts +4 -4
  96. package/src/api/vite/plugins/core.ts +4 -4
  97. package/src/api/vite/plugins/pages.ts +117 -171
  98. package/src/api/vite/plugins/serve.ts +5 -5
  99. package/src/cli/_/self-contained-mode.ts +5 -5
  100. package/src/exports/components.ts +1 -0
  101. package/src/lib/deployment/$$.ts +1 -1
  102. package/src/lib/deployment/$.test.ts +3 -3
  103. package/src/lib/deployment/$.ts +1 -1
  104. package/src/lib/file-router/file-router.ts +0 -2
  105. package/src/lib/file-router/linter.test.ts +2 -0
  106. package/src/lib/file-router/route.ts +2 -0
  107. package/src/lib/file-router/scan.ts +19 -13
  108. package/src/lib/task/$.test.ts +3 -3
  109. package/src/singletons/debug.ts +1 -1
  110. package/src/template/components/ThemeToggle.tsx +21 -0
  111. package/src/template/components/content/$$.ts +1 -0
  112. package/src/template/components/sidebar/Sidebar.tsx +2 -2
  113. package/src/template/components/sidebar/SidebarItem.tsx +8 -8
  114. package/src/template/contexts/ThemeContext.tsx +60 -0
  115. package/src/template/routes/root.tsx +15 -9
  116. package/build/lib/file-router/scan-tree.d.ts +0 -20
  117. package/build/lib/file-router/scan-tree.d.ts.map +0 -1
  118. package/build/lib/file-router/scan-tree.js +0 -158
  119. package/build/lib/file-router/scan-tree.js.map +0 -1
  120. package/build/lib/file-router/sidebar/index.d.ts +0 -3
  121. package/build/lib/file-router/sidebar/index.d.ts.map +0 -1
  122. package/build/lib/file-router/sidebar/index.js +0 -4
  123. package/build/lib/file-router/sidebar/index.js.map +0 -1
  124. package/build/lib/file-router/sidebar/sidebar-tree.d.ts +0 -9
  125. package/build/lib/file-router/sidebar/sidebar-tree.d.ts.map +0 -1
  126. package/build/lib/file-router/sidebar/sidebar-tree.js +0 -85
  127. package/build/lib/file-router/sidebar/sidebar-tree.js.map +0 -1
  128. package/build/lib/file-router/sidebar/types.d.ts.map +0 -1
  129. package/build/lib/file-router/sidebar/types.js +0 -2
  130. package/build/lib/file-router/sidebar/types.js.map +0 -1
  131. package/build/lib/tree/index.d.ts +0 -3
  132. package/build/lib/tree/index.d.ts.map +0 -1
  133. package/build/lib/tree/index.js +0 -2
  134. package/build/lib/tree/index.js.map +0 -1
  135. package/build/lib/tree/tree.d.ts +0 -62
  136. package/build/lib/tree/tree.d.ts.map +0 -1
  137. package/build/lib/tree/tree.js +0 -134
  138. package/build/lib/tree/tree.js.map +0 -1
  139. package/src/lib/file-router/scan-tree.test.ts +0 -189
  140. package/src/lib/file-router/scan-tree.ts +0 -205
  141. package/src/lib/file-router/sidebar/index.ts +0 -3
  142. package/src/lib/file-router/sidebar/sidebar-tree.test.ts +0 -123
  143. package/src/lib/file-router/sidebar/sidebar-tree.ts +0 -110
  144. package/src/lib/file-router/sidebar/types.ts +0 -19
  145. package/src/lib/tree/index.ts +0 -2
  146. package/src/lib/tree/tree.test.ts +0 -117
  147. 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 { debug as debugPolen } from '#singletons/debug'
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 { debug } from '#singletons/debug'
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 _debug = debug.sub('vite-plugin:branding')
19
- _debug('initialized')
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: _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 { debug } from '#singletons/debug'
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 _debug = debug.sub(`vite-plugin-core`)
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 = debug.sub(`vite-plugin:internal-import-alias`)
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
- _debug(`loadingViProjectDataVirtualModule`)
186
+ debug(`loadingViProjectDataVirtualModule`)
187
187
  const schema = await readSchema()
188
188
 
189
189
  // ━ Schema presence causes adding some navbar items