methanol 0.0.9 → 0.0.10
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 +3 -0
- package/index.js +7 -2
- package/package.json +8 -3
- package/src/build-system.js +43 -7
- package/src/client/sw.js +751 -0
- package/src/{assets.js → client/virtual-module/assets.js} +7 -3
- package/src/{virtual-module → client/virtual-module}/inject.js +1 -0
- package/src/{virtual-module → client/virtual-module}/loader.js +5 -5
- package/src/{virtual-module → client/virtual-module}/pagefind-loader.js +1 -1
- package/src/client/virtual-module/pwa-inject.js +25 -0
- package/src/components.js +5 -5
- package/src/config.js +22 -3
- package/src/dev-server.js +62 -66
- package/src/logger.js +9 -5
- package/src/main.js +5 -1
- package/src/mdx.js +21 -37
- package/src/pages.js +61 -51
- package/src/public-assets.js +1 -1
- package/src/{rewind.js → reframe.js} +1 -1
- package/src/rehype-plugins/link-resolve.js +2 -2
- package/src/stage-logger.js +3 -2
- package/src/state.js +16 -3
- package/src/utils.js +23 -1
- package/src/vite-plugins.js +17 -4
- package/themes/default/components/ThemeSearchBox.client.jsx +120 -11
- package/themes/default/index.js +2 -2
- package/themes/default/pages/404.mdx +4 -0
- package/themes/default/pages/index.mdx +7 -9
- package/themes/default/pages/offline.mdx +11 -0
- package/themes/default/sources/style.css +59 -169
- package/themes/default/src/nav-tree.jsx +112 -0
- package/themes/default/{page.jsx → src/page.jsx} +10 -55
- /package/themes/default/{heading.jsx → src/heading.jsx} +0 -0
|
@@ -21,10 +21,14 @@
|
|
|
21
21
|
import { readFileSync } from 'fs'
|
|
22
22
|
import { fileURLToPath } from 'url'
|
|
23
23
|
import { dirname, resolve } from 'path'
|
|
24
|
+
import { cached } from '../../utils.js'
|
|
24
25
|
|
|
25
26
|
const __filename = fileURLToPath(import.meta.url)
|
|
26
27
|
const __dirname = dirname(__filename)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const
|
|
29
|
+
const readStatic = (filePath) => cached(() => readFileSync(resolve(__dirname, filePath), 'utf-8'))
|
|
30
|
+
|
|
31
|
+
export const INJECT_SCRIPT = readStatic('./inject.js')
|
|
32
|
+
export const LOADER_SCRIPT = readStatic('./loader.js')
|
|
33
|
+
export const PAGEFIND_LOADER_SCRIPT = readStatic('./pagefind-loader.js')
|
|
34
|
+
export const PWA_INJECT_SCRIPT = readStatic('./pwa-inject.js')
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
export function init(registry, R) {
|
|
22
22
|
if (!registry) return
|
|
23
23
|
|
|
24
|
-
async function $$
|
|
24
|
+
async function $$rfrm(key, id, props, target = document.currentScript) {
|
|
25
25
|
const loader = registry[key]
|
|
26
26
|
|
|
27
27
|
if (!loader) {
|
|
@@ -103,14 +103,14 @@ export function init(registry, R) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
let loaded = []
|
|
106
|
-
if (window.$$
|
|
107
|
-
loaded = window.$$
|
|
106
|
+
if (window.$$rfrm) {
|
|
107
|
+
loaded = window.$$rfrm.$$loaded
|
|
108
108
|
}
|
|
109
|
-
window.$$
|
|
109
|
+
window.$$rfrm = $$rfrm
|
|
110
110
|
|
|
111
111
|
if (loaded) {
|
|
112
112
|
for (let i = 0; i < loaded.length; i++) {
|
|
113
|
-
$$
|
|
113
|
+
$$rfrm.apply(null, loaded[i])
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Copyright Yukino Song, SudoMaker Ltd.
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
|
|
22
|
+
navigator.serviceWorker.ready.then((reg) => {
|
|
23
|
+
reg.active?.postMessage({ type: 'METHANOL_WARM_MANIFEST' });
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/components.js
CHANGED
|
@@ -22,7 +22,7 @@ import { readdir, stat } from 'fs/promises'
|
|
|
22
22
|
import { existsSync } from 'fs'
|
|
23
23
|
import { join, extname, basename } from 'path'
|
|
24
24
|
import { pathToFileURL } from 'url'
|
|
25
|
-
import { env } from './
|
|
25
|
+
import { env } from './reframe.js'
|
|
26
26
|
import { state } from './state.js'
|
|
27
27
|
|
|
28
28
|
const normalizeComponentName = (value) => basename(value)
|
|
@@ -47,10 +47,10 @@ export const bumpComponentImportNonce = () => {
|
|
|
47
47
|
return componentImportNonce
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export const
|
|
51
|
-
export const client =
|
|
52
|
-
export const invalidateRegistryEntry =
|
|
53
|
-
export const genRegistryScript =
|
|
50
|
+
export const reframeEnv = env()
|
|
51
|
+
export const client = reframeEnv.client
|
|
52
|
+
export const invalidateRegistryEntry = reframeEnv.invalidate
|
|
53
|
+
export const genRegistryScript = reframeEnv.genRegistryScript
|
|
54
54
|
|
|
55
55
|
const resolveComponentExport = (componentPath, ext) => {
|
|
56
56
|
const staticCandidate = `${componentPath}.static${ext}`
|
package/src/config.js
CHANGED
|
@@ -26,8 +26,8 @@ import { mergeConfig } from 'vite'
|
|
|
26
26
|
import { cli, state } from './state.js'
|
|
27
27
|
import { logger } from './logger.js'
|
|
28
28
|
import { HTMLRenderer } from './renderer.js'
|
|
29
|
-
import {
|
|
30
|
-
import { env as createEnv } from './
|
|
29
|
+
import { reframeEnv } from './components.js'
|
|
30
|
+
import { env as createEnv } from './reframe.js'
|
|
31
31
|
import { cached, cachedStr } from './utils.js'
|
|
32
32
|
import defaultTheme from '../themes/default/index.js'
|
|
33
33
|
|
|
@@ -324,7 +324,7 @@ export const applyConfig = async (config, mode) => {
|
|
|
324
324
|
}
|
|
325
325
|
const themeEnv = state.USER_THEME.env || createEnv()
|
|
326
326
|
state.THEME_ENV = themeEnv
|
|
327
|
-
|
|
327
|
+
reframeEnv.setParent(themeEnv)
|
|
328
328
|
const themeRoot = state.USER_THEME.root || root
|
|
329
329
|
const themeComponentDirValue = hasOwn(state.USER_THEME, 'componentsDir')
|
|
330
330
|
? state.USER_THEME.componentsDir
|
|
@@ -383,8 +383,27 @@ export const applyConfig = async (config, mode) => {
|
|
|
383
383
|
state.RESOLVED_MDX_CONFIG = undefined
|
|
384
384
|
state.RESOLVED_VITE_CONFIG = undefined
|
|
385
385
|
state.PAGEFIND_ENABLED = resolvePagefindEnabled(config)
|
|
386
|
+
if (cli.CLI_SEARCH !== undefined) {
|
|
387
|
+
state.PAGEFIND_ENABLED = cli.CLI_SEARCH
|
|
388
|
+
}
|
|
386
389
|
state.PAGEFIND_OPTIONS = resolvePagefindOptions(config)
|
|
387
390
|
state.PAGEFIND_BUILD = resolvePagefindBuild(config)
|
|
391
|
+
|
|
392
|
+
if (hasOwn(config, 'pwa')) {
|
|
393
|
+
if (config.pwa === true) {
|
|
394
|
+
state.PWA_ENABLED = true
|
|
395
|
+
state.PWA_OPTIONS = null
|
|
396
|
+
} else if (typeof config.pwa === 'object' && config.pwa !== null) {
|
|
397
|
+
state.PWA_ENABLED = true
|
|
398
|
+
state.PWA_OPTIONS = config.pwa
|
|
399
|
+
} else {
|
|
400
|
+
state.PWA_ENABLED = false
|
|
401
|
+
state.PWA_OPTIONS = null
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (cli.CLI_PWA !== undefined) {
|
|
405
|
+
state.PWA_ENABLED = cli.CLI_PWA
|
|
406
|
+
}
|
|
388
407
|
state.USER_PRE_BUILD_HOOKS = normalizeHooks(config.preBuild)
|
|
389
408
|
state.USER_POST_BUILD_HOOKS = normalizeHooks(config.postBuild)
|
|
390
409
|
state.USER_PRE_BUNDLE_HOOKS = normalizeHooks(config.preBundle)
|
package/src/dev-server.js
CHANGED
|
@@ -104,12 +104,12 @@ export const runViteDev = async () => {
|
|
|
104
104
|
const assetWatcher = chokidar.watch(state.USER_ASSETS_DIR, {
|
|
105
105
|
ignoreInitial: true
|
|
106
106
|
})
|
|
107
|
-
const handleAssetUpdate = (type,
|
|
108
|
-
const relPath = relative(state.USER_ASSETS_DIR,
|
|
107
|
+
const handleAssetUpdate = (type, path) => {
|
|
108
|
+
const relPath = relative(state.USER_ASSETS_DIR, path)
|
|
109
109
|
enqueue(async () => {
|
|
110
110
|
await updateAsset({
|
|
111
111
|
type,
|
|
112
|
-
|
|
112
|
+
path,
|
|
113
113
|
relPath,
|
|
114
114
|
themeDir: state.THEME_ASSETS_DIR,
|
|
115
115
|
userDir: state.USER_ASSETS_DIR,
|
|
@@ -117,9 +117,9 @@ export const runViteDev = async () => {
|
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
}
|
|
120
|
-
assetWatcher.on('add', (
|
|
121
|
-
assetWatcher.on('change', (
|
|
122
|
-
assetWatcher.on('unlink', (
|
|
120
|
+
assetWatcher.on('add', (path) => handleAssetUpdate('add', path))
|
|
121
|
+
assetWatcher.on('change', (path) => handleAssetUpdate('change', path))
|
|
122
|
+
assetWatcher.on('unlink', (path) => handleAssetUpdate('unlink', path))
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const themeComponentsDir = state.THEME_COMPONENTS_DIR
|
|
@@ -289,8 +289,8 @@ export const runViteDev = async () => {
|
|
|
289
289
|
}
|
|
290
290
|
const notFoundPage = pagesContext.pagesByRoute.get('/404')
|
|
291
291
|
let pageMeta = pagesContext.pagesByRoute.get(requestedPath)
|
|
292
|
-
let
|
|
293
|
-
const hasMdx = Boolean(pageMeta) || existsSync(
|
|
292
|
+
let path = pageMeta?.path || resolvePageFile(requestedPath)
|
|
293
|
+
const hasMdx = Boolean(pageMeta) || existsSync(path)
|
|
294
294
|
let status = 200
|
|
295
295
|
let renderRoutePath = requestedPath
|
|
296
296
|
|
|
@@ -326,19 +326,15 @@ export const runViteDev = async () => {
|
|
|
326
326
|
|
|
327
327
|
if (isExcludedPath()) {
|
|
328
328
|
if (notFoundPage) {
|
|
329
|
-
|
|
329
|
+
path = notFoundPage.path
|
|
330
330
|
renderRoutePath = '/404'
|
|
331
331
|
status = 404
|
|
332
332
|
} else {
|
|
333
333
|
return next()
|
|
334
334
|
}
|
|
335
|
-
} else if (
|
|
336
|
-
filePath = notFoundPage.filePath
|
|
337
|
-
renderRoutePath = '/404'
|
|
338
|
-
status = 404
|
|
339
|
-
} else if (!pageMeta && !existsSync(filePath)) {
|
|
335
|
+
} else if (!pageMeta && !existsSync(path)) {
|
|
340
336
|
if (notFoundPage) {
|
|
341
|
-
|
|
337
|
+
path = notFoundPage.path
|
|
342
338
|
renderRoutePath = '/404'
|
|
343
339
|
status = 404
|
|
344
340
|
} else {
|
|
@@ -351,18 +347,18 @@ export const runViteDev = async () => {
|
|
|
351
347
|
try {
|
|
352
348
|
const renderEpoch = htmlCacheEpoch
|
|
353
349
|
const cacheEntry = htmlCache.get(renderRoutePath)
|
|
354
|
-
if (cacheEntry && cacheEntry.
|
|
350
|
+
if (cacheEntry && cacheEntry.path === path && cacheEntry.epoch === htmlCacheEpoch) {
|
|
355
351
|
res.statusCode = status
|
|
356
352
|
res.setHeader('Content-Type', 'text/html')
|
|
357
353
|
res.end(cacheEntry.html)
|
|
358
354
|
return
|
|
359
355
|
}
|
|
360
356
|
|
|
361
|
-
pageMeta ??= pagesContext.getPageByRoute(renderRoutePath, {
|
|
357
|
+
pageMeta ??= pagesContext.getPageByRoute(renderRoutePath, { path })
|
|
362
358
|
|
|
363
359
|
const html = await renderHtml({
|
|
364
360
|
routePath: renderRoutePath,
|
|
365
|
-
|
|
361
|
+
path,
|
|
366
362
|
components: {
|
|
367
363
|
...themeComponents,
|
|
368
364
|
...components
|
|
@@ -373,7 +369,7 @@ export const runViteDev = async () => {
|
|
|
373
369
|
if (renderEpoch === htmlCacheEpoch) {
|
|
374
370
|
htmlCache.set(renderRoutePath, {
|
|
375
371
|
html,
|
|
376
|
-
|
|
372
|
+
path,
|
|
377
373
|
epoch: renderEpoch
|
|
378
374
|
})
|
|
379
375
|
}
|
|
@@ -429,7 +425,7 @@ export const runViteDev = async () => {
|
|
|
429
425
|
reload()
|
|
430
426
|
}
|
|
431
427
|
|
|
432
|
-
const getExportName = (
|
|
428
|
+
const getExportName = (path) => basename(path).split('.')[0]
|
|
433
429
|
|
|
434
430
|
const findComponentExt = (dir, exportName) => {
|
|
435
431
|
for (const ext of COMPONENT_EXTENSIONS) {
|
|
@@ -444,11 +440,11 @@ export const runViteDev = async () => {
|
|
|
444
440
|
return null
|
|
445
441
|
}
|
|
446
442
|
|
|
447
|
-
const updateComponentEntry = async (
|
|
443
|
+
const updateComponentEntry = async (path, { fallback = false } = {}) => {
|
|
448
444
|
bumpComponentImportNonce()
|
|
449
|
-
const exportName = getExportName(
|
|
450
|
-
const dir = dirname(
|
|
451
|
-
let ext = extname(
|
|
445
|
+
const exportName = getExportName(path)
|
|
446
|
+
const dir = dirname(path)
|
|
447
|
+
let ext = extname(path)
|
|
452
448
|
let { component, hasClient, staticPath } = await buildComponentEntry({
|
|
453
449
|
dir,
|
|
454
450
|
exportName,
|
|
@@ -488,28 +484,28 @@ export const runViteDev = async () => {
|
|
|
488
484
|
const PAGE_UPDATE_DEBOUNCE_MS = 30
|
|
489
485
|
const pageUpdateTimers = new Map()
|
|
490
486
|
|
|
491
|
-
const schedulePageUpdate = (
|
|
492
|
-
const existing = pageUpdateTimers.get(
|
|
487
|
+
const schedulePageUpdate = (path, kind) => {
|
|
488
|
+
const existing = pageUpdateTimers.get(path)
|
|
493
489
|
if (existing?.timer) {
|
|
494
490
|
clearTimeout(existing.timer)
|
|
495
491
|
}
|
|
496
492
|
const entry = {
|
|
497
493
|
kind,
|
|
498
494
|
timer: setTimeout(() => {
|
|
499
|
-
pageUpdateTimers.delete(
|
|
500
|
-
enqueue(() => handlePageUpdate(
|
|
495
|
+
pageUpdateTimers.delete(path)
|
|
496
|
+
enqueue(() => handlePageUpdate(path, kind))
|
|
501
497
|
}, PAGE_UPDATE_DEBOUNCE_MS)
|
|
502
498
|
}
|
|
503
|
-
pageUpdateTimers.set(
|
|
499
|
+
pageUpdateTimers.set(path, entry)
|
|
504
500
|
}
|
|
505
501
|
|
|
506
|
-
const resolveWatchedSource = (
|
|
507
|
-
const inUserPages = routePathFromFile(
|
|
502
|
+
const resolveWatchedSource = (path) => {
|
|
503
|
+
const inUserPages = routePathFromFile(path, state.PAGES_DIR)
|
|
508
504
|
if (inUserPages) {
|
|
509
505
|
return { pagesDir: state.PAGES_DIR, source: 'user', routePath: inUserPages }
|
|
510
506
|
}
|
|
511
507
|
if (state.THEME_PAGES_DIR) {
|
|
512
|
-
const inThemePages = routePathFromFile(
|
|
508
|
+
const inThemePages = routePathFromFile(path, state.THEME_PAGES_DIR)
|
|
513
509
|
if (inThemePages) {
|
|
514
510
|
return { pagesDir: state.THEME_PAGES_DIR, source: 'theme', routePath: inThemePages }
|
|
515
511
|
}
|
|
@@ -517,16 +513,16 @@ export const runViteDev = async () => {
|
|
|
517
513
|
return null
|
|
518
514
|
}
|
|
519
515
|
|
|
520
|
-
const updatePageEntry = async (
|
|
516
|
+
const updatePageEntry = async (path, resolved) => {
|
|
521
517
|
if (!pagesContext || !resolved) return false
|
|
522
|
-
pagesContext.clearDerivedTitle?.(
|
|
518
|
+
pagesContext.clearDerivedTitle?.(path)
|
|
523
519
|
const nextEntry = await buildPageEntry({
|
|
524
|
-
|
|
520
|
+
path,
|
|
525
521
|
pagesDir: resolved.pagesDir,
|
|
526
522
|
source: resolved.source
|
|
527
523
|
})
|
|
528
524
|
if (!nextEntry) return false
|
|
529
|
-
const prevEntry = pagesContext.pages?.find?.((page) => page.
|
|
525
|
+
const prevEntry = pagesContext.pages?.find?.((page) => page.path === path) || null
|
|
530
526
|
if (!prevEntry) return false
|
|
531
527
|
if (prevEntry.exclude !== nextEntry.exclude) return false
|
|
532
528
|
if (prevEntry.isIndex !== nextEntry.isIndex || prevEntry.dir !== nextEntry.dir) return false
|
|
@@ -546,22 +542,22 @@ export const runViteDev = async () => {
|
|
|
546
542
|
return true
|
|
547
543
|
}
|
|
548
544
|
|
|
549
|
-
const isUserHeadAsset = (
|
|
550
|
-
const name = basename(
|
|
545
|
+
const isUserHeadAsset = (path) => {
|
|
546
|
+
const name = basename(path)
|
|
551
547
|
if (name !== 'style.css' && name !== 'index.js' && name !== 'index.ts') {
|
|
552
548
|
return false
|
|
553
549
|
}
|
|
554
550
|
const root = resolve(state.PAGES_DIR || '')
|
|
555
|
-
return root && resolve(dirname(
|
|
551
|
+
return root && resolve(dirname(path)) === root
|
|
556
552
|
}
|
|
557
553
|
|
|
558
|
-
const handlePageUpdate = async (
|
|
559
|
-
if (isUserHeadAsset(
|
|
554
|
+
const handlePageUpdate = async (path, kind) => {
|
|
555
|
+
if (isUserHeadAsset(path)) {
|
|
560
556
|
invalidateHtmlCache()
|
|
561
557
|
reload()
|
|
562
558
|
return
|
|
563
559
|
}
|
|
564
|
-
const resolved = resolveWatchedSource(
|
|
560
|
+
const resolved = resolveWatchedSource(path)
|
|
565
561
|
if (kind === 'unlink') {
|
|
566
562
|
if (resolved?.routePath) {
|
|
567
563
|
htmlCache.delete(resolved.routePath)
|
|
@@ -571,7 +567,7 @@ export const runViteDev = async () => {
|
|
|
571
567
|
await refreshPages()
|
|
572
568
|
return
|
|
573
569
|
}
|
|
574
|
-
const updated = await updatePageEntry(
|
|
570
|
+
const updated = await updatePageEntry(path, resolved)
|
|
575
571
|
if (updated) {
|
|
576
572
|
invalidateHtmlCache()
|
|
577
573
|
reload()
|
|
@@ -583,15 +579,15 @@ export const runViteDev = async () => {
|
|
|
583
579
|
await refreshPages()
|
|
584
580
|
}
|
|
585
581
|
|
|
586
|
-
pageWatcher.on('change', (
|
|
587
|
-
schedulePageUpdate(
|
|
582
|
+
pageWatcher.on('change', (path) => {
|
|
583
|
+
schedulePageUpdate(path, 'change')
|
|
588
584
|
})
|
|
589
585
|
|
|
590
|
-
pageWatcher.on('add', (
|
|
591
|
-
schedulePageUpdate(
|
|
586
|
+
pageWatcher.on('add', (path) => {
|
|
587
|
+
schedulePageUpdate(path, 'add')
|
|
592
588
|
})
|
|
593
|
-
pageWatcher.on('unlink', (
|
|
594
|
-
schedulePageUpdate(
|
|
589
|
+
pageWatcher.on('unlink', (path) => {
|
|
590
|
+
schedulePageUpdate(path, 'unlink')
|
|
595
591
|
})
|
|
596
592
|
pageWatcher.on('addDir', () => {
|
|
597
593
|
enqueue(refreshPages)
|
|
@@ -605,13 +601,13 @@ export const runViteDev = async () => {
|
|
|
605
601
|
ignoreInitial: true
|
|
606
602
|
})
|
|
607
603
|
|
|
608
|
-
componentWatcher.on('add', (
|
|
609
|
-
if (!isComponentFile(
|
|
604
|
+
componentWatcher.on('add', (path) => {
|
|
605
|
+
if (!isComponentFile(path)) {
|
|
610
606
|
return
|
|
611
607
|
}
|
|
612
|
-
if (isClientComponent(
|
|
608
|
+
if (isClientComponent(path)) {
|
|
613
609
|
enqueue(async () => {
|
|
614
|
-
const { hasClient } = await updateComponentEntry(
|
|
610
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
615
611
|
if (hasClient) {
|
|
616
612
|
invalidateRewindInject()
|
|
617
613
|
}
|
|
@@ -621,7 +617,7 @@ export const runViteDev = async () => {
|
|
|
621
617
|
return
|
|
622
618
|
}
|
|
623
619
|
enqueue(async () => {
|
|
624
|
-
const { hasClient } = await updateComponentEntry(
|
|
620
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
625
621
|
invalidateHtmlCache()
|
|
626
622
|
if (hasClient) {
|
|
627
623
|
invalidateRewindInject()
|
|
@@ -630,19 +626,19 @@ export const runViteDev = async () => {
|
|
|
630
626
|
})
|
|
631
627
|
})
|
|
632
628
|
|
|
633
|
-
componentWatcher.on('change', (
|
|
634
|
-
if (!isComponentFile(
|
|
629
|
+
componentWatcher.on('change', (path) => {
|
|
630
|
+
if (!isComponentFile(path)) {
|
|
635
631
|
return
|
|
636
632
|
}
|
|
637
|
-
if (isClientComponent(
|
|
633
|
+
if (isClientComponent(path)) {
|
|
638
634
|
enqueue(async () => {
|
|
639
|
-
await updateComponentEntry(
|
|
635
|
+
await updateComponentEntry(path)
|
|
640
636
|
invalidateHtmlCache()
|
|
641
637
|
})
|
|
642
638
|
return
|
|
643
639
|
}
|
|
644
640
|
enqueue(async () => {
|
|
645
|
-
const { hasClient } = await updateComponentEntry(
|
|
641
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
646
642
|
invalidateHtmlCache()
|
|
647
643
|
if (hasClient) {
|
|
648
644
|
invalidateRewindInject()
|
|
@@ -651,24 +647,24 @@ export const runViteDev = async () => {
|
|
|
651
647
|
})
|
|
652
648
|
})
|
|
653
649
|
|
|
654
|
-
componentWatcher.on('unlink', (
|
|
655
|
-
if (!isComponentFile(
|
|
656
|
-
if (isClientComponent(
|
|
650
|
+
componentWatcher.on('unlink', (path) => {
|
|
651
|
+
if (!isComponentFile(path)) return
|
|
652
|
+
if (isClientComponent(path)) {
|
|
657
653
|
enqueue(async () => {
|
|
658
|
-
await updateComponentEntry(
|
|
654
|
+
await updateComponentEntry(path, { fallback: true })
|
|
659
655
|
invalidateRewindInject()
|
|
660
656
|
invalidateHtmlCache()
|
|
661
657
|
reload()
|
|
662
658
|
})
|
|
663
659
|
return
|
|
664
660
|
}
|
|
665
|
-
const exportName = getExportName(
|
|
661
|
+
const exportName = getExportName(path)
|
|
666
662
|
const currentSource = componentSources.get(exportName)
|
|
667
|
-
if (currentSource && currentSource !==
|
|
663
|
+
if (currentSource && currentSource !== path && existsSync(currentSource)) {
|
|
668
664
|
return
|
|
669
665
|
}
|
|
670
666
|
enqueue(async () => {
|
|
671
|
-
const { hasClient } = await updateComponentEntry(
|
|
667
|
+
const { hasClient } = await updateComponentEntry(path, {
|
|
672
668
|
fallback: true
|
|
673
669
|
})
|
|
674
670
|
invalidateHtmlCache()
|
package/src/logger.js
CHANGED
|
@@ -71,10 +71,14 @@ export const style = {
|
|
|
71
71
|
bgWhite: formatter('\x1b[47m', '\x1b[49m')
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const log = console.log.bind(console)
|
|
75
|
+
const warn = console.warn.bind(console)
|
|
76
|
+
const error = console.error.bind(console)
|
|
77
|
+
|
|
74
78
|
export const logger = {
|
|
75
|
-
info: (msg) =>
|
|
76
|
-
success: (msg) =>
|
|
77
|
-
warn: (msg) =>
|
|
78
|
-
error: (msg) =>
|
|
79
|
-
dim: (msg) =>
|
|
79
|
+
info: (msg) => log(`${style.blue('ℹ')} ${msg}`),
|
|
80
|
+
success: (msg) => log(`${style.green('✔')} ${msg}`),
|
|
81
|
+
warn: (msg) => warn(`${style.yellow('⚠')} ${msg}`),
|
|
82
|
+
error: (msg) => error(`${style.red('✖')} ${msg}`),
|
|
83
|
+
dim: (msg) => log(style.dim(msg))
|
|
80
84
|
}
|
package/src/main.js
CHANGED
|
@@ -134,8 +134,12 @@ const main = async () => {
|
|
|
134
134
|
const endTime = performance.now()
|
|
135
135
|
const duration = endTime - startTime
|
|
136
136
|
const timeString = duration > 1000 ? `${(duration / 1000).toFixed(2)}s` : `${Math.round(duration)}ms`
|
|
137
|
+
const totalPages = pagesContext?.pages?.length ?? 0
|
|
138
|
+
const pageLabel = totalPages === 1 ? 'page' : 'pages'
|
|
137
139
|
console.log()
|
|
138
|
-
logger.success(
|
|
140
|
+
logger.success(
|
|
141
|
+
`Build complete! Processed ${style.bold(totalPages)} ${pageLabel} in ${style.bold(timeString)}.`
|
|
142
|
+
)
|
|
139
143
|
return
|
|
140
144
|
}
|
|
141
145
|
cli.showHelp()
|
package/src/mdx.js
CHANGED
|
@@ -41,13 +41,13 @@ import { linkResolve } from './rehype-plugins/link-resolve.js'
|
|
|
41
41
|
const resolveRewindInject = () =>
|
|
42
42
|
HTMLRenderer.rawHTML(`<script type="module" src="${withBase('/.methanol_virtual_module/inject.js')}"></script>`)
|
|
43
43
|
const RWND_FALLBACK = HTMLRenderer.rawHTML`<script>
|
|
44
|
-
if (!window.$$
|
|
44
|
+
if (!window.$$rfrm) {
|
|
45
45
|
const l = []
|
|
46
46
|
const r = function(k,i,p) {
|
|
47
47
|
l.push([k,i,p,document.currentScript])
|
|
48
48
|
}
|
|
49
49
|
r.$$loaded = l
|
|
50
|
-
window.$$
|
|
50
|
+
window.$$rfrm = r
|
|
51
51
|
}
|
|
52
52
|
</script>`
|
|
53
53
|
|
|
@@ -74,25 +74,21 @@ const resolveUserHeadAssets = () => {
|
|
|
74
74
|
return assets
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const resolvePageAssetUrl = (page,
|
|
78
|
-
const root = page.source === 'theme' && state.THEME_PAGES_DIR
|
|
79
|
-
? state.THEME_PAGES_DIR
|
|
80
|
-
: state.PAGES_DIR
|
|
77
|
+
const resolvePageAssetUrl = (page, path) => {
|
|
78
|
+
const root = page.source === 'theme' && state.THEME_PAGES_DIR ? state.THEME_PAGES_DIR : state.PAGES_DIR
|
|
81
79
|
if (!root) return null
|
|
82
|
-
const relPath = relative(root,
|
|
80
|
+
const relPath = relative(root, path).replace(/\\/g, '/')
|
|
83
81
|
if (!relPath || relPath.startsWith('..')) return null
|
|
84
82
|
return withBase(`/${relPath}`)
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
const resolvePageHeadAssets = (page) => {
|
|
88
|
-
if (!page.
|
|
89
|
-
const baseDir = dirname(page.
|
|
90
|
-
const baseName = basename(page.
|
|
86
|
+
if (!page.path) return []
|
|
87
|
+
const baseDir = dirname(page.path)
|
|
88
|
+
const baseName = basename(page.path).replace(/\.(mdx|md)$/, '')
|
|
91
89
|
const pagesRoot = state.PAGES_DIR ? resolve(state.PAGES_DIR) : null
|
|
92
|
-
const isRootIndex =
|
|
93
|
-
|
|
94
|
-
const isRootStylePage =
|
|
95
|
-
pagesRoot && baseName === 'style' && resolve(baseDir) === pagesRoot && page.source !== 'theme'
|
|
90
|
+
const isRootIndex = pagesRoot && baseName === 'index' && resolve(baseDir) === pagesRoot && page.source !== 'theme'
|
|
91
|
+
const isRootStylePage = pagesRoot && baseName === 'style' && resolve(baseDir) === pagesRoot && page.source !== 'theme'
|
|
96
92
|
const assets = []
|
|
97
93
|
const cssPath = resolve(baseDir, `${baseName}.css`)
|
|
98
94
|
if (existsSync(cssPath)) {
|
|
@@ -132,17 +128,11 @@ const resolvePageHeadAssets = (page) => {
|
|
|
132
128
|
return assets
|
|
133
129
|
}
|
|
134
130
|
|
|
135
|
-
export const buildPageContext = ({
|
|
136
|
-
routePath,
|
|
137
|
-
filePath,
|
|
138
|
-
pageMeta,
|
|
139
|
-
pagesContext,
|
|
140
|
-
lazyPagesTree = false
|
|
141
|
-
}) => {
|
|
131
|
+
export const buildPageContext = ({ routePath, path, pageMeta, pagesContext, lazyPagesTree = false }) => {
|
|
142
132
|
const page = pageMeta
|
|
143
133
|
const language = pagesContext.getLanguageForRoute ? pagesContext.getLanguageForRoute(routePath) : null
|
|
144
134
|
const getSiblings = pagesContext.getSiblings
|
|
145
|
-
? () => pagesContext.getSiblings(routePath, page.
|
|
135
|
+
? () => pagesContext.getSiblings(routePath, page.path || path)
|
|
146
136
|
: null
|
|
147
137
|
if (page && getSiblings && page.getSiblings !== getSiblings) {
|
|
148
138
|
page.getSiblings = getSiblings
|
|
@@ -150,7 +140,7 @@ export const buildPageContext = ({
|
|
|
150
140
|
const ctx = {
|
|
151
141
|
routePath,
|
|
152
142
|
routeHref: withBase(routePath),
|
|
153
|
-
|
|
143
|
+
path,
|
|
154
144
|
page,
|
|
155
145
|
pages: pagesContext.pages || [],
|
|
156
146
|
pagesByRoute: pagesContext.pagesByRoute || new Map(),
|
|
@@ -299,14 +289,14 @@ const resolveMdxConfigForPage = async (frontmatter) => {
|
|
|
299
289
|
return mdxConfig
|
|
300
290
|
}
|
|
301
291
|
|
|
302
|
-
export const compileMdx = async ({ content,
|
|
292
|
+
export const compileMdx = async ({ content, path, ctx }) => {
|
|
303
293
|
const mdxConfig = await resolveMdxConfigForPage(ctx.page.frontmatter)
|
|
304
294
|
const runtimeFactory = mdxConfig.development ? JSXDevFactory : JSXFactory
|
|
305
|
-
const compiled = await compile({ value: content, path:
|
|
295
|
+
const compiled = await compile({ value: content, path: path }, mdxConfig)
|
|
306
296
|
|
|
307
297
|
return await run(compiled, {
|
|
308
298
|
...runtimeFactory,
|
|
309
|
-
baseUrl: pathToFileURL(
|
|
299
|
+
baseUrl: pathToFileURL(path).href,
|
|
310
300
|
ctx,
|
|
311
301
|
rawHTML: HTMLRenderer.rawHTML
|
|
312
302
|
})
|
|
@@ -319,14 +309,14 @@ export const compilePageMdx = async (page, pagesContext, options = {}) => {
|
|
|
319
309
|
ctx ||
|
|
320
310
|
buildPageContext({
|
|
321
311
|
routePath: page.routePath,
|
|
322
|
-
|
|
312
|
+
path: page.path,
|
|
323
313
|
pageMeta: page,
|
|
324
314
|
pagesContext,
|
|
325
315
|
lazyPagesTree
|
|
326
316
|
})
|
|
327
317
|
const mdxModule = await compileMdx({
|
|
328
318
|
content: page.content,
|
|
329
|
-
|
|
319
|
+
path: page.path,
|
|
330
320
|
ctx: activeCtx
|
|
331
321
|
})
|
|
332
322
|
page.mdxComponent = mdxModule.default
|
|
@@ -342,23 +332,17 @@ export const compilePageMdx = async (page, pagesContext, options = {}) => {
|
|
|
342
332
|
}
|
|
343
333
|
}
|
|
344
334
|
if (typeof pagesContext.setDerivedTitle === 'function') {
|
|
345
|
-
pagesContext.setDerivedTitle(page.
|
|
335
|
+
pagesContext.setDerivedTitle(page.path, shouldUseTocTitle ? page.title : null, page.toc)
|
|
346
336
|
}
|
|
347
337
|
if (ctx && refreshPagesTree && pagesContext.getPagesTree) {
|
|
348
338
|
ctx.pagesTree = pagesContext.getPagesTree(activeCtx.routePath)
|
|
349
339
|
}
|
|
350
340
|
}
|
|
351
341
|
|
|
352
|
-
export const renderHtml = async ({
|
|
353
|
-
routePath,
|
|
354
|
-
filePath,
|
|
355
|
-
components,
|
|
356
|
-
pagesContext,
|
|
357
|
-
pageMeta
|
|
358
|
-
}) => {
|
|
342
|
+
export const renderHtml = async ({ routePath, path, components, pagesContext, pageMeta }) => {
|
|
359
343
|
const ctx = buildPageContext({
|
|
360
344
|
routePath,
|
|
361
|
-
|
|
345
|
+
path,
|
|
362
346
|
pageMeta,
|
|
363
347
|
pagesContext
|
|
364
348
|
})
|