Skip to content

Commit 5a63244

Browse files
authored
fix(pwa): site baseurl not passed to app.js (#1955)
1 parent 3ab3b84 commit 5a63244

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

_includes/js-selector.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@
9292
{% if jekyll.environment == 'production' %}
9393
<!-- PWA -->
9494
{% if site.pwa.enabled %}
95-
<script defer src="{{ 'app.min.js' | relative_url }}"></script>
95+
<script
96+
defer
97+
src="{{ 'app.min.js' | relative_url }}?baseurl={{ site.baseurl | default: '' }}&register={{ site.pwa.cache.enabled }}"
98+
></script>
9699
{% endif %}
97100

98101
<!-- Web Analytics -->

_javascript/pwa/app.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { pwa, baseurl } from '../../_config.yml';
21
import Toast from 'bootstrap/js/src/toast';
32

43
if ('serviceWorker' in navigator) {
5-
if (pwa.enabled) {
6-
const swUrl = `${baseurl}/sw.min.js`;
4+
// Get Jekyll config from URL parameters
5+
const src = new URL(document.currentScript.src);
6+
const register = src.searchParams.get('register');
7+
const baseUrl = src.searchParams.get('baseurl');
8+
9+
if (register) {
10+
const swUrl = `${baseUrl}/sw.min.js`;
711
const notification = document.getElementById('notification');
812
const btnRefresh = notification.querySelector('.toast-body>button');
913
const popupWindow = Toast.getOrCreateInstance(notification);
1014

1115
navigator.serviceWorker.register(swUrl).then((registration) => {
12-
// In case the user ignores the notification
16+
// Restore the update window that was last manually closed by the user
1317
if (registration.waiting) {
1418
popupWindow.show();
1519
}

_javascript/pwa/sw.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { baseurl } from '../../_config.yml';
2-
3-
importScripts(`${baseurl}/assets/js/data/swconf.js`);
1+
importScripts('./assets/js/data/swconf.js');
42

53
const purge = swconf.purge;
64
const interceptor = swconf.interceptor;

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@rollup/plugin-babel": "^6.0.4",
3737
"@rollup/plugin-node-resolve": "^15.2.3",
3838
"@rollup/plugin-terser": "^0.4.4",
39-
"@rollup/plugin-yaml": "^4.1.2",
4039
"@semantic-release/changelog": "^6.0.3",
4140
"@semantic-release/exec": "^6.0.3",
4241
"@semantic-release/git": "^10.0.1",

rollup.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import babel from '@rollup/plugin-babel';
22
import terser from '@rollup/plugin-terser';
33
import { nodeResolve } from '@rollup/plugin-node-resolve';
4-
import yaml from '@rollup/plugin-yaml';
54
import fs from 'fs';
65
import pkg from './package.json';
76

@@ -43,7 +42,7 @@ function build(filename, { src = SRC_DEFAULT, jekyll = false } = {}) {
4342
format: 'iife',
4443
name: 'Chirpy',
4544
banner,
46-
sourcemap: !isProd
45+
sourcemap: !isProd && !jekyll
4746
},
4847
watch: {
4948
include: `${src}/**`
@@ -55,7 +54,6 @@ function build(filename, { src = SRC_DEFAULT, jekyll = false } = {}) {
5554
plugins: ['@babel/plugin-transform-class-properties']
5655
}),
5756
nodeResolve(),
58-
yaml(),
5957
isProd && terser(),
6058
jekyll && insertFrontmatter()
6159
]

0 commit comments

Comments
 (0)