feat: add option to turn off PWA (#527)

This commit is contained in:
Cotes Chung 2022-06-05 00:10:20 +08:00
parent d127183b97
commit 106c981bac
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
4 changed files with 35 additions and 14 deletions

View file

@ -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 ------------------

View file

@ -90,7 +90,11 @@
{% if jekyll.environment == 'production' %} {% if jekyll.environment == 'production' %}
<!-- PWA --> <!-- PWA -->
{% if site.pwa.enabled %}
<script defer src="{{ '/app.js' | relative_url }}"></script> <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 %}

View file

@ -48,6 +48,7 @@ layout: compress
<i class="fas fa-angle-up"></i> <i class="fas fa-angle-up"></i>
</a> </a>
{% if site.pwa.enabled %}
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true" <div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
data-animation="true" data-autohide="false"> data-animation="true" data-autohide="false">
<div class="toast-header"> <div class="toast-header">
@ -62,6 +63,7 @@ layout: compress
</button> </button>
</div> </div>
</div> </div>
{% endif %}
{% include search-loader.html %} {% include search-loader.html %}

View 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();
}
});
}