methanol 0.0.20 → 0.0.21
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/build-system.js +22 -48
- package/src/config.js +3 -0
- package/src/feed.js +3 -12
- package/src/mdx.js +2 -1
- package/src/pages-index.js +10 -1
- package/src/state.js +9 -3
- package/src/workers/build-worker.js +14 -37
- package/themes/default/src/nav-tree.jsx +3 -2
package/package.json
CHANGED
package/src/build-system.js
CHANGED
|
@@ -101,6 +101,8 @@ export const buildHtmlEntries = async () => {
|
|
|
101
101
|
const excludedDirs = Array.from(pagesContext.excludedDirs || [])
|
|
102
102
|
const rssContent = new Map()
|
|
103
103
|
const intermediateOutputs = []
|
|
104
|
+
let feedIds = []
|
|
105
|
+
let feedAssignments = null
|
|
104
106
|
try {
|
|
105
107
|
await runWorkerStage({
|
|
106
108
|
workers,
|
|
@@ -168,6 +170,18 @@ export const buildHtmlEntries = async () => {
|
|
|
168
170
|
}
|
|
169
171
|
}))
|
|
170
172
|
})
|
|
173
|
+
if (state.RSS_ENABLED) {
|
|
174
|
+
const feedPages = selectFeedPages(pages, state.RSS_OPTIONS || {})
|
|
175
|
+
const pageIndex = new Map(pages.map((page, index) => [page, index]))
|
|
176
|
+
feedIds = feedPages.map((page) => pageIndex.get(page)).filter((id) => id != null)
|
|
177
|
+
if (feedIds.length) {
|
|
178
|
+
feedAssignments = Array.from({ length: workers.length }, () => [])
|
|
179
|
+
for (const id of feedIds) {
|
|
180
|
+
feedAssignments[id % workers.length].push(id)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
171
185
|
const renderToken = stageLogger.start('Rendering pages')
|
|
172
186
|
completed = 0
|
|
173
187
|
await runWorkerStage({
|
|
@@ -178,7 +192,8 @@ export const buildHtmlEntries = async () => {
|
|
|
178
192
|
message: {
|
|
179
193
|
type: 'render',
|
|
180
194
|
stage: 'render',
|
|
181
|
-
ids: assignments[index]
|
|
195
|
+
ids: assignments[index],
|
|
196
|
+
feedIds: feedAssignments ? feedAssignments[index] : []
|
|
182
197
|
}
|
|
183
198
|
})),
|
|
184
199
|
onProgress: (count) => {
|
|
@@ -198,56 +213,15 @@ export const buildHtmlEntries = async () => {
|
|
|
198
213
|
if (state.INTERMEDIATE_DIR) {
|
|
199
214
|
intermediateOutputs.push({ name, id })
|
|
200
215
|
}
|
|
216
|
+
if (result.feedContent != null) {
|
|
217
|
+
const key = page.path || page.routePath
|
|
218
|
+
if (key) {
|
|
219
|
+
rssContent.set(key, result.feedContent || '')
|
|
220
|
+
}
|
|
221
|
+
}
|
|
201
222
|
}
|
|
202
223
|
})
|
|
203
224
|
stageLogger.end(renderToken)
|
|
204
|
-
|
|
205
|
-
if (state.RSS_ENABLED) {
|
|
206
|
-
const feedPages = selectFeedPages(pages, state.RSS_OPTIONS || {})
|
|
207
|
-
const feedIds = []
|
|
208
|
-
const pageIndex = new Map(pages.map((page, index) => [page, index]))
|
|
209
|
-
for (const page of feedPages) {
|
|
210
|
-
const id = pageIndex.get(page)
|
|
211
|
-
if (id != null) {
|
|
212
|
-
feedIds.push(id)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (feedIds.length) {
|
|
216
|
-
const rssToken = stageLogger.start('Rendering feed')
|
|
217
|
-
completed = 0
|
|
218
|
-
const rssAssignments = Array.from({ length: workers.length }, () => [])
|
|
219
|
-
for (let i = 0; i < feedIds.length; i += 1) {
|
|
220
|
-
rssAssignments[i % workers.length].push(feedIds[i])
|
|
221
|
-
}
|
|
222
|
-
await runWorkerStage({
|
|
223
|
-
workers,
|
|
224
|
-
stage: 'rss',
|
|
225
|
-
messages: workers.map((worker, index) => ({
|
|
226
|
-
worker,
|
|
227
|
-
message: {
|
|
228
|
-
type: 'rss',
|
|
229
|
-
stage: 'rss',
|
|
230
|
-
ids: rssAssignments[index]
|
|
231
|
-
}
|
|
232
|
-
})),
|
|
233
|
-
onProgress: (count) => {
|
|
234
|
-
if (!logEnabled) return
|
|
235
|
-
completed = count
|
|
236
|
-
stageLogger.update(rssToken, `Rendering feed [${completed}/${feedIds.length}]`)
|
|
237
|
-
},
|
|
238
|
-
onResult: (result) => {
|
|
239
|
-
if (!result || typeof result.id !== 'number') return
|
|
240
|
-
const page = pages[result.id]
|
|
241
|
-
if (!page) return
|
|
242
|
-
const key = page.path || page.routePath
|
|
243
|
-
if (key) {
|
|
244
|
-
rssContent.set(key, result.content || '')
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
})
|
|
248
|
-
stageLogger.end(rssToken)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
225
|
} finally {
|
|
252
226
|
await terminateWorkers(workers)
|
|
253
227
|
}
|
package/src/config.js
CHANGED
|
@@ -461,6 +461,9 @@ export const applyConfig = async (config, mode) => {
|
|
|
461
461
|
state.RSS_ENABLED = cli.CLI_RSS
|
|
462
462
|
}
|
|
463
463
|
state.RSS_OPTIONS = resolveFeedOptions(config)
|
|
464
|
+
if (cli.CLI_RSS !== undefined && cli.CLI_ATOM === undefined) {
|
|
465
|
+
state.RSS_OPTIONS = { ...(state.RSS_OPTIONS || {}), atom: false }
|
|
466
|
+
}
|
|
464
467
|
if (cli.CLI_ATOM !== undefined) {
|
|
465
468
|
if (cli.CLI_ATOM === true) {
|
|
466
469
|
state.RSS_ENABLED = true
|
package/src/feed.js
CHANGED
|
@@ -63,15 +63,6 @@ const wrapCdata = (value) => {
|
|
|
63
63
|
return `<![CDATA[${text.replace(/]]>/g, ']]]]><![CDATA[>')}]]>`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const escapeXml = (value) => {
|
|
67
|
-
const text = value == null ? '' : String(value)
|
|
68
|
-
if (!text) return ''
|
|
69
|
-
return text
|
|
70
|
-
.replace(/&/g, '&')
|
|
71
|
-
.replace(/</g, '<')
|
|
72
|
-
.replace(/>/g, '>')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
66
|
const resolveSiteUrl = (options, site) => {
|
|
76
67
|
if (options?.siteUrl) return options.siteUrl
|
|
77
68
|
if (state.SITE_BASE) return state.SITE_BASE
|
|
@@ -86,10 +77,10 @@ const buildItem = (page, siteUrl, htmlContent = null, isAtom = false, siteOwner
|
|
|
86
77
|
const link = new URL(href, siteUrl).href
|
|
87
78
|
const title = page.title || page.name || page.routePath || link
|
|
88
79
|
const description = extractExcerpt(page)
|
|
89
|
-
const contentSource = htmlContent
|
|
80
|
+
const contentSource = htmlContent ?? page.content ?? ''
|
|
90
81
|
const content = contentSource
|
|
91
82
|
? (isAtom
|
|
92
|
-
?
|
|
83
|
+
? contentSource
|
|
93
84
|
: HTMLRenderer.rawHTML(wrapCdata(contentSource)))
|
|
94
85
|
: null
|
|
95
86
|
const authorValue = page.frontmatter?.author
|
|
@@ -183,7 +174,7 @@ export const generateRssFeed = async (pagesContext, rssContent = null) => {
|
|
|
183
174
|
const items = pages
|
|
184
175
|
.map((page) => ({
|
|
185
176
|
page,
|
|
186
|
-
content: rssContent?.get(page.path)
|
|
177
|
+
content: rssContent?.get(page.path) ?? rssContent?.get(page.routePath) ?? null
|
|
187
178
|
}))
|
|
188
179
|
.map((entry) => buildItem(entry.page, siteUrl, entry.content, isAtom, siteOwner))
|
|
189
180
|
.filter(Boolean)
|
package/src/mdx.js
CHANGED
package/src/pages-index.js
CHANGED
|
@@ -21,7 +21,16 @@
|
|
|
21
21
|
import JSON5 from 'json5'
|
|
22
22
|
import { extractExcerpt } from './text-utils.js'
|
|
23
23
|
|
|
24
|
-
const OMIT_KEYS = new Set([
|
|
24
|
+
const OMIT_KEYS = new Set([
|
|
25
|
+
'content',
|
|
26
|
+
'mdxComponent',
|
|
27
|
+
'mdxCtx',
|
|
28
|
+
'getSiblings',
|
|
29
|
+
'matter',
|
|
30
|
+
'path',
|
|
31
|
+
'exclude',
|
|
32
|
+
'segments'
|
|
33
|
+
])
|
|
25
34
|
|
|
26
35
|
const sanitizePage = (page) => {
|
|
27
36
|
const result = {}
|
package/src/state.js
CHANGED
|
@@ -169,19 +169,25 @@ const parser = yargs(hideBin(process.argv))
|
|
|
169
169
|
.wrap(null)
|
|
170
170
|
|
|
171
171
|
const argv = parser.parseSync()
|
|
172
|
+
const parsedCommand = argv._[0] ? String(argv._[0]) : null
|
|
173
|
+
const isServeCommand = parsedCommand === 'serve' || parsedCommand === 'preview'
|
|
174
|
+
const rawInput = argv.input || null
|
|
175
|
+
const rawOutput = argv.output || null
|
|
176
|
+
const normalizedInput = isServeCommand && rawInput && !rawOutput ? null : rawInput
|
|
177
|
+
const normalizedOutput = isServeCommand && rawInput && !rawOutput ? rawInput : rawOutput
|
|
172
178
|
|
|
173
179
|
export const cli = {
|
|
174
180
|
argv,
|
|
175
|
-
command:
|
|
181
|
+
command: parsedCommand,
|
|
176
182
|
showHelp: () => parser.showHelp(),
|
|
177
183
|
CLI_INTERMEDIATE_DIR: argv['intermediate-dir'] || null,
|
|
178
184
|
CLI_EMIT_INTERMEDIATE: Boolean(argv['emit-intermediate']),
|
|
179
185
|
CLI_HOST: argv.host ?? null,
|
|
180
186
|
CLI_PORT: typeof argv.port === 'number' ? argv.port : null,
|
|
181
|
-
CLI_PAGES_DIR:
|
|
187
|
+
CLI_PAGES_DIR: normalizedInput,
|
|
182
188
|
CLI_COMPONENTS_DIR: argv.components || null,
|
|
183
189
|
CLI_ASSETS_DIR: argv.assets || null,
|
|
184
|
-
CLI_OUTPUT_DIR:
|
|
190
|
+
CLI_OUTPUT_DIR: normalizedOutput,
|
|
185
191
|
CLI_CONFIG_PATH: argv.config || null,
|
|
186
192
|
CLI_SITE_NAME: argv['site-name'] || null,
|
|
187
193
|
CLI_OWNER: argv.owner || null,
|
|
@@ -169,8 +169,9 @@ const handleCompile = async (message) => {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
const handleRender = async (message) => {
|
|
172
|
-
const { ids = [], stage } = message || {}
|
|
173
|
-
const { renderHtml } = await import('../mdx.js')
|
|
172
|
+
const { ids = [], stage, feedIds = [] } = message || {}
|
|
173
|
+
const { renderHtml, renderPageContent } = await import('../mdx.js')
|
|
174
|
+
const feedSet = new Set(Array.isArray(feedIds) ? feedIds : [])
|
|
174
175
|
let completed = 0
|
|
175
176
|
for (const id of ids) {
|
|
176
177
|
const page = pages[id]
|
|
@@ -187,7 +188,17 @@ const handleRender = async (message) => {
|
|
|
187
188
|
pagesContext,
|
|
188
189
|
pageMeta: page
|
|
189
190
|
})
|
|
190
|
-
|
|
191
|
+
let feedContent = null
|
|
192
|
+
if (feedSet.has(id)) {
|
|
193
|
+
feedContent = await renderPageContent({
|
|
194
|
+
routePath: page.routePath,
|
|
195
|
+
path: page.path,
|
|
196
|
+
components,
|
|
197
|
+
pagesContext,
|
|
198
|
+
pageMeta: page
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
parentPort?.postMessage({ type: 'result', stage, result: { id, html, feedContent } })
|
|
191
202
|
} catch (error) {
|
|
192
203
|
logPageError('MDX render', page, error)
|
|
193
204
|
throw error
|
|
@@ -197,35 +208,6 @@ const handleRender = async (message) => {
|
|
|
197
208
|
}
|
|
198
209
|
}
|
|
199
210
|
|
|
200
|
-
const handleRss = async (message) => {
|
|
201
|
-
const { ids = [], stage } = message || {}
|
|
202
|
-
const { renderPageContent } = await import('../mdx.js')
|
|
203
|
-
let completed = 0
|
|
204
|
-
for (const id of ids) {
|
|
205
|
-
const page = pages[id]
|
|
206
|
-
if (!page) {
|
|
207
|
-
completed += 1
|
|
208
|
-
parentPort?.postMessage({ type: 'progress', stage, completed })
|
|
209
|
-
continue
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
const content = await renderPageContent({
|
|
213
|
-
routePath: page.routePath,
|
|
214
|
-
path: page.path,
|
|
215
|
-
components,
|
|
216
|
-
pagesContext,
|
|
217
|
-
pageMeta: page
|
|
218
|
-
})
|
|
219
|
-
parentPort?.postMessage({ type: 'result', stage, result: { id, content } })
|
|
220
|
-
} catch (error) {
|
|
221
|
-
logPageError('RSS render', page, error)
|
|
222
|
-
throw error
|
|
223
|
-
}
|
|
224
|
-
completed += 1
|
|
225
|
-
parentPort?.postMessage({ type: 'progress', stage, completed })
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
211
|
parentPort?.on('message', async (message) => {
|
|
230
212
|
const { type, stage } = message || {}
|
|
231
213
|
try {
|
|
@@ -250,11 +232,6 @@ parentPort?.on('message', async (message) => {
|
|
|
250
232
|
parentPort?.postMessage({ type: 'done', stage })
|
|
251
233
|
return
|
|
252
234
|
}
|
|
253
|
-
if (type === 'rss') {
|
|
254
|
-
await handleRss(message)
|
|
255
|
-
parentPort?.postMessage({ type: 'done', stage })
|
|
256
|
-
return
|
|
257
|
-
}
|
|
258
235
|
} catch (error) {
|
|
259
236
|
parentPort?.postMessage({ type: 'error', stage, error: serializeError(error) })
|
|
260
237
|
}
|
|
@@ -118,11 +118,12 @@ const NavTree = ({ nodes, depth }) => {
|
|
|
118
118
|
)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const
|
|
121
|
+
const _rootNodes = signal()
|
|
122
|
+
const rootNodes = signal(_rootNodes, (nodes) => nodes?.map(toSignal))
|
|
122
123
|
const rootTree = HTMLRenderer.createElement(NavTree, { nodes: rootNodes, depth: 0 })
|
|
123
124
|
|
|
124
125
|
export const renderNavTree = (nodes, path) => {
|
|
125
126
|
currentPath.value = path
|
|
126
|
-
|
|
127
|
+
_rootNodes.value = nodes
|
|
127
128
|
return rootTree
|
|
128
129
|
}
|