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,33 +10,25 @@
|
||||||
|
|
||||||
<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 %}
|
|
||||||
|
|
||||||
<div id="access-lastmod" class="post">
|
<div id="access-lastmod" class="post">
|
||||||
<span>{{- site.data.label.panel.lastmod -}}</span>
|
<span>{{- site.data.label.panel.lastmod -}}</span>
|
||||||
<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] %}
|
||||||
|
{% assign url = post.url | relative_url %}
|
||||||
{% if post %}
|
<li><a href="{{ url }}">{{ post.title }}</a></li>
|
||||||
{% assign url = post.url | relative_url %}
|
|
||||||
<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 %}
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
|
|
||||||
{% assign all_list = "" | split: "" %}
|
{% assign all_list = "" | split: "" %}
|
||||||
|
|
||||||
{% for entry in site.data.updates %}
|
{% for post in site.posts %}
|
||||||
{% capture elem %}
|
{% if post.lastmod %}
|
||||||
{{- entry.lastmod -}}::{{- entry.filename -}}
|
{% capture elem %}
|
||||||
{% endcapture %}
|
{{- post.lastmod | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}}
|
||||||
{% assign all_list = all_list | push: elem %}
|
{% endcapture %}
|
||||||
|
{% 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
|
8
feed.xml
8
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 }}" />
|
||||||
|
@ -60,4 +60,4 @@ layout: compress
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</feed>
|
</feed>
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
{{ source | replace: '&', '&' }}
|
{{ source | replace: '&', '&' }}
|
||||||
|
|
22
sitemap.xml
22
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 %}
|
<url>
|
||||||
{% if page.lastmod %}
|
|
||||||
{{ page.lastmod }}
|
|
||||||
{% elsif page.date %}
|
|
||||||
{{ page.date }}
|
|
||||||
{% else %}
|
|
||||||
{{ site.time }}
|
|
||||||
{% endif %}
|
|
||||||
{% endcapture %}
|
|
||||||
|
|
||||||
<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>
|
||||||
|
@ -88,4 +82,4 @@ layout: compress
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|
Loading…
Reference in a new issue