1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 13:44:15 +00:00

fix(pwa): site baseurl not passed to app.js (#1955)

This commit is contained in:
Cotes Chung
2024-09-18 22:32:26 +08:00
committed by GitHub
parent 3ab3b844d2
commit 5a63244721
5 changed files with 14 additions and 12 deletions

View File

@@ -1,15 +1,19 @@
import { pwa, baseurl } from '../../_config.yml';
import Toast from 'bootstrap/js/src/toast';
if ('serviceWorker' in navigator) {
if (pwa.enabled) {
const swUrl = `${baseurl}/sw.min.js`;
// Get Jekyll config from URL parameters
const src = new URL(document.currentScript.src);
const register = src.searchParams.get('register');
const baseUrl = src.searchParams.get('baseurl');
if (register) {
const swUrl = `${baseUrl}/sw.min.js`;
const notification = document.getElementById('notification');
const btnRefresh = notification.querySelector('.toast-body>button');
const popupWindow = Toast.getOrCreateInstance(notification);
navigator.serviceWorker.register(swUrl).then((registration) => {
// In case the user ignores the notification
// Restore the update window that was last manually closed by the user
if (registration.waiting) {
popupWindow.show();
}

View File

@@ -1,6 +1,4 @@
import { baseurl } from '../../_config.yml';
importScripts(`${baseurl}/assets/js/data/swconf.js`);
importScripts('./assets/js/data/swconf.js');
const purge = swconf.purge;
const interceptor = swconf.interceptor;