Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(structure): some improvements on performance of SW and updates #119

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# hidden files
.*
!.gitkeep
!.gitignore

# python compiled files
*.pyc

# jekyll debug
# jekyll debug and generated files
_data/updates.yml
_site
categories
tags

# Jeykll Gemfile.lock
Gemfile.lock
Expand All @@ -15,3 +20,6 @@ Gemfile.lock

# bundle cache
vendor

# standard style
!.editorconfig
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
source "https://rubygems.org"

gem "jekyll", ">=3.8.6"
gem "jekyll", github: "jekyll/jekyll"
gem "liquid-c"

# Official Plugins
group :jekyll_plugins do
gem "jekyll-include-cache"
gem "jekyll-paginate"
gem 'jekyll-pwa-plugin'
gem "jekyll-redirect-from"
gem "jekyll-seo-tag", "~> 2.6.1"
gem "jekyll-seo-tag"
end

group :test do
Expand Down
32 changes: 29 additions & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ disqus:
comments: false # boolean type, the global switch for posts comments.
shortname: '' # Fill with your Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname

onesignal:
id: '' # value with appId of OneSignal app account
subdomain: '' # subdomain name of configured app

# Prefer color scheme setting, available values:
#
Expand Down Expand Up @@ -178,13 +181,15 @@ compress_html:
envs: []

exclude:
- .jekyll-cache
- .gitignore
- vendor # Avoid Jekyll mistakenly read the vendor directory on Travis-CI's VM .
- Gemfile.lock
- Gemfile
- tools
- Gemfile.lock
- docs
- README.md
- tools
- LICENSE
- README.md

sitemap_exclude: # Sitemap will exclude the following items.
fuzzy:
Expand All @@ -200,3 +205,24 @@ sitemap_exclude: # Sitemap will exclude the following items.
- sitemap.xml
- robots.txt
- redirects.json

plugins:
- jekyll-include-cache
- jekyll-paginate
- jekyll-pwa-plugin
- jekyll-redirect-from
- jekyll-seo-tag

pwa:
enabled: true # Optional
sw_src_filepath: service-worker.js # Optional
sw_dest_filename: service-worker.js # Optional
dest_js_directory: assets/js # Required
precache_recent_posts_num: 5 # Optional
precache_glob_directory: / # Optional
precache_glob_patterns: # Optional
- "{js,css,fonts}/**/*.{js,css,eot,svg,ttf,woff}"
- index.html
precache_glob_ignores: # Optional
- sw-register.js
- "fonts/**/*"
2 changes: 1 addition & 1 deletion _data/rights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ brief: Some rights reserved.

verbose: >-
Except where otherwise noted, the blog posts on this site are licensed
under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author.
under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author.
32 changes: 14 additions & 18 deletions _includes/disqus.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
MIT License
-->

<div id="disqus" class="pt-2 pb-2">
<p class="font-italic text-center text-muted small">
Comments powered by <a href="https://disqus.com/">Disqus</a>.
</p>
</div>

<script src="{{ site.baseurl }}/assets/js/lib/jquery.disqusloader.min.js"></script>
<div id="disqus_thread"></div>
<script>
var options = {
scriptUrl: '//{{ site.disqus.shortname }}.disqus.com/embed.js',

disqusConfig: function() {
this.page.url = '{{ site.url | append: site.baseurl | append: page.url }}';
this.page.identifier = '{{ page.url }}';
}
};

$.disqusLoader('#disqus', options);
</script>
var disqus_config = function () {
this.page.url = '{{ site.url | append: site.baseurl | append: page.url }}';
this.page.identifier = '{{ page.url }}';
};
(function () {
var d = document, s = d.createElement('script');
s.src = 'https://{{ site.disqus.shortname }}.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<script id="dsq-count-scr" src="https://{{ site.disqus.shortname }}.disqus.com/count.js" async></script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
14 changes: 7 additions & 7 deletions _includes/google-analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
© 2017-2019 Cotes Chung
MIT License
-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', '{{ site.google_analytics.id }}', 'auto');
ga('send', 'pageview');
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics.id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics.id }}');
</script>
6 changes: 5 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

