1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-19 06:06:54 +00:00

Compare commits

...

17 Commits
v2.4 ... v2.4.2

Author SHA1 Message Date
Cotes Chung
b04bb847b1 Merge branch 'hotfix/2.4.2' 2020-07-30 02:50:19 +08:00
Cotes Chung
6ef97f1fad Fixed CI workflow. 2020-07-30 02:48:08 +08:00
Cotes Chung
18bd1a91ef Merge branch 'hotfix/2.4.1' 2020-07-26 18:31:56 +08:00
Cotes Chung
4dd4915bed Update issues template 2020-07-26 18:30:12 +08:00
Cotes Chung
a227ae386d Updated the contribution guide. 2020-07-26 17:06:33 +08:00
Cotes Chung
32bd36f016 Updated the CI/CD scripts. 2020-07-25 23:08:37 +08:00
Cotes Chung
aa23becd14 Split post date format code snippets.
Code improvement
2020-07-24 04:15:38 +08:00
Cotes Chung
b2f0b4cb1b Improved post date display. 2020-07-23 20:57:11 +08:00
Cotes Chung
209058b84a Code improvement.
Passing parameters to includes
2020-07-22 23:02:11 +08:00
Cotes Chung
562fcd4fd8 Fixed posts' base-url on cache list. 2020-07-17 16:27:11 +08:00
Cotes Chung
22115f3797 Optimized update list & fixed sw cache list. 2020-07-16 21:00:19 +08:00
Cotes Chung
9f3619e54a Fixed last-mod display for non-English named posts. 2020-07-16 21:00:19 +08:00
Cotes Chung
5b0aaa5403 Improved script tools.
- Allows posts to be placed in subdirectories (#41, #87).
- Identify posts file with the suffix ‘.markdown’.

**Page creator**
- Pass the posts without any categories or tags.
- Omit the YAML comments for categories/tags.

**Lastmod**
- compatible with one-digit month or day post files.
2020-07-14 23:16:43 +08:00
Cotes Chung
733bb0fbfa Updated the PR template. 2020-07-14 12:03:23 +08:00
Cotes Chung
0d47beba97 Improved the tool scripts.
- Avoid the empty lastmod file.
- Check if there is no post.
- Fixed the prompt message.
2020-07-14 03:24:25 +08:00
Cotes Chung
c0ba181246 Improved the PV fetching.
Discard some of the old permalink PV records.
2020-07-14 03:24:25 +08:00
Cotes Chung
313c44f238 Update Docs. 2020-07-12 01:30:55 +08:00
33 changed files with 311 additions and 283 deletions

View File

@@ -2,15 +2,21 @@
I want to thank you for sparing a time to improve this project! Here are some guidelines for contributing I want to thank you for sparing a time to improve this project! Here are some guidelines for contributing
To ensure that the blog design is not confused, this project does not accept suggestions for design changes, such as color scheme, fonts, typography, etc. If your request is about an enhancement, it is recommended to first submit a `Feature Request` type issue to discuss whether your idea fits the project. To ensure that the blog design is not confused, this project does not accept suggestions for design changes, such as color scheme, fonts, typography, etc. If your request is about an enhancement, it is recommended to first submit a [`Feature Request`](https://github.com/cotes2020/jekyll-theme-chirpy/issues/new?labels=enhancement&template=feature_request.md) issue to discuss whether your idea fits the project.
Generally, contribute to the project by: Generally, contribute to the project by:
1. Fork this project. 1. Fork this project on GitHub and clone it locally.
2. Create a new branch `my-new-feature`(or `fix-a-bug`), then complete the development, commit and push. 2. Create a new branch named `feature/my-feature` (or `feature/fix-a-bug`), which branch from `develop`:
3. Submit a new `Pull Request`.
```console
$ git checkout -b feature/<my-feature> develop
```
> Please note that the new branch name must include the prefix `feature/`.
3. After completing the development, commit and push to remote.
4. Submit a new **pull request** to the `develop` branch of upstream, i.e., `cotes2020/jekyll-theme-chirpy:develop`.
--- ---
:tada:Your volunteering will make the open source world more beautiful, thanks again!:tada: :tada: Your volunteering will make the open source world more beautiful, thanks again! :tada:

View File

@@ -11,7 +11,7 @@ labels: enhancement
- [ ] I have read the [contributing guidelines](https://github.com/cotes2020/jekyll-theme-chirpy/blob/master/.github/CONTRIBUTING.md). - [ ] I have read the [contributing guidelines](https://github.com/cotes2020/jekyll-theme-chirpy/blob/master/.github/CONTRIBUTING.md).
- [ ] There are no similar request on existing issues (including closed ones). - [ ] There are no similar request on existing issues (including closed ones).
- [ ] I have read the [project progress](https://github.com/cotes2020/jekyll-theme-chirpy/projects) and know the current progress of the project. - [ ] I have read the [project progress](https://github.com/cotes2020/jekyll-theme-chirpy/projects) and know the current progress of the project.
- [ ] I was in the `master` branch of the latest code. - [ ] I was in the `develop` branch of the latest code.
## Is your feature request related to a problem? Please describe ## Is your feature request related to a problem? Please describe

View File

@@ -7,20 +7,14 @@ labels: question
<!-- Note: Please follow the template to open a new issue, otherwise your question will probably be ignored. --> <!-- Note: Please follow the template to open a new issue, otherwise your question will probably be ignored. -->
## Checklist ## Checklist
<!-- Please complete the following list of tasks, and then check it by change the "[ ]" to "[x]" --> <!-- Please complete the following list of tasks, and then check it by change the "[ ]" to "[x]" -->
- [ ] I have read the [tutorials](https://chirpy.cotes.info/categories/tutorial/) and know the correct effect of the functional design. - [ ] I have read the [tutorials](https://chirpy.cotes.info/categories/tutorial/) and know the correct effect of the functional design.
- [ ] There are no similar question on existing issues (including closed ones). - [ ] There are no similar question on existing issues (including closed ones).
- [ ] I searched the Internet for related problems, but still couldn't solve it. - [ ] I searched the Internet for related problems, but still couldn't solve it.
- [ ] My question is based on the latest code of `master` branch. - [ ] My question is based on the latest code of `master` branch.
## I don't understand what the ReadMe/Wiki says ## Description
<!-- <!-- Please describe your question. -->
Point out the parts that are hard for you to understand.
-->
## I have other questions
<!--
Please describe your question.
-->

View File

@@ -1,11 +1,10 @@
# Description ## Description
<!-- <!--
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
--> -->
Fixes #(issue) e.g. Fixes #(issue)
## Type of change ## Type of change
@@ -17,7 +16,7 @@ Please select the desired item checkbox and change it to "[x]", then delete opti
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update - [ ] Documentation update
# How Has This Been Tested? ## How has this been tested?
<!-- <!--
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
@@ -26,16 +25,16 @@ Please describe the tests that you ran to verify your changes. Provide instructi
- [ ] I have run `bash ./tools/build.sh && bash ./tools/test.sh` (at the root of the project) locally and passed - [ ] I have run `bash ./tools/build.sh && bash ./tools/test.sh` (at the root of the project) locally and passed
- [ ] I have tested this feature in the browser - [ ] I have tested this feature in the browser
## Test Configuration **Test Configuration**
* Browerser type & version: * Browerser type & version:
* Operating system: * Operating system:
* Bundler version: * Bundler version:
* Ruby version: * Ruby version:
* Jekyl version: * Jekyll version:
# Checklist: ## Checklist:
<!-- Select checkboxes by change the "[ ]" to "[x]" --> <!-- Select checkboxes by change the "[ ]" to "[x]" -->
- [ ] My code follows the [Google style guidelines](https://google.github.io/styleguide/) - [ ] My code follows the [Google style guidelines](https://google.github.io/styleguide/)
- [ ] I have performed a self-review of my own code - [ ] I have performed a self-review of my own code

View File

@@ -1,8 +1,8 @@
name: 'Continuous Integration' name: 'Continuous Integration'
on: on:
push: push:
branches-ignore: branches:
- stable - '*'
tags-ignore: tags-ignore:
- '*' - '*'
paths-ignore: paths-ignore:
@@ -15,7 +15,7 @@ on:
- 'LICENSE' - 'LICENSE'
pull_request: pull_request:
paths: paths:
- "**" - '**'
jobs: jobs:
ci: ci:

View File

@@ -23,7 +23,7 @@ script:
- bash _cibuild.sh - bash _cibuild.sh
branches: branches:
only: stable only: master
git: git:
depth: false # for posts lastmod depth: false # for posts lastmod

View File

@@ -47,15 +47,15 @@ To improve the writing experience, we need to use some script tools. If your mac
* Debian * Debian
```console ```console
$ sudo apt-get install coreutils $ sudo apt-get install coreutils
``` ```
* macOS * macOS
```console ```console
$ brew install coreutils $ brew install coreutils
``` ```
### Jekyll Plugins ### Jekyll Plugins
@@ -66,7 +66,7 @@ $ brew install coreutils
$ git clone git@github.com:USER/jekyll-theme-chirpy.git -b master $ git clone git@github.com:USER/jekyll-theme-chirpy.git -b master
``` ```
and replace the `USER` above to your GitHub username. And replace the `USER` above to your GitHub username.
The first time you run or build the project on local machine, perform the installation of Jekyll plugins. Go to the root of repo and run: The first time you run or build the project on local machine, perform the installation of Jekyll plugins. Go to the root of repo and run:
@@ -82,7 +82,7 @@ $ bundle install
### Directory Structure ### Directory Structure
The main files and related brief introductions are listed below. The main files and related brief introductions are listed below:
```sh ```sh
jekyll-theme-chirpy/ jekyll-theme-chirpy/
@@ -113,8 +113,9 @@ jekyll-theme-chirpy/
As mentioned above, some files or directories should be removed from your repo: As mentioned above, some files or directories should be removed from your repo:
- .travis.yml ```terminal
- .github $ rm -rf .travis.yml .github _posts/*
```
### Configuration ### Configuration
@@ -164,7 +165,7 @@ Before the deployment begins, checkout the file `_config.yml` and make sure that
By deploying the site in this way, you're allowed to push the source code directly to the remote. By deploying the site in this way, you're allowed to push the source code directly to the remote.
> **Note**: If you want to use any third-party Jekyll plugins that not in [this list](https://pages.github.com/versions/), stop reading the current approach and go to [*Option 2: Build locally*](#option-2-build-locally). > **Note**: If you want to use any third-party Jekyll plugins that not on [this list](https://pages.github.com/versions/), stop reading the current approach and go to [*Option 2: Build locally*](#option-2-build-locally).
**1**. Rename the repository to: **1**. Rename the repository to:
@@ -202,7 +203,7 @@ it will automatically generates the *Latest Modified Date* and *Categories / Tag
#### Option 2: Build Locally #### Option 2: Build Locally
For security reasons, GitHub Pages runs on `safe` mode, which means the third-party Jekyll plugins or custom scripts won't work. If you want to use any another plugins that not in the [whitelist](https://pages.github.com/versions/), **you have to generate the site locally rather than on GitHub Pages**. For security reasons, GitHub Pages runs on `safe` mode, which means the third-party Jekyll plugins or custom scripts won't work. If you want to use any other plugin that not on the [whitelist](https://pages.github.com/versions/), **you have to generate the site locally rather than on GitHub Pages**.
**1**. Browse to GitHub website, create a brand new repo named: **1**. Browse to GitHub website, create a brand new repo named:

View File

@@ -6,4 +6,6 @@
tooltip: "%a, %b %e, %Y, %l:%M %p %z" tooltip: "%a, %b %e, %Y, %l:%M %p %z"
post: "%b %e, %Y" post:
long: "%b %e, %Y"
short: "%b %e"

View File

@@ -3,7 +3,10 @@
https://github.com/penibelst/jekyll-compress-html/issues/101 https://github.com/penibelst/jekyll-compress-html/issues/101
https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901 https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901
--> -->
{% if _content contains '<pre class="highlight">' %} {% if include.content contains '<pre class="highlight">' %}
{% assign _content = _content | replace: '<pre class="highlight"><code', '<code' %} {% assign content = include.content | replace: '<pre class="highlight"><code', '<code' %}
{% assign _content = _content | replace: '</code></pre>', '</code>' %} {% assign content = content | replace: '</code></pre>', '</code>' %}
{% endif %} {{ content }}
{% else %}
{{ include.content }}
{% endif %}

View File

@@ -8,18 +8,10 @@
{% if page.layout == 'home' %} {% if page.layout == 'home' %}
{% if site.google_analytics.pv.cache and site.google_analytics.pv.enabled %}
<script src="{{ '/assets/js/data/pv-cache.js' | relative_url }}"></script>
{% endif %}
<script src="{{ '/assets/js/home.min.js' | relative_url }}" async></script> <script src="{{ '/assets/js/home.min.js' | relative_url }}" async></script>
{% elsif page.layout == 'post' %} {% elsif page.layout == 'post' %}
{% if site.google_analytics.pv.cache and site.google_analytics.pv.enabled %}
<script src="{{ '/assets/js/data/pv-cache.js' | relative_url }}"></script>
{% endif %}
<script src="{{ '/assets/js/post.min.js' | relative_url }}" async></script> <script src="{{ '/assets/js/post.min.js' | relative_url }}" async></script>
{% if page.math %} {% if page.math %}

View File

@@ -1,12 +1,14 @@
{% comment %} {% comment %}
Remove line numbers from code snippets. Remove the line number of the code snippet.
v2.2 v2.2
https://github.com/cotes2020/jekyll-theme-chirpy https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung © 2020 Cotes Chung
Published under the MIT License Published under the MIT License
{% endcomment %} {% endcomment %}
{% if _content contains '<td class="rouge-gutter gl"><pre class="lineno">' %} {% assign content = include.content %}
{% assign _content = _content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
{% assign _content = _content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %} {% if content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
{% assign content = content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
{% assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
{% endif %} {% endif %}

View File

@@ -23,17 +23,12 @@
<ul class="post-content pl-0 pb-1 ml-1 mt-2"> <ul class="post-content pl-0 pb-1 ml-1 mt-2">
{% for item in update_list %} {% for item in update_list %}
{% assign post_url = item | split: "::" | last | prepend: "/posts/" | append: "/" %} {% assign post_url = item | split: "::" | last | url_encode | prepend: "/posts/" | append: "/" %}
{% assign post = site.posts | where: "url", post_url | first %} {% assign post = site.posts | where: "url", post_url | first %}
{% if post %} {% if post %}
{% assign url = post.url | relative_url %} {% assign url = post.url | relative_url %}
<li><a href="{{ url }}">{{ post.title }}</a></li> <li><a href="{{ url }}">{{ post.title }}</a></li>
{% assign sum = sum | plus: 1 %}
{% if sum >= MAX_SIZE %} {% break %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View File

@@ -93,15 +93,13 @@
<div class="card"> <div class="card">
<a href="{{ post.url | relative_url }}"> <a href="{{ post.url | relative_url }}">
<div class="card-body"> <div class="card-body">
<span class="timeago small"> {% include timeago.html date=post.date class="small" %}
{{ post.date | date: site.data.date_format.post }}
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
</span>
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3> <h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
<div class="text-muted small"> <div class="text-muted small">
{% assign content = post.content %} <p>
{% include no-linenos.html %} {% include no-linenos.html content=post.content %}
<p>{{ content | markdownify | strip_html | truncate: 200 | replace: '&', '&amp;' }}</p> {{ content | markdownify | strip_html | truncate: 200 }}
</p>
</div> </div>
</div> </div>
</a> </a>

View File

@@ -9,11 +9,14 @@
<div class="col-12 col-xl-11 post-content"> <div class="col-12 col-xl-11 post-content">
<div id="search-hints"> <div id="search-hints">
<h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4> <h4 class="text-muted mb-4">{{ site.data.label.panel.trending_tags }}</h4>
{% include trending-tags.html %} {% include trending-tags.html %}
{% for tag in trending_tags %} {% for tag in trending_tags %}
{% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %} {% capture url %}/tags/{{ tag | downcase | url_encode }}/{% endcapture %}
<a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a> <a class="post-tag" href="{{ url | relative_url }}">{{ tag | replace: '-', ' ' }}</a>
{% endfor %} {% endfor %}
</div> </div>
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div> <div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
</div> </div>

27
_includes/timeago.html Normal file
View File

@@ -0,0 +1,27 @@
<!--
Date format snippet
v2.4.1
https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung
MIT License
-->
<span class="timeago {% if include.class %}{{ include.class }}{% endif %}"
{% if include.tooltip %}
data-toggle="tooltip"
data-placement="bottom"
title="{{ include.date | date: site.data.date_format.tooltip }}"
{% endif %}>
{% assign this_year = site.time | date: "%Y" %}
{% assign post_year = include.date | date: "%Y" %}
{% if post_year == this_year %}
{{ include.date | date: site.data.date_format.post.short }}
{% else %}
{{ include.date | date: site.data.date_format.post.long }}
{% endif %}
<i class="unloaded">{{ include.date | date_to_xmlschema }}</i>
</span>

View File

@@ -7,15 +7,20 @@
{% endcomment %} {% endcomment %}
{% assign MAX_SIZE = 5 %} {% assign MAX_SIZE = 5 %}
{% assign sum = 0 %}
{% assign update_list = "" | split: "" %} {% assign all_list = "" | split: "" %}
{% for entry in site.data.updates %} {% for entry in site.data.updates %}
{% capture elem %} {% capture elem %}
{{- entry.lastmod -}}::{{- entry.filename -}} {{- entry.lastmod -}}::{{- entry.filename -}}
{% endcapture %} {% endcapture %}
{% assign all_list = all_list | push: elem %}
{% assign update_list = update_list | push: elem %}
{% endfor %} {% endfor %}
{% assign update_list = update_list | sort | reverse %} {% assign all_list = all_list | sort | reverse %}
{% assign update_list = "" | split: "" %}
{% for entry in all_list limit:MAX_SIZE %}
{% assign update_list = update_list | push: entry %}
{% endfor %}

View File

@@ -18,7 +18,7 @@ layout: page
<li class="d-flex justify-content-between pl-md-3 pr-md-3"> <li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a> <a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span> <span class="dash flex-grow-1"></span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span> <span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@@ -36,15 +36,12 @@ layout: compress
<div id="main-wrapper"> <div id="main-wrapper">
<div id="main"> <div id="main">
{% capture _content %} {% include fixlinenos.html content=content %}
{{ content }}
{% endcapture %}
{% include fixlinenos.html %}
{{ _content }}
{% include footer.html %} {% include footer.html %}
</div> </div>
{% include search-results.html %} {% include search-results.html %}
</div> <!-- #main-wrapper --> </div> <!-- #main-wrapper -->

View File

@@ -58,20 +58,16 @@ layout: page
</div> </div>
<div class="post-content"> <div class="post-content">
<p> <p>
{% assign _content = post.content %} {% include no-linenos.html content=post.content %}
{% include no-linenos.html %} {{ content | markdownify | strip_html | truncate: 200 }}
{{ _content | markdownify | strip_html | truncate: 200 }}
</p> </p>
</div> </div>
<div class="post-meta text-muted"> <div class="post-meta text-muted">
<!-- posted date --> <!-- posted date -->
<i class="far fa-clock fa-fw"></i> <i class="far fa-clock fa-fw"></i>
<span class="timeago" data-toggle="tooltip" data-placement="bottom" {% include timeago.html date=post.date tooltip=true %}
title="{{ post.date | date: site.data.date_format.tooltip }}">
{{ post.date | date: site.data.date_format.post }}
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
</span>
<!-- page views --> <!-- page views -->
{% if site.google_analytics.pv.enabled %} {% if site.google_analytics.pv.enabled %}
<i class="far fa-eye fa-fw"></i> <i class="far fa-eye fa-fw"></i>

View File

@@ -19,16 +19,12 @@ layout: default
<!-- Published date and author --> <!-- Published date and author -->
<div> <div>
Posted Posted
<span class="timeago" data-toggle="tooltip" data-placement="bottom" {% include timeago.html date=page.date tooltip=true %}
title="{{ page.date | date: site.data.date_format.tooltip }}">
{{ page.date | date: site.data.date_format.post }}
<i class="unloaded">{{ page.date | date_to_xmlschema }}</i>
</span>
by by
<span class="author"> <span class="author">
{% if page.author %} {% if page.author %}
{{ page.author }} {{ page.author }}
{% else%} {% else %}
{{ site.author }} {{ site.author }}
{% endif %} {% endif %}
</span> </span>
@@ -39,17 +35,18 @@ layout: default
{{ page.url | split: "/" | last }} {{ page.url | split: "/" | last }}
{%- endcapture -%} {%- endcapture -%}
{% assign record = site.data.updates | where: "filename", filename | first %} {% for item in site.data.updates %}
{% assign encode_filename = item.filename | url_encode %}
{% if filename == encode_filename %}
{% assign lastmod = item.lastmod %}
{% break %}
{% endif %}
{% endfor %}
{% if record %} {% if lastmod %}
<div> <div>
Updated Updated
<span class="timeago lastmod" {% include timeago.html date=lastmod class="lastmod" tooltip=true %}
data-toggle="tooltip" data-placement="bottom"
title="{{ record.lastmod | date: site.data.date_format.tooltip }}">
{{ record.lastmod | date: site.data.date_format.post }}
<i class="unloaded">{{ record.lastmod | date_to_xmlschema}}</i>
</span>
</div> </div>
{% endif %} {% endif %}

View File

@@ -18,7 +18,7 @@ layout: page
<li class="d-flex justify-content-between pl-md-3 pr-md-3"> <li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a> <a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span> <span class="dash flex-grow-1"></span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span> <span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@@ -15,15 +15,15 @@ To improve the writing experience, we need to use some script tools. If your mac
* Debian * Debian
```console ```console
$ sudo apt-get install coreutils $ sudo apt-get install coreutils
``` ```
* macOS * macOS
```console ```console
$ brew install coreutils $ brew install coreutils
``` ```
## Jekyll Plugins ## Jekyll Plugins
@@ -34,7 +34,7 @@ $ brew install coreutils
$ git clone git@github.com:USER/jekyll-theme-chirpy.git -b master $ git clone git@github.com:USER/jekyll-theme-chirpy.git -b master
``` ```
and replace the `USER` above to your GitHub username. And replace the `USER` above to your GitHub username.
The first time you run or build the project on local machine, perform the installation of Jekyll plugins. Go to the root of repo and run: The first time you run or build the project on local machine, perform the installation of Jekyll plugins. Go to the root of repo and run:
@@ -47,7 +47,7 @@ $ bundle install
## Directory Structure ## Directory Structure
The main files and related brief introductions are listed below. The main files and related brief introductions are listed below:
```sh ```sh
jekyll-theme-chirpy/ jekyll-theme-chirpy/
@@ -77,9 +77,9 @@ jekyll-theme-chirpy/
As mentioned above, some files or directories should be removed from your repo: As mentioned above, some files or directories should be removed from your repo:
- .travis.yml ```terminal
- .github $ rm -rf .travis.yml .github _posts/*
```
## Configuration ## Configuration
@@ -129,7 +129,7 @@ Before the deployment begins, checkout the file `_config.yml` and make sure that
By deploying the site in this way, you're allowed to push the source code directly to the remote. By deploying the site in this way, you're allowed to push the source code directly to the remote.
> **Note**: If you want to use any third-party Jekyll plugins that not in [this list](https://pages.github.com/versions/), stop reading the current approach and go to [*Option 2: Build locally*](#option-2-build-locally). > **Note**: If you want to use any third-party Jekyll plugins that not on [this list](https://pages.github.com/versions/), stop reading the current approach and go to [*Option 2: Build locally*](#option-2-build-locally).
**1**. Rename the repository to: **1**. Rename the repository to:
@@ -167,7 +167,7 @@ it will automatically generates the *Latest Modified Date* and *Categories / Tag
### Option 2: Build Locally ### Option 2: Build Locally
For security reasons, GitHub Pages runs on `safe` mode, which means the third-party Jekyll plugins or custom scripts won't work. If you want to use any another plugins that not in the [whitelist](https://pages.github.com/versions/), **you have to generate the site locally rather than on GitHub Pages**. For security reasons, GitHub Pages runs on `safe` mode, which means the third-party Jekyll plugins or custom scripts won't work. If you want to use any other plugin that not on the [whitelist](https://pages.github.com/versions/), **you have to generate the site locally rather than on GitHub Pages**.
**1**. Browse to GitHub website, create a brand new repo named: **1**. Browse to GitHub website, create a brand new repo named:

View File

@@ -31,20 +31,21 @@ read_categories() {
local _category=$(echo "$_yaml" | grep "^category:") local _category=$(echo "$_yaml" | grep "^category:")
if [[ ! -z "$_categories" ]]; then if [[ ! -z "$_categories" ]]; then
echo "$_categories" | sed "s/categories: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_categories" | sed "s/categories: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
elif [[ ! -z "_category" ]]; then elif [[ ! -z "_category" ]]; then
echo "$_category" | sed "s/category: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_category" | sed "s/category: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
fi fi
} }
read_tags() { read_tags() {
local _yaml=$(_read_yaml $1) local _yaml=$(_read_yaml $1)
echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\]//;s/, */,/g;s/\"//g;s/'//g" echo "$_yaml" | grep "^tags:" | sed "s/tags: *//;s/\[//;s/\].*//;s/, */,/g;s/\"//g;s/'//g"
} }
init() { init() {
if [[ -d categories ]]; then if [[ -d categories ]]; then
rm -rf categories rm -rf categories
fi fi
@@ -53,39 +54,47 @@ init() {
rm -rf tags rm -rf tags
fi fi
if [[ ! -d _posts ]]; then
exit 0
fi
mkdir categories tags mkdir categories tags
} }
create_category() { create_category() {
local _name=$1 if [[ ! -z $1 ]]; then
local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html" local _name=$1
local _filepath="categories/$(echo $_name | sed 's/ /-/g' | awk '{print tolower($0)}').html"
if [[ ! -f $_filepath ]]; then if [[ ! -f $_filepath ]]; then
echo "---" > $_filepath echo "---" > $_filepath
echo "layout: category" >> $_filepath echo "layout: category" >> $_filepath
echo "title: $_name" >> $_filepath echo "title: $_name" >> $_filepath
echo "category: $_name" >> $_filepath echo "category: $_name" >> $_filepath
echo "---" >> $_filepath echo "---" >> $_filepath
((category_count=category_count+1)) ((category_count=category_count+1))
fi
fi fi
} }
create_tag() { create_tag() {
local _name=$1 if [[ ! -z $1 ]]; then
local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html" local _name=$1
local _filepath="tags/$( echo $_name | sed "s/ /-/g;s/'//g" | awk '{print tolower($0)}' ).html"
if [[ ! -f $_filepath ]]; then if [[ ! -f $_filepath ]]; then
echo "---" > $_filepath echo "---" > $_filepath
echo "layout: tag" >> $_filepath echo "layout: tag" >> $_filepath
echo "title: $_name" >> $_filepath echo "title: $_name" >> $_filepath
echo "tag: $_name" >> $_filepath echo "tag: $_name" >> $_filepath
echo "---" >> $_filepath echo "---" >> $_filepath
((tag_count=tag_count+1)) ((tag_count=tag_count+1))
fi
fi fi
} }
@@ -97,46 +106,45 @@ create_tag() {
# $2 - type specified option # $2 - type specified option
######################################### #########################################
create_pages() { create_pages() {
if [[ $1 == '' ]]; then if [[ ! -z $1 ]]; then
exit 0 # split string to array
IFS_BAK=$IFS
IFS=','
local _string=$1
case $2 in
$TYPE_CATEGORY)
for i in ${_string#,}; do
create_category $i
done
;;
$TYPE_TAG)
for i in ${_string#,}; do
create_tag $i
done
;;
*)
;;
esac
IFS=$IFS_BAK
fi fi
# split string to array }
IFS_BAK=$IFS
IFS=','
local _string=$1
case $2 in
$TYPE_CATEGORY)
for i in ${_string#,}; do
create_category $i
done
;;
$TYPE_TAG)
for i in ${_string#,}; do
create_tag $i
done
;;
*)
;;
esac
IFS=$IFS_BAK
}
main() { main() {
init init
for _file in $(ls "_posts") for _file in $(find "_posts" -type f \( -iname \*.md -o -iname \*.markdown \))
do do
local _path="_posts/$_file" local _categories=$(read_categories "$_file")
local _categories=$(read_categories "$_path") local _tags=$(read_tags "$_file")
local _tags=$(read_tags "$_path")
create_pages "$_categories" $TYPE_CATEGORY create_pages "$_categories" $TYPE_CATEGORY
create_pages "$_tags" $TYPE_TAG create_pages "$_tags" $TYPE_TAG

View File

@@ -19,6 +19,7 @@ OUTPUT_FILE=updates.yml
_init() { _init() {
if [[ ! -d "$OUTPUT_DIR" ]]; then if [[ ! -d "$OUTPUT_DIR" ]]; then
mkdir "$OUTPUT_DIR" mkdir "$OUTPUT_DIR"
fi fi
@@ -27,7 +28,9 @@ _init() {
rm -f "$OUTPUT_DIR/$OUTPUT_FILE" rm -f "$OUTPUT_DIR/$OUTPUT_FILE"
fi fi
touch "$OUTPUT_DIR/$OUTPUT_FILE" if [[ ! -d $POST_DIR ]]; then
exit 0
fi
} }
@@ -55,6 +58,10 @@ _has_changed() {
_dump() { _dump() {
local _lasmod="`git log -1 --pretty=%ad --date=iso $2`" local _lasmod="`git log -1 --pretty=%ad --date=iso $2`"
if [[ ! -f "$OUTPUT_DIR/$OUTPUT_FILE" ]]; then
touch "$OUTPUT_DIR/$OUTPUT_FILE"
fi
echo "-" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo "-" >> "$OUTPUT_DIR/$OUTPUT_FILE"
echo " filename: '$1'" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " filename: '$1'" >> "$OUTPUT_DIR/$OUTPUT_FILE"
echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE" echo " lastmod: '$_lasmod'" >> "$OUTPUT_DIR/$OUTPUT_FILE"
@@ -67,14 +74,12 @@ main() {
local _count=0 local _count=0
for _file in $(ls -r "$POST_DIR") for _file in $(find ${POST_DIR} -type f \( -iname \*.md -o -iname \*.markdown \))
do do
_filepath="$POST_DIR/$_file" _filename=$(basename $_file | sed 's/[0-9]\([0-9]*-\)//g;s/\..*//' ) # remove date and extension
_filename="${_file%.*}" # jekyll cannot read the extension of a file, so omit it.
_filename=${_filename:11} # remove the date
if _has_changed "$_filepath"; then if _has_changed "$_file"; then
_dump "$_filename" "$_filepath" _dump "$_filename" "$_file"
((_count=_count+1)) ((_count=_count+1))
fi fi

View File

@@ -13,7 +13,7 @@
{% if site.google_analytics.pv.enabled %} {% if site.google_analytics.pv.enabled %}
const proxyData = '{"url": "{{ site.google_analytics.pv.proxy_endpoint }}"}'; {% include_relative _pv-config.js %}
{% include_relative _utils/pageviews.js %} {% include_relative _utils/pageviews.js %}

14
assets/js/_pv-config.js Normal file
View File

@@ -0,0 +1,14 @@
/*!
PV configuration and Javascript conversion.
*/
const proxyEndpoint = "{{ site.google_analytics.pv.proxy_endpoint }}";
{% if site.google_analytics.pv.cache and site.google_analytics.pv.enabled %}
{% assign enabled = true %}
{% else %}
{% assign enabled = false %}
{% endif %}
const pvCacheEnabled = {{ enabled }};

View File

@@ -24,19 +24,13 @@ function countUp(min, max, destId) {
function countPV(path, rows) { function countPV(path, rows) {
/* path permalink looks like: '/posts/post-title/' */
var fileName = path.replace(/\/posts\//g, '').replace(/\//g, '.html'); /* e.g. post-title.html */
var count = 0; var count = 0;
var _v2_url = path.replace(/posts\//g, ''); /* the v2.0+ blog permalink: "/post-title/" */
for (var i = 0; i < rows.length; ++i) { for (var i = 0; i < rows.length; ++i) {
var gaPath = rows[i][0]; var gaPath = rows[i][0];
if (gaPath == path || if (gaPath == path) { /* path format see: site.permalink */
gaPath == _v2_url ||
gaPath.concat('/') == _v2_url ||
gaPath.slice(gaPath.lastIndexOf('/') + 1) === fileName) { /* old permalink record */
count += parseInt(rows[i][1]); count += parseInt(rows[i][1]);
break;
} }
} }
@@ -95,9 +89,9 @@ var getInitStatus = (function() {
var PvCache = (function() { var PvCache = (function() {
const KEY_PV = "pv"; const KEY_PV = "pv";
const KEY_CREATION = "pv_created_date"; const KEY_CREATION = "pv_created_date";
const KEY_PV_TYPE = "pv_type"; const KEY_PV_SRC = "pv_source";
var PvType = { var Source = {
ORIGIN: "origin", ORIGIN: "origin",
PROXY: "proxy" PROXY: "proxy"
}; };
@@ -116,29 +110,29 @@ var PvCache = (function() {
}, },
saveOriginCache: function(pv) { saveOriginCache: function(pv) {
set(KEY_PV, pv); set(KEY_PV, pv);
set(KEY_PV_TYPE, PvType.ORIGIN ); set(KEY_PV_SRC, Source.ORIGIN );
set(KEY_CREATION, new Date().toJSON() ); set(KEY_CREATION, new Date().toJSON() );
}, },
saveProxyCache: function(pv) { saveProxyCache: function(pv) {
set(KEY_PV, pv); set(KEY_PV, pv);
set(KEY_PV_TYPE, PvType.PROXY ); set(KEY_PV_SRC, Source.PROXY );
set(KEY_CREATION, new Date().toJSON() ); set(KEY_CREATION, new Date().toJSON() );
}, },
isOriginCache: function() { isFromOrigin: function() {
return get(KEY_PV_TYPE) == PvType.ORIGIN; return get(KEY_PV_SRC) == Source.ORIGIN;
}, },
isProxyCache: function() { isFromProxy: function() {
return get(KEY_PV_TYPE) == PvType.PROXY; return get(KEY_PV_SRC) == Source.PROXY;
}, },
isExpired: function() { isExpired: function() {
if (PvCache.isOriginCache() ) { if (PvCache.isFromOrigin() ) {
let date = new Date(get(KEY_CREATION)); let date = new Date(get(KEY_CREATION));
date.setDate(date.getDate() + 1); /* fetch origin-data every day */ date.setDate(date.getDate() + 1); /* update origin records every day */
return Date.now() >= date.getTime(); return Date.now() >= date.getTime();
} else if (PvCache.isProxyCache() ) { } else if (PvCache.isFromProxy() ) {
let date = new Date(get(KEY_CREATION) ); let date = new Date(get(KEY_CREATION) );
date.setHours(date.getHours() + 1); /* proxy-data is updated every hour */ date.setHours(date.getHours() + 1); /* update proxy records per hour */
return Date.now() >= date.getTime(); return Date.now() >= date.getTime();
} }
return false; return false;
@@ -151,7 +145,7 @@ var PvCache = (function() {
}, },
inspectKeys: function() { inspectKeys: function() {
if (localStorage.getItem(KEY_PV) == null if (localStorage.getItem(KEY_PV) == null
|| localStorage.getItem(KEY_PV_TYPE) == null || localStorage.getItem(KEY_PV_SRC) == null
|| localStorage.getItem(KEY_CREATION) == null) { || localStorage.getItem(KEY_CREATION) == null) {
localStorage.clear(); localStorage.clear();
} }
@@ -161,20 +155,33 @@ var PvCache = (function() {
})(); /* PvCache */ })(); /* PvCache */
function fetchOriginPageviews(pvData) { function fetchPageviews(fetchOrigin = true, filterOrigin = false) {
if (pvData === undefined) { /* pvCacheEnabled see: /assets/js/_pv-config.js */
return; if (pvCacheEnabled && fetchOrigin) {
fetch('/assets/js/data/pageviews.json')
.then(response => response.json())
.then(data => {
if (filterOrigin) {
if (PvCache.newerThan(data)) {
return;
}
}
displayPageviews(data);
PvCache.saveOriginCache(JSON.stringify(data));
})
.then(() => fetchProxyPageviews());
} else {
fetchProxyPageviews();
} }
displayPageviews(pvData);
PvCache.saveOriginCache(JSON.stringify(pvData));
} }
function fetchProxyPageviews() { function fetchProxyPageviews() {
let proxy = JSON.parse(proxyData); /* see file '/assets/data/pv-data.json' */
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: proxy.url, url: proxyEndpoint, /* see: /assets/js/_pv-config.js */
dataType: 'jsonp', dataType: 'jsonp',
jsonpCallback: "displayPageviews", jsonpCallback: "displayPageviews",
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
@@ -192,41 +199,24 @@ $(function() {
if ($('.pageviews').length > 0) { if ($('.pageviews').length > 0) {
PvCache.inspectKeys(); PvCache.inspectKeys();
let cache = PvCache.getData(); let cache = PvCache.getData();
if (cache) { if (cache) {
displayPageviews(cache);
if (PvCache.isExpired()) { if (PvCache.isExpired()) {
if (PvCache.isProxyCache() ) { fetchPageviews(true, PvCache.isFromProxy());
let originPvData = pageviews ? JSON.parse(pageviews) : undefined;
if (originPvData) {
if (PvCache.newerThan(originPvData)) {
displayPageviews(cache);
} else {
fetchOriginPageviews(originPvData);
}
}
fetchProxyPageviews(); } else {
} else if (PvCache.isOriginCache() ) { if (PvCache.isFromOrigin()) {
fetchOriginPageviews(originPvData); fetchPageviews(false);
fetchProxyPageviews();
}
} else { /* still valid */
displayPageviews(cache);
if (PvCache.isOriginCache() ) {
fetchProxyPageviews();
} }
} }
} else { } else {
let originPvData = pageviews ? JSON.parse(pageviews) : undefined; fetchPageviews();
fetchOriginPageviews(originPvData);
fetchProxyPageviews();
} }
} }

View File

@@ -8,37 +8,41 @@
$(function() { $(function() {
function timeago(date, isLastmod) { function timeago(iso, isLastmod) {
var now = new Date(); let now = new Date();
var past = new Date(date); let past = new Date(iso);
var seconds = Math.floor((now - past) / 1000);
var year = Math.floor(seconds / 31536000); if (past.getFullYear() != now.getFullYear()) {
if (year >= 1) { toRefresh -= 1;
return year + " year" + (year > 1 ? "s" : "") + " ago"; return past.toLocaleString("en-US", {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} }
var month = Math.floor(seconds / 2592000); if (past.getMonth() != now.getMonth()) {
if (month >= 1) { toRefresh -= 1;
return month + " month" + (month > 1 ? "s" : "") + " ago"; return past.toLocaleString("en-US", {
month: 'short',
day: 'numeric'
});
} }
var week = Math.floor(seconds / 604800); let seconds = Math.floor((now - past) / 1000);
if (week >= 1) {
return week + " week" + (week > 1 ? "s" : "") + " ago";
}
var day = Math.floor(seconds / 86400); let day = Math.floor(seconds / 86400);
if (day >= 1) { if (day >= 1) {
toRefresh -= 1;
return day + " day" + (day > 1 ? "s" : "") + " ago"; return day + " day" + (day > 1 ? "s" : "") + " ago";
} }
var hour = Math.floor(seconds / 3600); let hour = Math.floor(seconds / 3600);
if (hour >= 1) { if (hour >= 1) {
return hour + " hour" + (hour > 1 ? "s" : "") + " ago"; return hour + " hour" + (hour > 1 ? "s" : "") + " ago";
} }
var minute = Math.floor(seconds / 60); let minute = Math.floor(seconds / 60);
if (minute >= 1) { if (minute >= 1) {
return minute + " minute" + (minute > 1 ? "s" : "") + " ago"; return minute + " minute" + (minute > 1 ? "s" : "") + " ago";
} }
@@ -50,29 +54,30 @@ $(function() {
function updateTimeago() { function updateTimeago() {
$(".timeago").each(function() { $(".timeago").each(function() {
if ($(this).children("i").length > 0) { if ($(this).children("i").length > 0) {
var basic = $(this).text();
var isLastmod = $(this).hasClass('lastmod'); var isLastmod = $(this).hasClass('lastmod');
var node = $(this).children("i"); var node = $(this).children("i");
var date = node.text(); /* ISO Dates: 'YYYY-MM-DDTHH:MM:SSZ' */ var date = node.text(); /* ISO Date: 'YYYY-MM-DDTHH:MM:SSZ' */
$(this).text(timeago(date, isLastmod)); $(this).text(timeago(date, isLastmod));
$(this).append(node); $(this).append(node);
} }
}); });
if (vote == 0 && intervalId != undefined) { if (toRefresh == 0 && intervalId != undefined) {
clearInterval(intervalId); /* stop interval */ clearInterval(intervalId); /* stop interval */
} }
return vote; return toRefresh;
} }
var vote = $(".timeago").length; var toRefresh = $(".timeago").length;
if (vote == 0) {
if (toRefresh == 0) {
return; return;
} }
if (updateTimeago() > 0) { /* run immediately */ if (updateTimeago() > 0) { /* run immediately */
vote = $(".timeago").length; /* resume */ var intervalId = setInterval(updateTimeago, 60000); /* run every minute */
var intervalId = setInterval(updateTimeago, 60000); /* loop every minutes */
} }
}); });

View File

@@ -42,19 +42,16 @@ const include = [
/* The posts of first Home page and recent update list */ /* The posts of first Home page and recent update list */
{% assign post_list = "" | split: "" %} {% assign post_list = "" | split: "" %}
{% assign sum = 0 %}
{% for post in site.posts %} {% for post in site.posts limit: site.paginate %}
{% assign post_list = post_list | push: post.url %} {% capture post_url %}{{ post.url | relative_url }}{% endcapture %}
{% assign sum = sum | plus: 1 %} {% assign post_list = post_list | push: post_url %}
{% if sum >= site.paginate %}
{% break %}
{% endif %}
{% endfor %} {% endfor %}
{% include update-list.html %} {% include update-list.html %}
{% for item in update_list %} {% for item in update_list %}
{% assign url = item | split: "::" | last | prepend: "/posts/" | append: "/" %} {% assign url = item | split: "::" | last | url_encode | prepend: "/posts/" | append: "/" | relative_url %}
{% assign post_list = post_list | push: url %} {% assign post_list = post_list | push: url %}
{% endfor %} {% endfor %}
@@ -106,6 +103,9 @@ const include = [
]; ];
const exclude = [ const exclude = [
'/assets/js/data/pv-cache.js', {%- if site.google_analytics.pv.proxy_url and site.google_analytics.pv.enabled -%}
'{{ site.google_analytics.pv.proxy_url }}',
{%- endif -%}
'/assets/js/data/pageviews.json',
'/img.shields.io/' '/img.shields.io/'
]; ];

View File

@@ -1,11 +0,0 @@
---
layout: compress
---
{%- capture pv_data -%}
{%- if site.google_analytics.pv.cache and site.google_analytics.pv.enabled -%}
{% include_relative _pageviews.json %}
{%- endif -%}
{%- endcapture -%}
const pageviews = '{{ pv_data }}';

View File

@@ -10,9 +10,8 @@ layout: compress
"categories": "{{ post.categories | join: ', '}}", "categories": "{{ post.categories | join: ', '}}",
"tags": "{{ post.tags | join: ', ' }}", "tags": "{{ post.tags | join: ', ' }}",
"date": "{{ post.date }}", "date": "{{ post.date }}",
{% assign _content = post.content %} {% include no-linenos.html content=post.content %}
{% include no-linenos.html %} "snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
"snippet": "{{ _content | strip_html | strip_newlines | remove_chars | escape | truncate: 300 | replace: '\', '\\\\' }}"
}{% unless forloop.last %},{% endunless %} }{% unless forloop.last %},{% endunless %}
{% endfor %} {% endfor %}
] ]

View File

@@ -114,10 +114,11 @@ jekyll-theme-chirpy/
``` ```
你需要将以下文件或目录删除: 如备注所述,部分文件或目录需要被删除:
- .travis.yml ```terminal
- .github $ rm -rf .travis.yml .github _posts/*
```
### 配置文件 ### 配置文件

View File

@@ -19,7 +19,7 @@ check_status() {
local _change=$(git status . -s) local _change=$(git status . -s)
if [[ ! -z ${_change} ]]; then if [[ ! -z ${_change} ]]; then
echo "Warning: Commit the changes of the changes first:" echo "Warning: Commit the following changes first:"
echo "$_change" echo "$_change"
exit 1 exit 1
fi fi