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 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.10",
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
  }
@@ -102,14 +107,11 @@ export const buildHtmlEntries = async () => {
102
107
  for (let i = 0; i < pagesContext.pages.length; i++) {
103
108
  const page = pagesContext.pages[i]
104
109
  if (logEnabled) {
105
- stageLogger.update(
106
- renderToken,
107
- `Rendering pages [${i + 1}/${totalPages}] ${page.filePath}`
108
- )
110
+ stageLogger.update(renderToken, `Rendering pages [${i + 1}/${totalPages}] ${page.path}`)
109
111
  }
110
112
  const html = await renderHtml({
111
113
  routePath: page.routePath,
112
- filePath: page.filePath,
114
+ path: page.path,
113
115
  components: mergedComponents,
114
116
  pagesContext,
115
117
  pageMeta: page
@@ -176,6 +178,8 @@ export const runViteBuild = async (entry, htmlCache) => {
176
178
  })
177
179
  }
178
180
  const copyPublicDirEnabled = state.STATIC_DIR !== false
181
+ const manifestConfig = state.PWA_OPTIONS?.manifest || {}
182
+ const resolvedManifest = { name: state.SITE_NAME, short_name: state.SITE_NAME, ...manifestConfig }
179
183
  const baseConfig = {
180
184
  configFile: false,
181
185
  root: state.PAGES_DIR,
@@ -198,10 +202,42 @@ export const runViteBuild = async (entry, htmlCache) => {
198
202
  resolve: {
199
203
  dedupe: ['refui', 'methanol']
200
204
  },
201
- plugins: [methanolVirtualHtmlPlugin(htmlCache), methanolResolverPlugin()]
205
+ plugins: [
206
+ methanolVirtualHtmlPlugin(htmlCache),
207
+ methanolResolverPlugin(),
208
+ state.PWA_ENABLED
209
+ ? VitePWA({
210
+ injectRegister: 'auto',
211
+ registerType: 'autoUpdate',
212
+ strategies: 'injectManifest',
213
+ srcDir: resolve(__dirname, 'client'),
214
+ filename: 'sw.js',
215
+ manifest: resolvedManifest,
216
+ injectManifest: {
217
+ globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
218
+ ...(state.PWA_OPTIONS?.injectManifest || {})
219
+ }
220
+ })
221
+ : null
222
+ ]
202
223
  }
203
224
  const userConfig = await resolveUserViteConfig('build')
204
225
  const finalConfig = userConfig ? mergeConfig(baseConfig, userConfig) : baseConfig
205
- await viteBuild(finalConfig)
226
+
227
+ const originalLog = console.log
228
+ const originalWarn = console.warn
229
+ if (!cli.CLI_VERBOSE) {
230
+ console.log = () => {}
231
+ console.warn = () => {}
232
+ }
233
+
234
+ try {
235
+ await viteBuild(finalConfig)
236
+ } finally {
237
+ if (!cli.CLI_VERBOSE) {
238
+ console.log = originalLog
239
+ console.warn = originalWarn
240
+ }
241
+ }
206
242
  stageLogger.end(token)
207
243
  }