Add hook to generate the lastmod of posts
This commit is contained in:
parent
1889b6b4e0
commit
10bc44367a
6 changed files with 43 additions and 57 deletions
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
<div class="access">
|
<div class="access">
|
||||||
|
|
||||||
{% if site.data.updates %}
|
|
||||||
|
|
||||||
{% include update-list.html %}
|
{% include update-list.html %}
|
||||||
|
|
||||||
{% if update_list.size > 0 %}
|
{% if update_list.size > 0 %}
|
||||||
|
@ -21,23 +19,17 @@
|
||||||
<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 | url_encode | prepend: "/posts/" | append: "/" %}
|
{% assign index = item | split: "::" | last | plus: 0 %}
|
||||||
{% assign post = site.posts | where: "url", post_url | first %}
|
{% assign post = site.posts[index] %}
|
||||||
|
|
||||||
{% 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>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div><!-- #access-lastmod -->
|
</div> <!-- #access-lastmod -->
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endif %} <!-- site.data.updates -->
|
|
||||||
|
|
||||||
{% include trending-tags.html %}
|
{% include trending-tags.html %}
|
||||||
|
|
||||||
{% if trending_tags.size > 0 %}
|
{% if trending_tags.size > 0 %}
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
|
|
||||||
{% assign all_list = "" | split: "" %}
|
{% assign all_list = "" | split: "" %}
|
||||||
|
|
||||||
{% for entry in site.data.updates %}
|
{% for post in site.posts %}
|
||||||
|
{% if post.lastmod %}
|
||||||
{% capture elem %}
|
{% capture elem %}
|
||||||
{{- entry.lastmod -}}::{{- entry.filename -}}
|
{{- post.lastmod | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}}
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
{% assign all_list = all_list | push: elem %}
|
{% assign all_list = all_list | push: elem %}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% assign all_list = all_list | sort | reverse %}
|
{% assign all_list = all_list | sort | reverse %}
|
||||||
|
|
|
@ -31,22 +31,10 @@ layout: default
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- lastmod -->
|
<!-- lastmod -->
|
||||||
{%- capture filename -%}
|
{% if page.lastmod %}
|
||||||
{{ page.url | split: "/" | last }}
|
|
||||||
{%- endcapture -%}
|
|
||||||
|
|
||||||
{% 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 lastmod %}
|
|
||||||
<div>
|
<div>
|
||||||
Updated
|
Updated
|
||||||
{% include timeago.html date=lastmod class="lastmod" tooltip=true %}
|
{% include timeago.html date=page.lastmod class="lastmod" tooltip=true %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -61,7 +49,6 @@ layout: default
|
||||||
</div> <!-- .post-meta -->
|
</div> <!-- .post-meta -->
|
||||||
|
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
|
|
||||||
{%- capture img_placehodler -%}
|
{%- capture img_placehodler -%}
|
||||||
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||||
{% endcapture%}
|
{% endcapture%}
|
||||||
|
|
11
_plugins/posts-lastmod-hook.rb
Normal file
11
_plugins/posts-lastmod-hook.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Check for changed posts
|
||||||
|
Jekyll::Hooks.register :posts, :post_init do |post|
|
||||||
|
|
||||||
|
commit_num = `git rev-list --count HEAD "#{ post.path }"`
|
||||||
|
|
||||||
|
if commit_num.to_i > 1
|
||||||
|
lastmod_date = `git log -1 --pretty="%ad" --date=iso "#{ post.path }"`
|
||||||
|
post.data['lastmod'] = lastmod_date
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
6
feed.xml
6
feed.xml
|
@ -30,10 +30,10 @@ layout: compress
|
||||||
<title>{{ post.title }}</title>
|
<title>{{ post.title }}</title>
|
||||||
<link href="{{ post_absolute_url }}" rel="alternate" type="text/html" title="{{ post.title }}" />
|
<link href="{{ post_absolute_url }}" rel="alternate" type="text/html" title="{{ post.title }}" />
|
||||||
<published>{{ post.date | date_to_xmlschema }}</published>
|
<published>{{ post.date | date_to_xmlschema }}</published>
|
||||||
{% if post.seo.date_modified %}
|
{% if post.lastmod %}
|
||||||
<updated>{{ post.seo.date_modified | date_to_xmlschema }}</updated>
|
<updated>{{ post.lastmod | date_to_xmlschema }}</updated>
|
||||||
{% else %}
|
{% else %}
|
||||||
<updated>{{ site.time | date_to_xmlschema }}</updated>
|
<updated>{{ post.date | date_to_xmlschema }}</updated>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<id>{{ post_absolute_url }}</id>
|
<id>{{ post_absolute_url }}</id>
|
||||||
<content src="{{ post_absolute_url }}" />
|
<content src="{{ post_absolute_url }}" />
|
||||||
|
|
18
sitemap.xml
18
sitemap.xml
|
@ -14,7 +14,11 @@ layout: compress
|
||||||
{% for post in site.posts %}
|
{% for post in site.posts %}
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ site.url | append: site.baseurl | append: post.url }}</loc>
|
<loc>{{ site.url | append: site.baseurl | append: post.url }}</loc>
|
||||||
<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>
|
{% if post.lastmod %}
|
||||||
|
<lastmod>{{ post.lastmod | date_to_xmlschema }}</lastmod>
|
||||||
|
{% else %}
|
||||||
|
<lastmod>{{ post.date | date_to_xmlschema }}</lastmod>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if post.sitemap.changefreq %}
|
{% if post.sitemap.changefreq %}
|
||||||
<changefreq>{{ post.sitemap.changefreq }}</changefreq>
|
<changefreq>{{ post.sitemap.changefreq }}</changefreq>
|
||||||
|
@ -59,19 +63,9 @@ layout: compress
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% capture lastmod %}
|
|
||||||
{% if page.lastmod %}
|
|
||||||
{{ page.lastmod }}
|
|
||||||
{% elsif page.date %}
|
|
||||||
{{ page.date }}
|
|
||||||
{% else %}
|
|
||||||
{{ site.time }}
|
|
||||||
{% endif %}
|
|
||||||
{% endcapture %}
|
|
||||||
|
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ site.url | append: site.baseurl | append: page.url | remove: "index.html" }}</loc>
|
<loc>{{ site.url | append: site.baseurl | append: page.url | remove: "index.html" }}</loc>
|
||||||
<lastmod>{{ lastmod | date_to_xmlschema }}</lastmod>
|
<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>
|
||||||
|
|
||||||
{% if page.sitemap.changefreq %}
|
{% if page.sitemap.changefreq %}
|
||||||
<changefreq>{{ page.sitemap.changefreq }}</changefreq>
|
<changefreq>{{ page.sitemap.changefreq }}</changefreq>
|
||||||
|
|
Loading…
Reference in a new issue