feat: add option to turn off PWA (#527)
This commit is contained in:
parent
d127183b97
commit
106c981bac
4 changed files with 35 additions and 14 deletions
|
@ -115,6 +115,9 @@ assets:
|
||||||
# only works if `assets.self_host.enabled` is 'true'
|
# only works if `assets.self_host.enabled` is 'true'
|
||||||
env: # [development|production]
|
env: # [development|production]
|
||||||
|
|
||||||
|
pwa:
|
||||||
|
enabled: true # the option for PWA feature
|
||||||
|
|
||||||
paginate: 10
|
paginate: 10
|
||||||
|
|
||||||
# ------------ The following options are not recommended to be modified ------------------
|
# ------------ The following options are not recommended to be modified ------------------
|
||||||
|
|
|
@ -90,7 +90,11 @@
|
||||||
|
|
||||||
{% if jekyll.environment == 'production' %}
|
{% if jekyll.environment == 'production' %}
|
||||||
<!-- PWA -->
|
<!-- PWA -->
|
||||||
<script defer src="{{ '/app.js' | relative_url }}"></script>
|
{% if site.pwa.enabled %}
|
||||||
|
<script defer src="{{ '/app.js' | relative_url }}"></script>
|
||||||
|
{% else %}
|
||||||
|
<script defer src="{{ '/unregister.js' | relative_url }}"></script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- GA -->
|
<!-- GA -->
|
||||||
{% if site.google_analytics.id != empty and site.google_analytics.id %}
|
{% if site.google_analytics.id != empty and site.google_analytics.id %}
|
||||||
|
|
|
@ -48,20 +48,22 @@ layout: compress
|
||||||
<i class="fas fa-angle-up"></i>
|
<i class="fas fa-angle-up"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
|
{% if site.pwa.enabled %}
|
||||||
data-animation="true" data-autohide="false">
|
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
|
||||||
<div class="toast-header">
|
data-animation="true" data-autohide="false">
|
||||||
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
|
<div class="toast-header">
|
||||||
<span aria-hidden="true">×</span>
|
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
|
||||||
</button>
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="toast-body text-center pt-0">
|
||||||
|
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[lang].notification.update_found }}</p>
|
||||||
|
<button type="button" class="btn btn-primary" aria-label="Update">
|
||||||
|
{{ site.data.locales[lang].notification.update }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="toast-body text-center pt-0">
|
{% endif %}
|
||||||
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[lang].notification.update_found }}</p>
|
|
||||||
<button type="button" class="btn btn-primary" aria-label="Update">
|
|
||||||
{{ site.data.locales[lang].notification.update }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% include search-loader.html %}
|
{% include search-loader.html %}
|
||||||
|
|
||||||
|
|
12
assets/js/pwa/unregister.js
Normal file
12
assets/js/pwa/unregister.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
layout: compress
|
||||||
|
permalink: '/unregister.js'
|
||||||
|
---
|
||||||
|
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||||
|
for (let reg of registrations) {
|
||||||
|
reg.unregister();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue