methanol 0.0.0 → 0.0.2

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 (48) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +58 -0
  3. package/banner.txt +6 -0
  4. package/bin/methanol.js +24 -0
  5. package/index.js +22 -0
  6. package/package.json +51 -9
  7. package/src/assets.js +30 -0
  8. package/src/build-system.js +200 -0
  9. package/src/components.js +145 -0
  10. package/src/config.js +396 -0
  11. package/src/dev-server.js +632 -0
  12. package/src/main.js +133 -0
  13. package/src/mdx.js +406 -0
  14. package/src/node-loader.js +88 -0
  15. package/src/pagefind.js +107 -0
  16. package/src/pages.js +771 -0
  17. package/src/preview-server.js +58 -0
  18. package/src/public-assets.js +73 -0
  19. package/src/register-loader.js +29 -0
  20. package/src/rehype-plugins/link-resolve.js +116 -0
  21. package/src/rehype-plugins/methanol-ctx.js +89 -0
  22. package/src/renderer.js +25 -0
  23. package/src/rewind.js +117 -0
  24. package/src/stage-logger.js +59 -0
  25. package/src/state.js +179 -0
  26. package/src/virtual-module/inject.js +30 -0
  27. package/src/virtual-module/loader.js +116 -0
  28. package/src/virtual-module/pagefind.js +108 -0
  29. package/src/vite-plugins.js +173 -0
  30. package/themes/default/components/ThemeAccentSwitch.client.jsx +95 -0
  31. package/themes/default/components/ThemeAccentSwitch.static.jsx +23 -0
  32. package/themes/default/components/ThemeColorSwitch.client.jsx +95 -0
  33. package/themes/default/components/ThemeColorSwitch.static.jsx +23 -0
  34. package/themes/default/components/ThemeSearchBox.client.jsx +324 -0
  35. package/themes/default/components/ThemeSearchBox.static.jsx +40 -0
  36. package/themes/default/components/ThemeToCContainer.client.jsx +154 -0
  37. package/themes/default/components/ThemeToCContainer.static.jsx +61 -0
  38. package/themes/default/components/pre.client.jsx +84 -0
  39. package/themes/default/components/pre.static.jsx +27 -0
  40. package/themes/default/heading.jsx +35 -0
  41. package/themes/default/index.js +41 -0
  42. package/themes/default/page.jsx +303 -0
  43. package/themes/default/pages/404.mdx +8 -0
  44. package/themes/default/pages/index.mdx +31 -0
  45. package/themes/default/public/favicon.png +0 -0
  46. package/themes/default/public/logo.png +0 -0
  47. package/themes/default/sources/prefetch.js +49 -0
  48. package/themes/default/sources/style.css +1660 -0
@@ -0,0 +1,107 @@
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
+ import { access } from 'fs/promises'
22
+ import { constants } from 'fs'
23
+ import { join, delimiter } from 'path'
24
+ import { spawn } from 'child_process'
25
+ import { state } from './state.js'
26
+
27
+ const resolvePagefindBin = async () => {
28
+ const binName = process.platform === 'win32' ? 'pagefind.cmd' : 'pagefind'
29
+ const candidates = [
30
+ join(state.PROJECT_ROOT, 'node_modules', '.bin', binName),
31
+ join(state.ROOT_DIR, 'node_modules', '.bin', binName)
32
+ ]
33
+ for (const candidate of candidates) {
34
+ try {
35
+ await access(candidate, constants.X_OK)
36
+ return candidate
37
+ } catch {}
38
+ }
39
+ const pathEntries = (process.env.PATH || '').split(delimiter).filter(Boolean)
40
+ for (const entry of pathEntries) {
41
+ const candidate = join(entry, binName)
42
+ try {
43
+ await access(candidate, constants.X_OK)
44
+ return candidate
45
+ } catch {}
46
+ }
47
+ return null
48
+ }
49
+
50
+ const toKebabCase = (value) =>
51
+ String(value)
52
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
53
+ .replace(/_/g, '-')
54
+ .toLowerCase()
55
+
56
+ const buildArgsFromOptions = (options) => {
57
+ if (!options) return []
58
+ if (Array.isArray(options)) {
59
+ return options.map(String)
60
+ }
61
+ if (typeof options !== 'object') return []
62
+ const args = []
63
+ for (const [rawKey, rawValue] of Object.entries(options)) {
64
+ if (!rawKey) continue
65
+ const key = String(rawKey)
66
+ const normalized = toKebabCase(key.replace(/^--/, ''))
67
+ if (normalized === 'site' || normalized === 'site-dir' || normalized === 'source') {
68
+ continue
69
+ }
70
+ const flag = key.startsWith('--') ? key : `--${normalized}`
71
+ if (rawValue === true) {
72
+ args.push(flag)
73
+ } else if (rawValue === false || rawValue == null) {
74
+ continue
75
+ } else {
76
+ args.push(flag, String(rawValue))
77
+ }
78
+ }
79
+ return args
80
+ }
81
+
82
+ const runCommand = (command, args, options) =>
83
+ new Promise((resolve) => {
84
+ const child = spawn(command, args, {
85
+ stdio: 'inherit',
86
+ ...options
87
+ })
88
+ child.on('close', (code) => resolve(code === 0))
89
+ child.on('error', () => resolve(false))
90
+ })
91
+
92
+ export const runPagefind = async () => {
93
+ const bin = await resolvePagefindBin()
94
+ if (!bin) {
95
+ console.log('Pagefind not found; skipping search indexing.')
96
+ return false
97
+ }
98
+ console.log('Running Pagefind search indexing...')
99
+ const extraArgs = buildArgsFromOptions(state.PAGEFIND_BUILD)
100
+ const ok = await runCommand(bin, ['--site', state.DIST_DIR, ...extraArgs], {
101
+ cwd: state.PROJECT_ROOT
102
+ })
103
+ if (!ok) {
104
+ console.warn('Pagefind failed to build search index.')
105
+ }
106
+ return ok
107
+ }