Skip to content

Commit

Permalink
New feature: PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed May 9, 2020
1 parent 49c30b5 commit e1ade75
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 66 deletions.
3 changes: 3 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@

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

<!-- PWA -->
<script src="{{ '/app.js' | relative_url }}" defer></script>

</head>
22 changes: 8 additions & 14 deletions _includes/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@
<div class="access">

{% if site.data.updates %}
{% assign MAX_SIZE = 5 %}
{% assign sum = 0 %}
{% assign sort_list = "" | split: "" %}

{% for entry in site.data.updates %}
{% capture elem %}
{{- entry.lastmod -}}::{{- entry.filename -}}
{% endcapture %}
{% assign sort_list = sort_list | push: elem %}
{% endfor %}
{% include update_list.html %}

{% assign sort_list = sort_list | sort | reverse %}

{% if sort_list.size > 0 %}
{% if update_list.size > 0 %}

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

{% for item in sort_list %}
{% for item in update_list %}
{% assign post_url = item | split: "::" | last | prepend: "/posts/" | append: "/" %}
{% assign post = site.posts | where: "url", post_url | first %}

Expand Down Expand Up @@ -60,7 +50,11 @@ <h3 data-toc-skip>
{{- site.data.label.panel.trending_tags -}}
</h3>
<div class="d-flex flex-wrap mt-3 mb-1 mr-3">
{% include trending-tags.html %}
{% include trending-tags.html %}
{% for tag in trending_tags %}
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
<a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a>
{% endfor %}
</div>
</div>

Expand Down
20 changes: 12 additions & 8 deletions _includes/trending-tags.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<!--
{% comment %}
The trending tags list
v2.0
https://github.com/cotes2020/jekyll-theme-chirpy
© 2019 Cotes Chung
MIT Licensed
-->
{% endcomment %}

{% assign MAX = 10 %}

{% capture tags_array %}
{% for tag in site.tags %}
{{ tag[1] | size }}:{{ tag[0] | replace: ' ', '-' }}
{{ tag[1] | size }}::{{ tag[0] | replace: ' ', '-' }}
{% endfor %}
{% endcapture %}

{% assign trends = tags_array | split: " " | sort | reverse %}
{% assign all_tags = tags_array | split: " " | sort | reverse %}
{% assign count = 0 %}

{% for trend in trends %}
{% assign trending_tags = "" | split: "" %}

{% for iter in all_tags %}
{% assign count = count | plus: 1 %}
{% assign tag = trend | split: ":" | last %}
<a class="post-tag" href="{{ site.baseurl }}/tags/{{ tag | downcase | url_encode }}/">{{ tag | replace: '-', ' ' }}</a>
{% assign tag = iter | split: "::" | last %}

{% assign trending_tags = trending_tags | push: tag %}

{% if count >= MAX %}
{% break %}
{% endif %}
{% endfor %}
{% endfor %}
21 changes: 21 additions & 0 deletions _includes/update_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% comment %}
Get the last 5 post from lastmod list.
v2.2
https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung
MIT License
{% endcomment %}

{% assign MAX_SIZE = 5 %}
{% assign sum = 0 %}
{% assign update_list = "" | split: "" %}

{% for entry in site.data.updates %}
{% capture elem %}
{{- entry.lastmod -}}::{{- entry.filename -}}
{% endcapture %}

{% assign update_list = update_list | push: elem %}
{% endfor %}

{% assign update_list = update_list | sort | reverse %}
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: compress
# Chirpy v2.2
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2020 Cotes Chung
# MIT Licensed
---

/* Registering Service Worker */
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('{{ "/sw.js" | relative_url }}');
};
112 changes: 112 additions & 0 deletions assets/data/cache-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
# The list to be cached by PWA
# Chirpy v2.2
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2020 Cotes Chung
# MIT Licensed
---

