Merge branch 'master' into production
This commit is contained in:
commit
b9d053b3cd
32 changed files with 304 additions and 184 deletions
2
.github/codeql/codeql-config.yml
vendored
Normal file
2
.github/codeql/codeql-config.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
paths-ignore:
|
||||
- "assets/js"
|
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
|
@ -7,7 +7,7 @@ updates:
|
|||
bundler:
|
||||
dependency-type: "production"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
versioning-strategy: increase
|
||||
|
@ -15,7 +15,7 @@ updates:
|
|||
npm:
|
||||
dependency-type: "development"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
groups:
|
||||
|
@ -23,4 +23,4 @@ updates:
|
|||
update-types:
|
||||
- "major"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
interval: "weekly"
|
||||
|
|
7
.github/workflows/codeql.yml
vendored
7
.github/workflows/codeql.yml
vendored
|
@ -2,11 +2,9 @@ name: "CodeQL"
|
|||
|
||||
on:
|
||||
push:
|
||||
paths: ["**.js"]
|
||||
paths: ["_javascript/**/*.js"]
|
||||
pull_request:
|
||||
paths: ["**.js"]
|
||||
schedule:
|
||||
- cron: "0 0 * * 5"
|
||||
paths: ["_javascript/**/*.js"]
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
|
@ -32,6 +30,7 @@ jobs:
|
|||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: "${{ matrix.language }}"
|
||||
config-file: .github/codeql/codeql-config.yml
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
|
|
4
.github/workflows/stale.yml
vendored
4
.github/workflows/stale.yml
vendored
|
@ -22,8 +22,8 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
days-before-stale: 30
|
||||
days-before-close: 1
|
||||
# 60 days before marking issues/PRs stale
|
||||
days-before-close: -1 # does not close automatically
|
||||
stale-issue-label: ${{ env.STALE_LABEL }}
|
||||
exempt-issue-labels: ${{ env.EXEMPT_LABELS }}
|
||||
stale-issue-message: ${{ env.MESSAGE }}
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -16,7 +16,6 @@ package-lock.json
|
|||
|
||||
# IDE configurations
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
# Misc
|
||||
assets/js/dist
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx --no -- commitlint -x $(npm root -g)/@commitlint/config-conventional --edit
|
||||
npx --no -- commitlint --edit ${1}
|
||||
|
|
12
.vscode/extensions.json
vendored
Normal file
12
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"recommendations": [
|
||||
// Liquid tags auto-complete
|
||||
"killalau.vscode-liquid-snippets",
|
||||
// Liquid syntax highlighting and formatting
|
||||
"Shopify.theme-check-vscode",
|
||||
// Common formatter
|
||||
"esbenp.prettier-vscode",
|
||||
"foxundermoon.shell-format",
|
||||
"stylelint.vscode-stylelint"
|
||||
]
|
||||
}
|
24
.vscode/settings.json
vendored
Normal file
24
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
// Prettier
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"prettier.trailingComma": "none",
|
||||
// Shopify Liquid
|
||||
"files.associations": {
|
||||
"*.html": "liquid"
|
||||
},
|
||||
// Formatter
|
||||
"[html][liquid]": {
|
||||
"editor.defaultFormatter": "Shopify.theme-check-vscode"
|
||||
},
|
||||
"[shellscript]": {
|
||||
"editor.defaultFormatter": "foxundermoon.shell-format"
|
||||
},
|
||||
// Disable vscode built-in stylelint
|
||||
"css.validate": false,
|
||||
"scss.validate": false,
|
||||
"less.validate": false,
|
||||
// Stylint extension settings
|
||||
"stylelint.snippet": ["css", "less", "postcss", "scss"],
|
||||
"stylelint.validate": ["css", "less", "postcss", "scss"]
|
||||
}
|
|
@ -34,7 +34,7 @@
|
|||
- Built-in Search
|
||||
- Atom Feeds
|
||||
- PWA
|
||||
- Google Analytics
|
||||
- Google Analytics / GoatCounter
|
||||
- SEO & Performance Optimization
|
||||
|
||||
## Documentation
|
||||
|
|
20
_config.yml
20
_config.yml
|
@ -52,6 +52,9 @@ google_site_verification: # fill in to your verification string
|
|||
google_analytics:
|
||||
id: # fill in your Google Analytics ID
|
||||
|
||||
goatcounter:
|
||||
id: # fill in your Goatcounter ID
|
||||
|
||||
# Prefer color scheme setting.
|
||||
#
|
||||
# Note: Keep empty will follow the system prefer color by default,
|
||||
|
@ -63,7 +66,7 @@ google_analytics:
|
|||
# light - Use the light color scheme
|
||||
# dark - Use the dark color scheme
|
||||
#
|
||||
theme_mode: # [light|dark]
|
||||
theme_mode: # [light | dark]
|
||||
|
||||
# The CDN endpoint for images.
|
||||
# Notice that once it is assigned, the CDN url
|
||||
|
@ -108,10 +111,17 @@ assets:
|
|||
enabled: # boolean, keep empty means false
|
||||
# specify the Jekyll environment, empty means both
|
||||
# only works if `assets.self_host.enabled` is 'true'
|
||||
env: # [development|production]
|
||||
env: # [development | production]
|
||||
|
||||
pwa:
|
||||
enabled: true # the option for PWA feature
|
||||
enabled: true # the option for PWA feature (installable)
|
||||
cache:
|
||||
enabled: true # the option for PWA offline cache
|
||||
# Paths defined here will be excluded from the PWA cache.
|
||||
# Usually its value is the `baseurl` of another website that
|
||||
# shares the same domain name as the current website.
|
||||
deny_paths:
|
||||
# - "/example" # URLs match `<SITE_URL>/example/*` will not be cached by the PWA
|
||||
|
||||
paginate: 10
|
||||
|
||||
|
@ -157,10 +167,6 @@ defaults:
|
|||
values:
|
||||
layout: page
|
||||
permalink: /:title/
|
||||
- scope:
|
||||
path: assets/img/favicons
|
||||
values:
|
||||
swcache: true
|
||||
- scope:
|
||||
path: assets/js/dist
|
||||
values:
|
||||
|
|
|
@ -8,6 +8,8 @@ cdns:
|
|||
- url: https://fonts.googleapis.com
|
||||
# jsDelivr CDN
|
||||
- url: https://cdn.jsdelivr.net
|
||||
# polyfill.io for math
|
||||
- url: https://polyfill.io
|
||||
|
||||
# fonts
|
||||
|
||||
|
@ -33,7 +35,7 @@ search:
|
|||
js: https://cdn.jsdelivr.net/npm/simple-jekyll-search@1.10.0/dest/simple-jekyll-search.min.js
|
||||
|
||||
mermaid:
|
||||
js: https://cdn.jsdelivr.net/npm/mermaid@10.6.1/dist/mermaid.min.js
|
||||
js: https://cdn.jsdelivr.net/npm/mermaid@10.8.0/dist/mermaid.min.js
|
||||
|
||||
dayjs:
|
||||
js:
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
<link rel="apple-touch-icon" sizes="180x180" href="{{ favicon_path }}/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="{{ favicon_path }}/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="{{ favicon_path }}/favicon-16x16.png">
|
||||
<link rel="manifest" href="{{ favicon_path }}/site.webmanifest">
|
||||
{% if site.pwa.enabled %}
|
||||
<link rel="manifest" href="{{ favicon_path }}/site.webmanifest">
|
||||
{% endif %}
|
||||
<link rel="shortcut icon" href="{{ favicon_path }}/favicon.ico">
|
||||
<meta name="apple-mobile-web-app-title" content="{{ site.title }}">
|
||||
<meta name="application-name" content="{{ site.title }}">
|
||||
|
|
|
@ -8,9 +8,15 @@
|
|||
"
|
||||
>
|
||||
<p>
|
||||
{{ '©' }}
|
||||
{{- '©' }}
|
||||
<time>{{ 'now' | date: '%Y' }}</time>
|
||||
|
||||
{% if site.social.links %}
|
||||
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>.
|
||||
{% else %}
|
||||
<em class="fst-normal">{{ site.social.name }}</em>.
|
||||
{% endif %}
|
||||
|
||||
{% if site.data.locales[include.lang].copyright.brief %}
|
||||
<span
|
||||
data-bs-toggle="tooltip"
|
||||
|
|
8
_includes/goatcounter.html
Normal file
8
_includes/goatcounter.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<!-- GoatCounter -->
|
||||
|
||||
<script
|
||||
data-goatcounter="https://{{ site.goatcounter.id }}.goatcounter.com/count"
|
||||
async
|
||||
src="https://gc.zgo.at/count.js"
|
||||
></script>
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
{% unless src contains '://' %}
|
||||
{%- capture img_url -%}
|
||||
{% include img-url.html src=src img_path=page.img_path %}
|
||||
{% include img-url.html src=src img_path=page.img_path absolute=true %}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
|
||||
|
@ -31,15 +31,20 @@
|
|||
|
||||
{% elsif site.social_preview_image %}
|
||||
{%- capture img_url -%}
|
||||
{% include img-url.html src=site.social_preview_image %}
|
||||
{% include img-url.html src=site.social_preview_image absolute=true %}
|
||||
{%- endcapture -%}
|
||||
|
||||
{%- capture og_image -%}
|
||||
<meta property="og:image" content="{{ img_url }}" />
|
||||
{%- endcapture -%}
|
||||
|
||||
{% assign old_meta_clip = '<meta name="twitter:card"' %}
|
||||
{% assign new_meta_clip = og_image | append: old_meta_clip %}
|
||||
{%- capture twitter_image -%}
|
||||
<meta property="twitter:card" content="summary_large_image" />
|
||||
<meta property="twitter:image" content="{{ img_url }}" />
|
||||
{%- endcapture -%}
|
||||
|
||||
{% assign old_meta_clip = '<meta name="twitter:card" content="summary" />' %}
|
||||
{% assign new_meta_clip = og_image | append: twitter_image %}
|
||||
{% assign seo_tags = seo_tags | replace: old_meta_clip, new_meta_clip %}
|
||||
{% endif %}
|
||||
|
||||
|
@ -76,7 +81,7 @@
|
|||
{% endif %}
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<link rel="stylesheet" href="{{ site.data.origin[type].bootstrap.css | relative_url}}">
|
||||
<link rel="stylesheet" href="{{ site.data.origin[type].bootstrap.css | relative_url }}">
|
||||
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="{{ site.data.origin[type].fontawesome.css | relative_url }}">
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
Generate image final URL based on `site.img_cdn`, `page.img_path`
|
||||
|
||||
Arguments:
|
||||
src - basic image path, required
|
||||
img_path - relative path of image, optional
|
||||
src - required, basic image path
|
||||
img_path - optional, relative path of image
|
||||
absolute - optional, boolean, if true, generate absolute URL
|
||||
|
||||
Return:
|
||||
image URL
|
||||
|
@ -14,7 +15,7 @@
|
|||
{%- if url -%}
|
||||
{% unless url contains ':' %}
|
||||
{%- comment -%} CND URL {%- endcomment -%}
|
||||
{% assign prefix = site.img_cdn | default: '' | relative_url %}
|
||||
{% assign prefix = site.img_cdn | default: '' %}
|
||||
|
||||
{%- comment -%} Add page image path prefix {%- endcomment -%}
|
||||
{% assign url = include.img_path | default: '' | append: '/' | append: url %}
|
||||
|
@ -26,6 +27,12 @@
|
|||
| replace: '//', '/'
|
||||
| replace: ':', ':/'
|
||||
%}
|
||||
|
||||
{% if include.absolute %}
|
||||
{% assign url = url | absolute_url %}
|
||||
{% else %}
|
||||
{% assign url = url | relative_url %}
|
||||
{% endif %}
|
||||
{% endunless %}
|
||||
{%- endif -%}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
<!-- layout specified -->
|
||||
|
||||
{% assign js_dist = '/assets/js/dist/' %}
|
||||
|
||||
{% if page.layout == 'post' or page.layout == 'page' or page.layout == 'home' %}
|
||||
{% assign urls = urls | append: ',' | append: site.data.origin[type]['lazy-polyfill'].js %}
|
||||
|
||||
|
@ -65,7 +67,7 @@
|
|||
{% assign js = 'commons' %}
|
||||
{% endcase %}
|
||||
|
||||
{% capture script %}/assets/js/dist/{{ js }}.min.js{% endcapture %}
|
||||
{% capture script %}{{ js_dist }}{{ js }}.min.js{% endcapture %}
|
||||
<script defer src="{{ script | relative_url }}"></script>
|
||||
|
||||
{% if page.math %}
|
||||
|
@ -83,7 +85,9 @@
|
|||
displayMath: [
|
||||
['$$', '$$'],
|
||||
['\\[', '\\]']
|
||||
]
|
||||
],
|
||||
/* equation numbering */
|
||||
tags: 'ams'
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -94,13 +98,16 @@
|
|||
{% if jekyll.environment == 'production' %}
|
||||
<!-- PWA -->
|
||||
{% if site.pwa.enabled %}
|
||||
<script defer src="{{ '/app.js' | relative_url }}"></script>
|
||||
{% else %}
|
||||
<script defer src="{{ '/unregister.js' | relative_url }}"></script>
|
||||
<script defer src="{{ 'app.min.js' | prepend: js_dist | relative_url }}"></script>
|
||||
{% endif %}
|
||||
|
||||
<!-- GA -->
|
||||
{% if site.google_analytics.id != empty and site.google_analytics.id %}
|
||||
{% include google-analytics.html %}
|
||||
{% endif %}
|
||||
|
||||
<!-- GoatCounter -->
|
||||
{% if site.goatcounter.id != empty and site.goatcounter.id %}
|
||||
{% include goatcounter.html %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
{% if forloop.first %}
|
||||
<span>
|
||||
<a href="{{ '/' | relative_url }}">
|
||||
{{ site.data.locales[include.lang].tabs.home | capitalize }}
|
||||
{{- site.data.locales[include.lang].tabs.home | capitalize -}}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
|
@ -30,8 +30,8 @@
|
|||
|
||||
{% elsif page.layout == 'category' or page.layout == 'tag' %}
|
||||
<span>
|
||||
<a href="{{ item | relative_url }}">
|
||||
{{ site.data.locales[include.lang].tabs[item] | default: page.title }}
|
||||
<a href="{{ item | append: '/' | relative_url }}">
|
||||
{{- site.data.locales[include.lang].tabs[item] | default: page.title -}}
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export function toc() {
|
||||
if (document.querySelector('main h2')) {
|
||||
if (document.querySelector('main h2, main h3')) {
|
||||
// see: https://github.com/tscanlin/tocbot#usage
|
||||
tocbot.init({
|
||||
tocSelector: '#toc',
|
||||
|
|
|
@ -134,7 +134,14 @@ fi;
|
|||
|
||||
The mathematics powered by [**MathJax**](https://www.mathjax.org/):
|
||||
|
||||
$$ \sum_{n=1}^\infty 1/n^2 = \frac{\pi^2}{6} $$
|
||||
$$
|
||||
\begin{equation}
|
||||
\sum_{n=1}^\infty 1/n^2 = \frac{\pi^2}{6}
|
||||
\label{eq:series}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
We can reference the equation as \eqref{eq:series}.
|
||||
|
||||
When $a \ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ authors: [<author1_id>, <author2_id>] # for multiple entries
|
|||
---
|
||||
```
|
||||
|
||||
|
||||
Having said that, the key `author` can also identify multiple entries.
|
||||
|
||||
> The benefit of reading the author information from the file `_data/authors.yml`{: .filepath } is that the page will have the meta tag `twitter:creator`, which enriches the [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started#card-and-content-attribution) and is good for SEO.
|
||||
|
@ -110,6 +109,8 @@ math: true
|
|||
After enabling the mathematical feature, you can add math equations with the following syntax:
|
||||
|
||||
- **Block math** should be added with `$$ math $$` with **mandatory** blank lines before and after `$$`
|
||||
- **Inserting equation numbering** should be added with `$$\begin{equation} math \end{equation}$$`
|
||||
- **Referencing equation numbering** should be done with `\label{eq:label_name}` in the equation block and `\eqref{eq:label_name}` inline with text (see example below)
|
||||
- **Inline math** (in lines) should be added with `$$ math $$` without any blank line before or after `$$`
|
||||
- **Inline math** (in lists) should be added with `\$$ math $$`
|
||||
|
||||
|
@ -120,6 +121,17 @@ $$
|
|||
LaTeX_math_expression
|
||||
$$
|
||||
|
||||
<!-- Equation numbering, keep all blank lines -->
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
LaTeX_math_expression
|
||||
\label{eq:label_name}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
Can be referenced as \eqref{eq:label_name}.
|
||||
|
||||
<!-- Inline math in lines, NO blank lines -->
|
||||
|
||||
"Lorem ipsum dolor sit amet, $$ LaTeX_math_expression $$ consectetur adipiscing elit."
|
||||
|
@ -243,7 +255,7 @@ For instance, when using images:
|
|||
The parsing result will automatically add the CDN prefix `https://cdn.com` before the image path:
|
||||
|
||||
```html
|
||||
<img src="https://cdn.com/path/to/flower.png" alt="The flower">
|
||||
<img src="https://cdn.com/path/to/flower.png" alt="The flower" />
|
||||
```
|
||||
{: .nolineno }
|
||||
|
||||
|
@ -267,7 +279,7 @@ And then, the image source of Markdown can write the file name directly:
|
|||
The output will be:
|
||||
|
||||
```html
|
||||
<img src="/img/path/flower.png" alt="The flower">
|
||||
<img src="/img/path/flower.png" alt="The flower" />
|
||||
```
|
||||
{: .nolineno }
|
||||
|
||||
|
@ -420,6 +432,7 @@ You can embed a video with the following syntax:
|
|||
```liquid
|
||||
{% include embed/{Platform}.html id='{ID}' %}
|
||||
```
|
||||
|
||||
Where `Platform` is the lowercase of the platform name, and `ID` is the video ID.
|
||||
|
||||
The following table shows how to get the two parameters we need in a given video URL, and you can also know the currently supported video platforms.
|
||||
|
|
|
@ -101,7 +101,7 @@ Now you can choose _ONE_ of the following methods to deploy your Jekyll site.
|
|||
There are a few things to get ready for.
|
||||
|
||||
- If you're on the GitHub Free plan, keep your site repository public.
|
||||
- If you have committed `Gemfile.lock`{: .filepath} to the repository, and your local machine is not running Linux, go the the root of your site and update the platform list of the lock-file:
|
||||
- If you have committed `Gemfile.lock`{: .filepath} to the repository, and your local machine is not running Linux, go to the root of your site and update the platform list of the lock-file:
|
||||
|
||||
```console
|
||||
$ bundle lock --add-platform x86_64-linux
|
||||
|
|
|
@ -144,6 +144,10 @@ footer {
|
|||
}
|
||||
}
|
||||
|
||||
em {
|
||||
@extend %text-highlight;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
margin-bottom: 0;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
---
|
||||
layout: compress
|
||||
# The list to be cached by PWA
|
||||
---
|
||||
|
||||
const resource = [
|
||||
/* --- CSS --- */
|
||||
'{{ "/assets/css/:THEME.css" | replace: ':THEME', site.theme | relative_url }}',
|
||||
|
||||
/* --- PWA --- */
|
||||
'{{ "/app.js" | relative_url }}',
|
||||
'{{ "/sw.js" | relative_url }}',
|
||||
|
||||
/* --- HTML --- */
|
||||
'{{ "/index.html" | relative_url }}',
|
||||
'{{ "/404.html" | relative_url }}',
|
||||
|
||||
{% for tab in site.tabs %}
|
||||
'{{ tab.url | relative_url }}',
|
||||
{% endfor %}
|
||||
|
||||
/* --- 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 %}
|
||||
];
|
||||
|
||||
/* The request url with below domain will be cached */
|
||||
const allowedDomains = [
|
||||
{% if site.google_analytics.id != empty and site.google_analytics.id %}
|
||||
'www.googletagmanager.com',
|
||||
'www.google-analytics.com',
|
||||
{% endif %}
|
||||
|
||||
'{{ 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',
|
||||
'polyfill.io'
|
||||
];
|
||||
|
||||
/* Requests that include the following path will be banned */
|
||||
const denyUrls = [];
|
51
assets/js/data/swconf.js
Normal file
51
assets/js/data/swconf.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
layout: compress
|
||||
permalink: '/:path/swconf.js'
|
||||
# Note that this file will be fetched by the ServiceWorker, so it will not be cached.
|
||||
---
|
||||
|
||||
const swconf = {
|
||||
{% if site.pwa.cache.enabled %}
|
||||
cacheName: 'chirpy-{{ "now" | date: "%s" }}',
|
||||
|
||||
{%- comment -%} Resources added to the cache during PWA installation. {%- endcomment -%}
|
||||
resources: [
|
||||
'{{ "/assets/css/:THEME.css" | replace: ':THEME', site.theme | relative_url }}',
|
||||
'{{ "/" | relative_url }}',
|
||||
{% for tab in site.tabs %}
|
||||
'{{- tab.url | relative_url -}}',
|
||||
{% endfor %}
|
||||
|
||||
{% assign cache_list = site.static_files | where: 'swcache', true %}
|
||||
{% for file in cache_list %}
|
||||
'{{ file.path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
|
||||
{% endfor %}
|
||||
],
|
||||
|
||||
{%- comment -%} The request url with below domain will be cached. {%- endcomment -%}
|
||||
allowHosts: [
|
||||
{% if site.img_cdn and site.img_cdn contains '//' %}
|
||||
'{{ site.img_cdn | split: '//' | last | split: '/' | first }}',
|
||||
{% endif %}
|
||||
|
||||
{%- unless site.assets.self_host.enabled -%}
|
||||
{% for cdn in site.data.origin["cors"].cdns %}
|
||||
'{{ cdn.url | split: "//" | last }}'
|
||||
{%- unless forloop.last -%},{%- endunless -%}
|
||||
{% endfor %}
|
||||
{% endunless %}
|
||||
],
|
||||
|
||||
{%- comment -%} The request url with below path will not be cached. {%- endcomment -%}
|
||||
denyPaths: [
|
||||
{% for path in site.pwa.cache.deny_paths %}
|
||||
{% unless path == empty %}
|
||||
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
|
||||
{% endunless %}
|
||||
{% endfor %}
|
||||
],
|
||||
purge: false
|
||||
{% else %}
|
||||
purge: true
|
||||
{% endif %}
|
||||
};
|
|
@ -1,17 +1,18 @@
|
|||
---
|
||||
layout: compress
|
||||
permalink: '/app.js'
|
||||
permalink: /assets/js/dist/:basename.min.js
|
||||
---
|
||||
|
||||
const $notification = $('#notification');
|
||||
const $btnRefresh = $('#notification .toast-body>button');
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
/* Registering Service Worker */
|
||||
navigator.serviceWorker.register('{{ "/sw.js" | relative_url }}')
|
||||
.then(registration => {
|
||||
const isEnabled = '{{ site.pwa.enabled }}' === 'true';
|
||||
|
||||
/* in case the user ignores the notification */
|
||||
if (isEnabled) {
|
||||
const swUrl = '{{ '/sw.min.js' | relative_url }}';
|
||||
const $notification = $('#notification');
|
||||
const $btnRefresh = $('#notification .toast-body>button');
|
||||
|
||||
navigator.serviceWorker.register(swUrl).then((registration) => {
|
||||
{% comment %}In case the user ignores the notification{% endcomment %}
|
||||
if (registration.waiting) {
|
||||
$notification.toast('show');
|
||||
}
|
||||
|
@ -26,7 +27,7 @@ if ('serviceWorker' in navigator) {
|
|||
});
|
||||
});
|
||||
|
||||
$btnRefresh.click(() => {
|
||||
$btnRefresh.on('click', () => {
|
||||
if (registration.waiting) {
|
||||
registration.waiting.postMessage('SKIP_WAITING');
|
||||
}
|
||||
|
@ -36,12 +37,18 @@ if ('serviceWorker' in navigator) {
|
|||
|
||||
let refreshing = false;
|
||||
|
||||
/* Detect controller change and refresh all the opened tabs */
|
||||
{% comment %}Detect controller change and refresh all the opened tabs{% endcomment %}
|
||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||
if (!refreshing) {
|
||||
window.location.reload();
|
||||
refreshing = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
||||
for (let registration of registrations) {
|
||||
registration.unregister();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,37 +1,51 @@
|
|||
---
|
||||
layout: compress
|
||||
permalink: '/sw.js'
|
||||
permalink: /:basename.min.js
|
||||
# PWA service worker
|
||||
---
|
||||
|
||||
self.importScripts('{{ "/assets/js/data/swcache.js" | relative_url }}');
|
||||
const swconfUrl = '{{ '/assets/js/data/swconf.js' | relative_url }}';
|
||||
|
||||
const cacheName = 'chirpy-{{ "now" | date: "%s" }}';
|
||||
importScripts(swconfUrl);
|
||||
const purge = swconf.purge;
|
||||
|
||||
function verifyDomain(url) {
|
||||
for (const domain of allowedDomains) {
|
||||
const regex = RegExp(`^http(s)?:\/\/${domain}\/`);
|
||||
function verifyHost(url) {
|
||||
for (const host of swconf.allowHosts) {
|
||||
const regex = RegExp(`^http(s)?://${host}/`);
|
||||
if (regex.test(url)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isExcluded(url) {
|
||||
for (const item of denyUrls) {
|
||||
if (url === item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function verifyUrl(url) {
|
||||
if (!verifyHost(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const requestPath = new URL(url).pathname;
|
||||
|
||||
for (const path of swconf.denyPaths) {
|
||||
if (requestPath.startsWith(path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!purge) {
|
||||
swconf.allowHosts.push(location.host);
|
||||
}
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
if (purge) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.waitUntil(
|
||||
caches.open(cacheName).then((cache) => {
|
||||
return cache.addAll(resource);
|
||||
caches.open(swconf.cacheName).then((cache) => {
|
||||
return cache.addAll(swconf.resources);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -41,8 +55,12 @@ self.addEventListener('activate', (event) => {
|
|||
caches.keys().then((keyList) => {
|
||||
return Promise.all(
|
||||
keyList.map((key) => {
|
||||
if (key !== cacheName) {
|
||||
if (purge) {
|
||||
return caches.delete(key);
|
||||
} else {
|
||||
if (key !== swconf.cacheName) {
|
||||
return caches.delete(key);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -66,22 +84,16 @@ self.addEventListener('fetch', (event) => {
|
|||
return fetch(event.request).then((response) => {
|
||||
const url = event.request.url;
|
||||
|
||||
if (
|
||||
event.request.method !== 'GET' ||
|
||||
!verifyDomain(url) ||
|
||||
isExcluded(url)
|
||||
) {
|
||||
if (purge || event.request.method !== 'GET' || !verifyUrl(url)) {
|
||||
return response;
|
||||
}
|
||||
|
||||
/* see: <https://developers.google.com/web/fundamentals/primers/service-workers#cache_and_return_requests> */
|
||||
{% comment %}See: <https://developers.google.com/web/fundamentals/primers/service-workers#cache_and_return_requests>{% endcomment %}
|
||||
let responseToCache = response.clone();
|
||||
|
||||
caches.open(cacheName).then((cache) => {
|
||||
/* console.log('[sw] Caching new resource: ' + event.request.url); */
|
||||
caches.open(swconf.cacheName).then((cache) => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
|
||||
return response;
|
||||
});
|
||||
})
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
layout: compress
|
||||
permalink: '/unregister.js'
|
||||
---
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||
for (let reg of registrations) {
|
||||
reg.unregister();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit c57724981c36d839881f89540d34d205db06a86f
|
||||
Subproject commit 7bc0d86b6af83d7acfc63db50f29a5975cec2513
|
16
package.json
16
package.json
|
@ -21,16 +21,19 @@
|
|||
"fixlint": "npm run test -- --fix"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.23.7",
|
||||
"@babel/core": "^7.23.9",
|
||||
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
||||
"@babel/preset-env": "^7.23.7",
|
||||
"@babel/preset-env": "^7.23.9",
|
||||
"@commitlint/cli": "^18.6.1",
|
||||
"@commitlint/config-conventional": "^18.6.2",
|
||||
"@rollup/plugin-babel": "^6.0.4",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"husky": "^9.0.11",
|
||||
"rimraf": "^5.0.5",
|
||||
"rollup": "^4.9.2",
|
||||
"rollup": "^4.10.0",
|
||||
"rollup-plugin-license": "^3.2.0",
|
||||
"stylelint": "^16.1.0",
|
||||
"stylelint-config-standard-scss": "^12.0.0"
|
||||
"stylelint": "^16.2.1",
|
||||
"stylelint-config-standard-scss": "^13.0.0"
|
||||
},
|
||||
"prettier": {
|
||||
"trailingComma": "none"
|
||||
|
@ -41,6 +44,9 @@
|
|||
"not dead"
|
||||
],
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
],
|
||||
"rules": {
|
||||
"body-max-line-length": [
|
||||
0,
|
||||
|
|
|
@ -3,21 +3,21 @@ import terser from '@rollup/plugin-terser';
|
|||
import license from 'rollup-plugin-license';
|
||||
import path from 'path';
|
||||
|
||||
const JS_SRC = '_javascript';
|
||||
const JS_DIST = 'assets/js/dist';
|
||||
const SRC_DEFAULT = '_javascript';
|
||||
const DIST_DEFAULT = 'assets/js/dist';
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
function build(filename) {
|
||||
return {
|
||||
input: [`${JS_SRC}/${filename}.js`],
|
||||
input: [`${SRC_DEFAULT}/${filename}.js`],
|
||||
output: {
|
||||
file: `${JS_DIST}/${filename}.min.js`,
|
||||
file: `${DIST_DEFAULT}/${filename}.min.js`,
|
||||
format: 'iife',
|
||||
name: 'Chirpy',
|
||||
sourcemap: !isProd
|
||||
},
|
||||
watch: {
|
||||
include: `${JS_SRC}/**`
|
||||
include: `${SRC_DEFAULT}/**`
|
||||
},
|
||||
plugins: [
|
||||
babel({
|
||||
|
@ -28,7 +28,7 @@ function build(filename) {
|
|||
license({
|
||||
banner: {
|
||||
commentStyle: 'ignored',
|
||||
content: { file: path.join(__dirname, JS_SRC, '_copyright') }
|
||||
content: { file: path.join(__dirname, SRC_DEFAULT, '_copyright') }
|
||||
}
|
||||
}),
|
||||
isProd && terser()
|
||||
|
|
|
@ -70,12 +70,14 @@ _check_git() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
$opt_pre || (
|
||||
if [[ $working_branch != "$DEFAULT_BRANCH" &&
|
||||
$working_branch != hotfix/* &&
|
||||
$working_branch != "$PROD_BRANCH" ]]; then
|
||||
echo "> Abort: Please run on the default, release or patch branch."
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
_check_src() {
|
||||
|
@ -156,7 +158,7 @@ build_gem() {
|
|||
rm -f ./*.gem
|
||||
|
||||
npm run build
|
||||
git add "$JS_DIST" -f # add JS dist to gem
|
||||
git add "$JS_DIST" -f # add JS distribution files to gem
|
||||
gem build "$GEM_SPEC"
|
||||
cp "$JS_DIST"/* "$BACKUP_PATH"
|
||||
|
||||
|
|
Loading…
Reference in a new issue