From 2c5e67f02b75f4cffeeaf0dba24eb104b9a98ab1 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 3 Feb 2022 01:31:53 +0800 Subject: [PATCH] Improve the SW cache list --- _config.yml | 17 +++++++++++------ assets/js/data/search.json | 1 + assets/js/data/swcache.js | 29 ++++++++++------------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/_config.yml b/_config.yml index 889371d..b5b89a3 100644 --- a/_config.yml +++ b/_config.yml @@ -121,8 +121,7 @@ collections: sort_by: order defaults: - - - scope: + - scope: path: '' # An empty string here means all files in the project type: posts values: @@ -132,18 +131,24 @@ defaults: # DO NOT modify the following parameter unless you are confident enough # to update the code of all other post links in this project. permalink: /posts/:title/ - - - scope: + - scope: path: _drafts values: comments: false - - - scope: + - scope: path: '' type: tabs # see `site.collections` values: layout: page permalink: /:title/ + - scope: + path: assets/img/favicons + values: + swcache: true + - scope: + path: assets/js/dist + values: + swcache: true sass: style: compressed diff --git a/assets/js/data/search.json b/assets/js/data/search.json index 76bee41..0aaf170 100644 --- a/assets/js/data/search.json +++ b/assets/js/data/search.json @@ -1,5 +1,6 @@ --- layout: compress +swcache: true --- [ diff --git a/assets/js/data/swcache.js b/assets/js/data/swcache.js index 4017f74..b004d05 100644 --- a/assets/js/data/swcache.js +++ b/assets/js/data/swcache.js @@ -9,13 +9,7 @@ const resource = [ /* --- CSS --- */ '{{ "/assets/css/style.css" | relative_url }}', - /* --- JavaScripts --- */ - {% assign js_path = "/assets/js" | relative_url %} - '{{ js_path }}/dist/home.min.js', - '{{ js_path }}/dist/page.min.js', - '{{ js_path }}/dist/post.min.js', - '{{ js_path }}/dist/categories.min.js', - '{{ js_path }}/data/search.json', + /* --- PWA --- */ '{{ "/app.js" | relative_url }}', '{{ "/sw.js" | relative_url }}', @@ -26,18 +20,11 @@ const resource = [ '{{ tab.url | relative_url }}', {% endfor %} - /* --- Favicons --- */ - {% assign favicon_path = "/assets/img/favicons" | relative_url %} - - '{{ favicon_path }}/android-chrome-192x192.png', - '{{ favicon_path }}/android-chrome-512x512.png', - '{{ favicon_path }}/apple-touch-icon.png', - '{{ favicon_path }}/favicon-16x16.png', - '{{ favicon_path }}/favicon-32x32.png', - '{{ favicon_path }}/favicon.ico', - '{{ favicon_path }}/mstile-150x150.png', - '{{ favicon_path }}/site.webmanifest', - '{{ favicon_path }}/browserconfig.xml' + /* --- Favicons & compressed JS --- */ + {% assign cache_list = site.static_files | where: 'swcache', true %} + {% for file in cache_list %} + '{{ file.path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%} + {% endfor %} ]; @@ -50,6 +37,10 @@ const allowedDomains = [ '{{ site.url | split: "//" | last }}', + {% if site.img_cdn contains '//' and site.img_cdn %} + '{{ site.img_cdn | split: '//' | last | split: '/' | first }}', + {% endif %} + 'fonts.gstatic.com', 'fonts.googleapis.com', 'cdn.jsdelivr.net',