Skip to content

Commit fa77dfb

Browse files
committed
New feature: PWA
1 parent 5ab1121 commit fa77dfb

10 files changed

Lines changed: 266 additions & 66 deletions

File tree

_includes/head.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,7 @@
144144

145145
<script src="{{ site.baseurl }}/assets/js/dist/tooltip-loader.min.js" async></script>
146146

147+
<!-- PWA -->
148+
<script src="{{ '/app.js' | relative_url }}" defer></script>
149+
147150
</head>

_includes/panel.html

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,18 @@
1111
<div class="access">
1212

1313
{% if site.data.updates %}
14-
{% assign MAX_SIZE = 5 %}
15-
{% assign sum = 0 %}
16-
{% assign sort_list = "" | split: "" %}
1714

18-
{% for entry in site.data.updates %}
19-
{% capture elem %}
20-
{{- entry.lastmod -}}::{{- entry.filename -}}
21-
{% endcapture %}
22-
{% assign sort_list = sort_list | push: elem %}
23-
{% endfor %}
15+
{% include update_list.html %}
2416

25-
{% assign sort_list = sort_list | sort | reverse %}
26-
27-
{% if sort_list.size > 0 %}
17+
{% if update_list.size > 0 %}
2818

2919
<div id="access-lastmod" class="post">
3020
<h3 data-toc-skip>
3121
{{- site.data.label.panel.lastmod -}}
3222
</h3>
3323
<ul class="post-content pl-0 pb-1 ml-1 mt-2">
3424

35-
{% for item in sort_list %}
25+
{% for item in update_list %}
3626
{% assign post_url = item | split: "::" | last | prepend: "/posts/" | append: "/" %}
3727
{% assign post = site.posts | where: "url", post_url | first %}
3828

@@ -60,7 +50,11 @@ <h3 data-toc-skip>
6050
{{- site.data.label.panel.trending_tags -}}
6151
</h3>
6252
<div class="d-flex flex-wrap mt-3 mb-1 mr-3">
63-
{% include trending-tags.html %}
53+
{% include trending-tags.html %}
54+
{% for tag in trending_tags %}
55+
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
56+
<a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a>
57+
{% endfor %}
6458
</div>
6559
</div>
6660

_includes/trending-tags.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
<!--
1+
{% comment %}
22
The trending tags list
33
v2.0
44
https://github.com/cotes2020/jekyll-theme-chirpy
55
© 2019 Cotes Chung
66
MIT Licensed
7-
-->
7+
{% endcomment %}
88

99
{% assign MAX = 10 %}
1010

1111
{% capture tags_array %}
1212
{% for tag in site.tags %}
13-
{{ tag[1] | size }}:{{ tag[0] | replace: ' ', '-' }}
13+
{{ tag[1] | size }}::{{ tag[0] | replace: ' ', '-' }}
1414
{% endfor %}
1515
{% endcapture %}
1616

17-
{% assign trends = tags_array | split: " " | sort | reverse %}
17+
{% assign all_tags = tags_array | split: " " | sort | reverse %}
1818
{% assign count = 0 %}
1919

20-
{% for trend in trends %}
20+
{% assign trending_tags = "" | split: "" %}
21+
22+
{% for iter in all_tags %}
2123
{% assign count = count | plus: 1 %}
22-
{% assign tag = trend | split: ":" | last %}
23-
<a class="post-tag" href="{{ site.baseurl }}/tags/{{ tag | downcase | url_encode }}/">{{ tag | replace: '-', ' ' }}</a>
24+
{% assign tag = iter | split: "::" | last %}
25+
26+
{% assign trending_tags = trending_tags | push: tag %}
27+
2428
{% if count >= MAX %}
2529
{% break %}
2630
{% endif %}
27-
{% endfor %}
31+
{% endfor %}

_includes/update_list.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% comment %}
2+
Get the last 5 post from lastmod list.
3+
v2.2
4+
https://github.com/cotes2020/jekyll-theme-chirpy
5+
© 2020 Cotes Chung
6+
MIT License
7+
{% endcomment %}
8+
9+
{% assign MAX_SIZE = 5 %}
10+
{% assign sum = 0 %}
11+
{% assign update_list = "" | split: "" %}
12+
13+
{% for entry in site.data.updates %}
14+
{% capture elem %}
15+
{{- entry.lastmod -}}::{{- entry.filename -}}
16+
{% endcapture %}
17+
18+
{% assign update_list = update_list | push: elem %}
19+
{% endfor %}
20+
21+
{% assign update_list = update_list | sort | reverse %}

app.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
layout: compress
3+
# Chirpy v2.2
4+
# https://github.com/cotes2020/jekyll-theme-chirpy
5+
# © 2020 Cotes Chung
6+
# MIT Licensed
7+
---
8+
9+
/* Registering Service Worker */
10+
if('serviceWorker' in navigator) {
11+
navigator.serviceWorker.register('{{ "/sw.js" | relative_url }}');
12+
};

assets/data/cache-list.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
# The list to be cached by PWA
3+
# Chirpy v2.2
4+
# https://github.com/cotes2020/jekyll-theme-chirpy
5+
# © 2020 Cotes Chung
6+
# MIT Licensed
7+
---
8+
9+
var cacheList = [
10+
11+
/*--- CSS ---*/
12+
13+
'{{ "/assets/css/home.css" | relative_url }}',
14+
'{{ "/assets/css/categories.css" | relative_url }}',
15+
'{{ "/assets/css/tags.css" | relative_url }}',
16+
'{{ "/assets/css/archives.css" | relative_url }}',
17+
'{{ "/assets/css/page.css" | relative_url }}',
18+
'{{ "/assets/css/post.css" | relative_url }}',
19+
'{{ "/assets/css/category-tag.css" | relative_url }}',
20+
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" | relative_url }}',
21+
22+
/*--- Javascripts ---*/
23+
24+
'{{ "/assets/js/dist/commons.js" | relative_url }}',
25+
'{{ "/assets/js/dist/timeago.min.js" | relative_url }}',
26+
'{{ "/assets/js/dist/category-collapse.min.js" | relative_url }}',
27+
'{{ "/assets/js/dist/toc.min.js" | relative_url }}',
28+
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js" | relative_url }}',
29+
30+
/*--- HTML ---*/
31+
32+
/* Tabs */
33+
{% for tab in site.data.tabs %}
34+
{% capture item %}
35+
{%- unless tab.name == 'Home' -%}
36+
/tabs/{{ tab.name | downcase }}
37+
{%- endunless -%}
38+
{{- "/" -}}
39+
{% endcapture %}
40+
'{{ item | relative_url }}',
41+
{% endfor %}
42+
43+
/* The posts of first Home page and recent update list */
44+
{% assign post_list = "" | split: "" %}
45+
{% assign sum = 0 %}
46+
47+
{% for post in site.posts %}
48+
{% assign post_list = post_list | push: post.url %}
49+
{% assign sum = sum | plus: 1 %}
50+
{% if sum >= site.paginate %}
51+
{% break %}
52+
{% endif %}
53+
{% endfor %}
54+
55+
{% include update_list.html %}
56+
{% for item in update_list %}
57+
{% assign url = item | split: "::" | last | prepend: "/posts/" | append: "/" %}
58+
{% assign post_list = post_list | push: url %}
59+
{% endfor %}
60+
61+
{% assign post_list = post_list | uniq %}
62+
63+
{% for url in post_list %}
64+
'{{ url }}',
65+
{% endfor %}
66+
67+
/* Trending tags */
68+
{% include trending-tags.html %}
69+
{% for tag in trending_tags %}
70+
{% capture tag_url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
71+
'{{ tag_url | relative_url }}',
72+
{% endfor %}
73+
74+
/*--- Icons ---*/
75+
76+
{%- capture icon_url -%}
77+
{{ "/assets/img/favicons" | relative_url }}
78+
{%- endcapture -%}
79+
'{{ icon_url }}/favicon.ico',
80+
'{{ icon_url }}/apple-icon.png',
81+
'{{ icon_url }}/apple-icon-precomposed.png',
82+
'{{ icon_url }}/apple-icon-57x57.png',
83+
'{{ icon_url }}/apple-icon-60x60.png',
84+
'{{ icon_url }}/apple-icon-72x72.png',
85+
'{{ icon_url }}/apple-icon-76x76.png',
86+
'{{ icon_url }}/apple-icon-114x114.png',
87+
'{{ icon_url }}/apple-icon-120x120.png',
88+
'{{ icon_url }}/apple-icon-144x144.png',
89+
'{{ icon_url }}/apple-icon-152x152.png',
90+
'{{ icon_url }}/apple-icon-180x180.png',
91+
'{{ icon_url }}/android-icon-192x192.png',
92+
'{{ icon_url }}/favicon-32x32.png',
93+
'{{ icon_url }}/favicon-96x96.png',
94+
'{{ icon_url }}/favicon-16x16.png',
95+
'{{ icon_url }}/ms-icon-144x144.png',
96+
'{{ icon_url }}/manifest.json',
97+
'{{ icon_url }}/browserconfig.xml',
98+
99+
/*--- Others ---*/
100+
101+
{% if site.google_analytics.pv.enabled %}
102+
'{{ "/assets/data/pv-data.json" | relative_url }}',
103+
'{{ "/assets/lib/countUp.min.js" | relative_url }}',
104+
'{{ "/assets/js/dist/pageviews.min.js" | relative_url }}',
105+
{% endif %}
106+
107+
'{{ "/assets/data/search.json" | relative_url }}',
108+
'{{ "/404.html" | relative_url }}',
109+
110+
'{{ "/app.js" | relative_url }}',
111+
'{{ "/sw.js" | relative_url }}'
112+
];

assets/data/pv-data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
layout: compress
32
---
43

54
const proxyData = '{"url": "{{ site.google_analytics.pv.proxy_endpoint }}"}';

assets/data/search.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
layout: compress
32
---
43

54
[

assets/img/favicons/manifest.json

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
---
22
layout: compress
3-
3+
#
44
# A part of the Favicons
5-
# v2.0
5+
# Chirpy v2.0
66
# https://github.com/cotes2020/jekyll-theme-chirpy
77
# © 2019 Cotes Chung
88
# MIT License
99
---
1010

11+
{% assign icon_url = "/assets/img/favicons/" | relative_url %}
12+
1113
{
12-
"name": "App",
13-
"icons": [
14-
{
15-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-36x36.png",
16-
"sizes": "36x36",
17-
"type": "image\/png",
18-
"density": "0.75"
19-
},
20-
{
21-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-48x48.png",
22-
"sizes": "48x48",
23-
"type": "image\/png",
24-
"density": "1.0"
25-
},
26-
{
27-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-72x72.png",
28-
"sizes": "72x72",
29-
"type": "image\/png",
30-
"density": "1.5"
31-
},
32-
{
33-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-96x96.png",
34-
"sizes": "96x96",
35-
"type": "image\/png",
36-
"density": "2.0"
37-
},
38-
{
39-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-144x144.png",
40-
"sizes": "144x144",
41-
"type": "image\/png",
42-
"density": "3.0"
43-
},
44-
{
45-
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-192x192.png",
46-
"sizes": "192x192",
47-
"type": "image\/png",
48-
"density": "4.0"
49-
}
50-
]
51-
}
14+
"name": "{{ site.title }}",
15+
"short_name": "{{ site.title }}",
16+
"description": "{{ site.description }}",
17+
"icons": [
18+
{
19+
"src": "{{ icon_url }}/android-icon-36x36.png",
20+
"sizes": "36x36",
21+
"type": "image/png",
22+
"density": "0.75"
23+
},
24+
{
25+
"src": "{{ icon_url }}/android-icon-48x48.png",
26+
"sizes": "48x48",
27+
"type": "image/png",
28+
"density": "1.0"
29+
},
30+
{
31+
"src": "{{ icon_url }}/android-icon-72x72.png",
32+
"sizes": "72x72",
33+
"type": "image/png",
34+
"density": "1.5"
35+
},
36+
{
37+
"src": "{{ icon_url }}/android-icon-96x96.png",
38+
"sizes": "96x96",
39+
"type": "image/png",
40+
"density": "2.0"
41+
},
42+
{
43+
"src": "{{ icon_url }}/android-icon-144x144.png",
44+
"sizes": "144x144",
45+
"type": "image/png",
46+
"density": "3.0"
47+
},
48+
{
49+
"src": "{{ icon_url }}/android-icon-192x192.png",
50+
"sizes": "192x192",
51+
"type": "image/png",
52+
"density": "4.0"
53+
}],
54+
"start_url": "{{ '/index.html' | relative_url }}",
55+
"display": "fullscreen",
56+
"theme_color": "#2a1e6b",
57+
"background_color": "white"
58+
}

0 commit comments

Comments
 (0)