Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix baseurl not passed to app.js #1955

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
{% if jekyll.environment == 'production' %}
<!-- PWA -->
{% if site.pwa.enabled %}
<script defer src="{{ 'app.min.js' | relative_url }}"></script>
<script
defer
src="{{ 'app.min.js' | relative_url }}?baseurl={{ site.baseurl | default: '' }}&register={{ site.pwa.cache.enabled }}"
></script>
{% endif %}

<!-- Web Analytics -->
Expand Down
12 changes: 8 additions & 4 deletions _javascript/pwa/app.js
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
4 changes: 1 addition & 3 deletions _javascript/pwa/sw.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-yaml": "^4.1.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
Expand Down
4 changes: 1 addition & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import babel from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import yaml from '@rollup/plugin-yaml';
import fs from 'fs';
import pkg from './package.json';

Expand Down Expand Up @@ -43,7 +42,7 @@ function build(filename, { src = SRC_DEFAULT, jekyll = false } = {}) {
format: 'iife',
name: 'Chirpy',
banner,
sourcemap: !isProd
sourcemap: !isProd && !jekyll
},
watch: {
include: `${src}/**`
Expand All @@ -55,7 +54,6 @@ function build(filename, { src = SRC_DEFAULT, jekyll = false } = {}) {
plugins: ['@babel/plugin-transform-class-properties']
}),
nodeResolve(),
yaml(),
isProd && terser(),
jekyll && insertFrontmatter()
]
Expand Down