methanol 0.0.9 → 0.0.11

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 CHANGED
@@ -44,6 +44,9 @@ export default () => ({
44
44
  // optional: code highlighting (Starry Night)
45
45
  starryNight: false,
46
46
 
47
+ // optional: pwa support
48
+ pwa: true,
49
+
47
50
  // optional: site metadata
48
51
  site: {
49
52
  base: '/docs/'
package/index.js CHANGED
@@ -18,5 +18,10 @@
18
18
  * under the License.
19
19
  */
20
20
 
21
- export { env } from './src/rewind.js'
22
- export { HTMLRenderer } from './src/renderer.js'
21
+ import { HTMLRenderer } from './src/renderer.js'
22
+
23
+ export { env } from './src/reframe.js'
24
+
25
+ const DOCTYPE_HTML = HTMLRenderer.rawHTML`<!DOCTYPE html>`
26
+
27
+ export { HTMLRenderer, DOCTYPE_HTML }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "methanol",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Static site generator powered by rEFui and MDX",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -35,13 +35,18 @@
35
35
  "gray-matter": "^4.0.3",
36
36
  "hast-util-is-element": "^3.0.0",
37
37
  "json5": "^2.2.3",
38
- "refui": "^0.16.2",
38
+ "null-prototype-object": "^1.2.5",
39
+ "refui": "^0.16.3",
39
40
  "refurbish": "^0.1.8",
40
41
  "rehype-slug": "^6.0.0",
41
42
  "rehype-starry-night": "^2.2.0",
42
43
  "remark-gfm": "^4.0.1",
43
44
  "unist-util-visit": "^5.0.0",
44
- "vite": "^7.3.0",
45
+ "vite": "^7.3.1",
46
+ "vite-plugin-pwa": "^1.2.0",
47
+ "workbox-core": "^7.4.0",
48
+ "workbox-routing": "^7.4.0",
49
+ "workbox-strategies": "^7.4.0",
45
50
  "yargs": "^18.0.0"
46
51
  },
47
52
  "repository": {
@@ -20,7 +20,9 @@
20
20
 
21
21
  import { writeFile, mkdir, rm, readFile, readdir, stat } from 'fs/promises'
22
22
  import { resolve, dirname, join } from 'path'
23
+ import { fileURLToPath } from 'url'
23
24
  import { build as viteBuild, mergeConfig, normalizePath } from 'vite'
25
+ import { VitePWA } from 'vite-plugin-pwa'
24
26
  import { state, cli } from './state.js'
25
27
  import { resolveUserViteConfig } from './config.js'
26
28
  import { buildPagesContext } from './pages.js'
@@ -30,6 +32,9 @@ import { methanolVirtualHtmlPlugin, methanolResolverPlugin } from './vite-plugin
30
32
  import { createStageLogger } from './stage-logger.js'
31
33
  import { preparePublicAssets } from './public-assets.js'
32
34
 
35
+ const __filename = fileURLToPath(import.meta.url)
36
+ const __dirname = dirname(__filename)
37
+
33
38
  const ensureDir = async (dir) => {
34
39
  await mkdir(dir, { recursive: true })
35
40
  }
@@ -104,12 +109,12 @@ export const buildHtmlEntries = async () => {
104
109
  if (logEnabled) {
105
110
  stageLogger.update(
106
111
  renderToken,
107
- `Rendering pages [${i + 1}/${totalPages}] ${page.filePath}`
112
+ `Rendering pages [${i + 1}/${totalPages}] ${page.routePath || page.path}`
108
113
  )
109
114
  }
110
115
  const html = await renderHtml({
111
116
  routePath: page.routePath,
112
- filePath: page.filePath,
117
+ path: page.path,
113
118
  components: mergedComponents,
114
119
  pagesContext,
115
120
  pageMeta: page
@@ -176,6 +181,8 @@ export const runViteBuild = async (entry, htmlCache) => {
176
181
  })
177
182
  }
178
183
  const copyPublicDirEnabled = state.STATIC_DIR !== false
184
+ const manifestConfig = state.PWA_OPTIONS?.manifest || {}
185
+ const resolvedManifest = { name: state.SITE_NAME, short_name: state.SITE_NAME, ...manifestConfig }
179
186
  const baseConfig = {
180
187
  configFile: false,
181
188
  root: state.PAGES_DIR,
@@ -198,10 +205,42 @@ export const runViteBuild = async (entry, htmlCache) => {
198
205
  resolve: {
199
206
  dedupe: ['refui', 'methanol']
200
207
  },
201
- plugins: [methanolVirtualHtmlPlugin(htmlCache), methanolResolverPlugin()]
208
+ plugins: [
209
+ methanolVirtualHtmlPlugin(htmlCache),
210
+ methanolResolverPlugin(),
211
+ state.PWA_ENABLED
212
+ ? VitePWA({
213
+ injectRegister: 'auto',
214
+ registerType: 'autoUpdate',
215
+ strategies: 'injectManifest',
216
+ srcDir: resolve(__dirname, 'client'),
217
+ filename: 'sw.js',
218
+ manifest: resolvedManifest,
219
+ injectManifest: {
220
+ globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
221
+ ...(state.PWA_OPTIONS?.injectManifest || {})
222
+ }
223
+ })
224
+ : null
225
+ ]
202
226
  }
203
227
  const userConfig = await resolveUserViteConfig('build')
204
228
  const finalConfig = userConfig ? mergeConfig(baseConfig, userConfig) : baseConfig
205
- await viteBuild(finalConfig)
229
+
230
+ const originalLog = console.log
231
+ const originalWarn = console.warn
232
+ if (!cli.CLI_VERBOSE) {
233
+ console.log = () => {}
234
+ console.warn = () => {}
235
+ }
236
+
237
+ try {
238
+ await viteBuild(finalConfig)
239
+ } finally {
240
+ if (!cli.CLI_VERBOSE) {
241
+ console.log = originalLog
242
+ console.warn = originalWarn
243
+ }
244
+ }
206
245
  stageLogger.end(token)
207
246
  }