From 4ea320b2504ac072d440bb0227fd695deb00341b Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 26 Nov 2020 23:52:59 +0800 Subject: [PATCH] Generate sitemap by plugin --- Gemfile | 1 + _config.yml | 22 +-------- _includes/update-list.html | 4 +- _layouts/post.html | 4 +- _plugins/posts-lastmod-hook.rb | 2 +- sitemap.xml | 85 ---------------------------------- 6 files changed, 8 insertions(+), 110 deletions(-) delete mode 100644 sitemap.xml diff --git a/Gemfile b/Gemfile index bbea1bf..8a8821c 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ group :jekyll_plugins do gem "jekyll-redirect-from" gem "jekyll-seo-tag", "~> 2.6.1" gem "jekyll-archives" + gem "jekyll-sitemap" end group :test do diff --git a/_config.yml b/_config.yml index 1b4f71b..1b103a3 100644 --- a/_config.yml +++ b/_config.yml @@ -7,7 +7,6 @@ # jekyll-seo-tag settings › https://github.com/jekyll/jekyll-seo-tag/blob/master/docs/usage.md #-------------------------- - title: Chirpy # the main title tagline: A text-focused Jekyll theme. # it will display as the sub-title @@ -42,7 +41,6 @@ social: # - https://www.linkedin.com/in/username google_site_verification: google_meta_tag_verification # change to your verification string - #-------------------------- @@ -184,7 +182,7 @@ compress_html: envs: [] exclude: - - vendor # Avoid Jekyll mistakenly read the vendor directory on Travis-CI's VM . + - vendor - Gemfile.lock - Gemfile - tools @@ -192,23 +190,7 @@ exclude: - README.md - LICENSE -sitemap_exclude: # Sitemap will exclude the following items. - fuzzy: - - /assets/ - accurate: - - /norobots/ - - /tabs/ - - /categories/ - - /tags/ - - /posts/ - - 404.html - - feed.xml - - sitemap.xml - - robots.txt - - redirects.json - -# see: -jekyll-archives: +jekyll-archives: enabled: [categories, tags] layouts: category: category diff --git a/_includes/update-list.html b/_includes/update-list.html index b0eb52a..328267a 100644 --- a/_includes/update-list.html +++ b/_includes/update-list.html @@ -11,9 +11,9 @@ {% assign all_list = "" | split: "" %} {% for post in site.posts %} - {% if post.lastmod %} + {% if post.last_modified_at %} {% capture elem %} - {{- post.lastmod | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}} + {{- post.last_modified_at | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}} {% endcapture %} {% assign all_list = all_list | push: elem %} {% endif %} diff --git a/_layouts/post.html b/_layouts/post.html index cee27cc..1a9133b 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -31,10 +31,10 @@ layout: default - {% if page.lastmod %} + {% if page.last_modified_at %}
Updated - {% include timeago.html date=page.lastmod class="lastmod" tooltip=true %} + {% include timeago.html date=page.last_modified_at class="lastmod" tooltip=true %}
{% endif %} diff --git a/_plugins/posts-lastmod-hook.rb b/_plugins/posts-lastmod-hook.rb index 5119b48..e88d831 100644 --- a/_plugins/posts-lastmod-hook.rb +++ b/_plugins/posts-lastmod-hook.rb @@ -5,7 +5,7 @@ Jekyll::Hooks.register :posts, :post_init do |post| if commit_num.to_i > 1 lastmod_date = `git log -1 --pretty="%ad" --date=iso "#{ post.path }"` - post.data['lastmod'] = lastmod_date + post.data['last_modified_at'] = lastmod_date end end diff --git a/sitemap.xml b/sitemap.xml deleted file mode 100644 index 1fb01fa..0000000 --- a/sitemap.xml +++ /dev/null @@ -1,85 +0,0 @@ ---- -layout: compress - -# The Sitemap template -# v2.0 -# https://github.com/cotes2020/jekyll-theme-chirpy -# © 2017-2019 Cotes Chung -# MIT License ---- - - - - -{% for post in site.posts %} - - {{ site.url | append: site.baseurl | append: post.url }} - {% if post.lastmod %} - {{ post.lastmod | date_to_xmlschema }} - {% else %} - {{ post.date | date_to_xmlschema }} - {% endif %} - - {% if post.sitemap.changefreq %} - {{ post.sitemap.changefreq }} - {% else %} - monthly - {% endif %} - - {% if post.sitemap.priority %} - {{ post.sitemap.priority }} - {% else %} - 0.5 - {% endif %} - -{% endfor %} - -{% for page in site.pages %} - - {% assign pass = false %} - - {% for fuzzy in site.sitemap_exclude.fuzzy %} - {% if page.url contains fuzzy %} - {% assign pass = true %} - {% break %} - {% endif %} - {% endfor %} - - {% unless pass %} - {% for accurate in site.sitemap_exclude.accurate %} - {% assign len = accurate | size %} - {% capture beg %}{{ 0 | minus: len }}{% endcapture %} - {% capture tail %}{{ page.url | slice: beg, len }}{% endcapture %} - - {% if tail == accurate %} - {% assign pass = true %} - {% break %} - {% endif %} - - {% endfor %} - {% endunless %} - - {% if pass %} - {% continue %} - {% endif %} - - - {{ site.url | append: site.baseurl | append: page.url | remove: "index.html" }} - {{ site.time | date_to_xmlschema }} - - {% if page.sitemap.changefreq %} - {{ page.sitemap.changefreq }} - {% else %} - monthly - {% endif %} - - {% if page.sitemap.priority %} - {{ page.sitemap.priority }} - {% else %} - 0.3 - {% endif %} - - -{% endfor %} - -