var cacheList = [

/*--- CSS ---*/

'{{ "/assets/css/home.css" | relative_url }}',
'{{ "/assets/css/categories.css" | relative_url }}',
'{{ "/assets/css/tags.css" | relative_url }}',
'{{ "/assets/css/archives.css" | relative_url }}',
'{{ "/assets/css/page.css" | relative_url }}',
'{{ "/assets/css/post.css" | relative_url }}',
'{{ "/assets/css/category-tag.css" | relative_url }}',
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.css" | relative_url }}',

/*--- Javascripts ---*/

'{{ "/assets/js/dist/commons.js" | relative_url }}',
'{{ "/assets/js/dist/timeago.min.js" | relative_url }}',
'{{ "/assets/js/dist/category-collapse.min.js" | relative_url }}',
'{{ "/assets/js/dist/toc.min.js" | relative_url }}',
'{{ "/assets/lib/bootstrap-toc-1.0.1/bootstrap-toc.min.js" | relative_url }}',

/*--- HTML ---*/

/* Tabs */
{% for tab in site.data.tabs %}
{% capture item %}
{%- unless tab.name == 'Home' -%}
/tabs/{{ tab.name | downcase }}
{%- endunless -%}
{{- "/" -}}
{% endcapture %}
'{{ item | relative_url }}',
{% endfor %}

/* The posts of first Home page and recent update list */
{% assign post_list = "" | split: "" %}
{% assign sum = 0 %}
{% for post in site.posts %}
{% assign post_list = post_list | push: post.url %}
{% assign sum = sum | plus: 1 %}
{% if sum >= site.paginate %}
{% break %}
{% endif %}
{% endfor %}
{% include update_list.html %}
{% for item in update_list %}
{% assign url = item | split: "::" | last | prepend: "/posts/" | append: "/" %}
{% assign post_list = post_list | push: url %}
{% endfor %}
{% assign post_list = post_list | uniq %}
{% for url in post_list %}
'{{ url }}',
{% endfor %}
/* Trending tags */
{% include trending-tags.html %}
{% for tag in trending_tags %}
{% capture tag_url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
'{{ tag_url | relative_url }}',
{% endfor %}
/*--- Icons ---*/
{%- capture icon_url -%}
{{ "/assets/img/favicons" | relative_url }}
{%- endcapture -%}
'{{ icon_url }}/favicon.ico',
'{{ icon_url }}/apple-icon.png',
'{{ icon_url }}/apple-icon-precomposed.png',
'{{ icon_url }}/apple-icon-57x57.png',
'{{ icon_url }}/apple-icon-60x60.png',
'{{ icon_url }}/apple-icon-72x72.png',
'{{ icon_url }}/apple-icon-76x76.png',
'{{ icon_url }}/apple-icon-114x114.png',
'{{ icon_url }}/apple-icon-120x120.png',
'{{ icon_url }}/apple-icon-144x144.png',
'{{ icon_url }}/apple-icon-152x152.png',
'{{ icon_url }}/apple-icon-180x180.png',
'{{ icon_url }}/android-icon-192x192.png',
'{{ icon_url }}/favicon-32x32.png',
'{{ icon_url }}/favicon-96x96.png',
'{{ icon_url }}/favicon-16x16.png',
'{{ icon_url }}/ms-icon-144x144.png',
'{{ icon_url }}/manifest.json',
'{{ icon_url }}/browserconfig.xml',
/*--- Others ---*/
{% if site.google_analytics.pv.enabled %}
'{{ "/assets/data/pv-data.json" | relative_url }}',
'{{ "/assets/lib/countUp.min.js" | relative_url }}',
'{{ "/assets/js/dist/pageviews.min.js" | relative_url }}',
{% endif %}
'{{ "/assets/data/search.json" | relative_url }}',
'{{ "/404.html" | relative_url }}',
'{{ "/app.js" | relative_url }}',
'{{ "/sw.js" | relative_url }}'
];
1 change: 0 additions & 1 deletion assets/data/pv-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: compress
---

const proxyData = '{"url": "{{ site.google_analytics.pv.proxy_endpoint }}"}';
Expand Down
1 change: 0 additions & 1 deletion assets/data/search.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: compress
---

[
Expand Down
91 changes: 49 additions & 42 deletions assets/img/favicons/manifest.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
---
layout: compress

#
# A part of the Favicons
# v2.0
# Chirpy v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2019 Cotes Chung
# MIT License
---

{% assign icon_url = "/assets/img/favicons/" | relative_url %}

{
"name": "App",
"icons": [
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-36x36.png",
"sizes": "36x36",
"type": "image\/png",
"density": "0.75"
},
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-48x48.png",
"sizes": "48x48",
"type": "image\/png",
"density": "1.0"
},
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-72x72.png",
"sizes": "72x72",
"type": "image\/png",
"density": "1.5"
},
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-96x96.png",
"sizes": "96x96",
"type": "image\/png",
"density": "2.0"
},
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-144x144.png",
"sizes": "144x144",
"type": "image\/png",
"density": "3.0"
},
{
"src": "{{ site.baseurl }}\/assets\/img\/favicons\/android-icon-192x192.png",
"sizes": "192x192",
"type": "image\/png",
"density": "4.0"
}
]
}
"name": "{{ site.title }}",
"short_name": "{{ site.title }}",
"description": "{{ site.description }}",
"icons": [
{
"src": "{{ icon_url }}/android-icon-36x36.png",
"sizes": "36x36",
"type": "image/png",
"density": "0.75"
},
{
"src": "{{ icon_url }}/android-icon-48x48.png",
"sizes": "48x48",
"type": "image/png",
"density": "1.0"
},
{
"src": "{{ icon_url }}/android-icon-72x72.png",
"sizes": "72x72",
"type": "image/png",
"density": "1.5"
},
{
"src": "{{ icon_url }}/android-icon-96x96.png",
"sizes": "96x96",
"type": "image/png",
"density": "2.0"
},
{
"src": "{{ icon_url }}/android-icon-144x144.png",
"sizes": "144x144",
"type": "image/png",
"density": "3.0"
},
{
"src": "{{ icon_url }}/android-icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"density": "4.0"
}],
"start_url": "{{ '/index.html' | relative_url }}",
"display": "fullscreen",
"theme_color": "#2a1e6b",
"background_color": "white"
}
Loading

0 comments on commit e1ade75

Please sign in to comment.