<!-- GA -->
{% if jekyll.environment == 'production' %}
{% include google-analytics.html %}

<link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials">
<link rel="dns-prefetch" href="https://www.google-analytics.com">

Expand Down Expand Up @@ -70,6 +72,8 @@

<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected]/dist/js/bootstrap.min.js" async></script>

{% include onesignal.html %}

{% include js-selector.html %}

</head>
</head>
6 changes: 3 additions & 3 deletions _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

{% elsif page.layout == 'page' %}

<script src="{{ '/assets/js/page.min.js' | relative_url }}" async></script>

{% if page.type == 'categories' %}
<script src="{{ '/assets/js/categories.min.js' | relative_url }}" async></script>
{% else %}
<script src="{{ '/assets/js/page.min.js' | relative_url }}" async></script>
{% endif %}

{% else %}
Expand All @@ -37,5 +37,5 @@

<!-- PWA -->
{% if jekyll.environment == 'production' %}
<script src="{{ '/app.js' | relative_url }}" defer></script>
<script src="{{ '/sw-register.js' | relative_url }}" defer></script>
{% endif %}
14 changes: 14 additions & 0 deletions _includes/onesignal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- OneSignal snippet implementation -->
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(function () {
OneSignal.init({
appId: "{{ site.onesignal.id }}",
notifyButton: {
enable: true,
},
subdomainName: "{{ site.onesignal.subdomain }}",
});
});
</script>
2 changes: 1 addition & 1 deletion _includes/search-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ <h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4>
</div>
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
{% endif %}
{% endfor %}

</div>
</div>
6 changes: 1 addition & 5 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@
<i class="fas fa-angle-up"></i>
</a>

{% if jekyll.environment == 'production' %}
{% include google-analytics.html %}
{% endif %}

{% include search-loader.html %}

</body>

</html>
</html>
12 changes: 0 additions & 12 deletions app.js

This file was deleted.

2 changes: 1 addition & 1 deletion assets/js/_commons/back-to-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ $(function() {
$("body,html").animate({scrollTop: 0}, 800);
return false;
});
});
});
8 changes: 5 additions & 3 deletions assets/js/_utils/category-collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ $(function() {
var parentPrefix = "h_";

/* close up top-category */
$(".collapse").on("hide.bs.collapse", function() { /* Bootstrap collapse events. */
$(".collapse").on("hide.bs.collapse", function(e) { /* Bootstrap collapse events. */
e.stopPropagation();
var parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
if (parentId) {
$("#" + parentId + " .far.fa-folder-open").attr("class", "far fa-folder fa-fw");
Expand All @@ -21,7 +22,8 @@ $(function() {
});

/* expand the top category */
$(".collapse").on("show.bs.collapse", function() {
$(".collapse").on("show.bs.collapse", function(e) {
e.stopPropagation();
var parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
if (parentId) {
$("#" + parentId + " .far.fa-folder").attr("class", "far fa-folder-open fa-fw");
Expand All @@ -30,4 +32,4 @@ $(function() {
}
});

});
});
34 changes: 34 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// service-worker.js

// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
prefix: 'rios0rios0',
suffix: 'v1',
precache: 'precache',
runtime: 'runtime-cache'
});

// let Service Worker take control of pages ASAP
workbox.skipWaiting();
workbox.clientsClaim();

// let Workbox handle our precache list
workbox.precaching.precacheAndRoute(self.__precacheManifest);

// use `networkFirst` strategy for `*.html`, like all my posts
workbox.routing.registerRoute(
/\.html$/,
workbox.strategies.networkFirst()
);

// use `cacheFirst` strategy for images
workbox.routing.registerRoute(
/assets\/(img|icons)/,
workbox.strategies.cacheFirst()
);

// third party files
workbox.routing.registerRoute(
/^https?:\/\/cdn.staticfile.org/,
workbox.strategies.staleWhileRevalidate()
);
Loading