@uniweb/core 0.3.2 → 0.3.4
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 +1 -1
- package/src/page.js +1 -0
- package/src/uniweb.js +14 -0
- package/src/website.js +11 -35
package/package.json
CHANGED
package/src/page.js
CHANGED
|
@@ -22,6 +22,7 @@ export default class Page {
|
|
|
22
22
|
this.route = pageData.route
|
|
23
23
|
this.sourcePath = pageData.sourcePath || null // Original folder-based path (for ancestor checking)
|
|
24
24
|
this.isIndex = pageData.isIndex || false // True if this page is the index for its parent route
|
|
25
|
+
this.parentRoute = pageData.parent || null // Declared parent route for hierarchy linking (set by build)
|
|
25
26
|
this.title = pageData.title || ''
|
|
26
27
|
this.description = pageData.description || ''
|
|
27
28
|
this.label = pageData.label || null // Short label for navigation (null = use title)
|
package/src/uniweb.js
CHANGED
|
@@ -22,6 +22,10 @@ export default class Uniweb {
|
|
|
22
22
|
// Set by runtime based on site config
|
|
23
23
|
this.iconResolver = null
|
|
24
24
|
|
|
25
|
+
// Pre-populated icon cache for SSR: Map<"family:name", svgString>
|
|
26
|
+
// Populated by prerender before rendering, read synchronously by Icon component
|
|
27
|
+
this.iconCache = new Map()
|
|
28
|
+
|
|
25
29
|
// Initialize analytics (disabled by default, configure via site config)
|
|
26
30
|
this.analytics = new Analytics(configData.analytics || {})
|
|
27
31
|
}
|
|
@@ -40,6 +44,16 @@ export default class Uniweb {
|
|
|
40
44
|
return this.iconResolver(library, name)
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Get a cached icon synchronously (for SSR/prerender)
|
|
49
|
+
* @param {string} library - Icon family code
|
|
50
|
+
* @param {string} name - Icon name
|
|
51
|
+
* @returns {string|null} SVG string or null if not cached
|
|
52
|
+
*/
|
|
53
|
+
getIconSync(library, name) {
|
|
54
|
+
return this.iconCache.get(`${library}:${name}`) || null
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
/**
|
|
44
58
|
* Set the foundation module after loading
|
|
45
59
|
* @param {Object} foundation - The loaded ESM foundation module
|
package/src/website.js
CHANGED
|
@@ -128,48 +128,23 @@ export default class Website {
|
|
|
128
128
|
* @private
|
|
129
129
|
*/
|
|
130
130
|
buildPageHierarchy() {
|
|
131
|
-
//
|
|
132
|
-
const sortedPages = [...this.pages].sort((a, b) => {
|
|
133
|
-
const depthA = (a.route.match(/\//g) || []).length
|
|
134
|
-
const depthB = (b.route.match(/\//g) || []).length
|
|
135
|
-
return depthA - depthB
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
// Build a map of route to page for quick lookup
|
|
139
|
-
// Include both actual routes and nav routes (for index pages)
|
|
131
|
+
// Build a map of route to page for parent lookup
|
|
140
132
|
const pageMap = new Map()
|
|
141
|
-
for (const page of
|
|
133
|
+
for (const page of this.pages) {
|
|
142
134
|
pageMap.set(page.route, page)
|
|
143
|
-
// Also map the nav route for index pages so parent lookup works
|
|
144
|
-
if (page.isIndex) {
|
|
145
|
-
const navRoute = page.getNavRoute()
|
|
146
|
-
if (navRoute !== page.route) {
|
|
147
|
-
pageMap.set(navRoute, page)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
135
|
}
|
|
151
136
|
|
|
152
|
-
//
|
|
153
|
-
for (const page of
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// /docs/getting-started -> /docs
|
|
161
|
-
const parentRoute = '/' + segments.slice(0, -1).join('/')
|
|
162
|
-
const parent = pageMap.get(parentRoute)
|
|
163
|
-
|
|
164
|
-
if (parent) {
|
|
165
|
-
parent.children.push(page)
|
|
166
|
-
page.parent = parent
|
|
137
|
+
// Link pages using the declared parent route (set by build)
|
|
138
|
+
for (const page of this.pages) {
|
|
139
|
+
if (page.parentRoute) {
|
|
140
|
+
const parent = pageMap.get(page.parentRoute)
|
|
141
|
+
if (parent) {
|
|
142
|
+
parent.children.push(page)
|
|
143
|
+
page.parent = parent
|
|
144
|
+
}
|
|
167
145
|
}
|
|
168
146
|
}
|
|
169
147
|
|
|
170
|
-
// Note: Pages arrive pre-sorted from build time.
|
|
171
|
-
// The hierarchy is hydrated from that order - no runtime sorting needed.
|
|
172
|
-
|
|
173
148
|
// Build page ID map for makeHref() resolution
|
|
174
149
|
// Supports both explicit IDs and route-based lookup
|
|
175
150
|
this._pageIdMap = new Map()
|
|
@@ -796,6 +771,7 @@ export default class Website {
|
|
|
796
771
|
label: page.getLabel(),
|
|
797
772
|
description: page.description,
|
|
798
773
|
hasContent: page.hasContent(),
|
|
774
|
+
version: page.version || null, // Version metadata for filtering by version
|
|
799
775
|
children: nested && page.hasChildren()
|
|
800
776
|
? page.children.filter(isPageVisible).map(buildPageInfo)
|
|
801
777
|
: []
|