Skip to content

Commit

Permalink
feat: add option to turn off PWA (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Jun 4, 2022
1 parent d127183 commit 106c981
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ assets:
# only works if `assets.self_host.enabled` is 'true'
env: # [development|production]

pwa:
enabled: true # the option for PWA feature

paginate: 10

# ------------ The following options are not recommended to be modified ------------------
Expand Down
6 changes: 5 additions & 1 deletion _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@

{% if jekyll.environment == 'production' %}
<!-- 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 -->
{% if site.google_analytics.id != empty and site.google_analytics.id %}
Expand Down
28 changes: 15 additions & 13 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@
<i class="fas fa-angle-up"></i>
</a>

<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
data-animation="true" data-autohide="false">
<div class="toast-header">
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{% if site.pwa.enabled %}
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
data-animation="true" data-autohide="false">
<div class="toast-header">
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">&times;</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 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>
{% endif %}

{% include search-loader.html %}

Expand Down
12 changes: 12 additions & 0 deletions assets/js/pwa/unregister.js
Original file line number Diff line number Diff line change
@@ -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();
}
});
}

0 comments on commit 106c981

Please sign in to comment.