From 6220d09ffba112dd6bbe4b48c8f3957deac9cb52 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:50:12 +0800 Subject: [PATCH 1/5] Replace the pageviews with categories on home page --- _includes/js-selector.html | 2 +- _layouts/home.html | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 20531b4..219fe96 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -4,7 +4,7 @@ -{% if page.layout == 'home' or page.layout == 'post' %} +{% if page.layout == 'post' %} {% if site.google_analytics.pv.proxy_endpoint or site.google_analytics.pv.cache_path %} diff --git a/_layouts/home.html b/_layouts/home.html index 6cf5e3c..1233e10 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -68,13 +68,17 @@ layout: page {% include read-time.html content=post.content %} - - {% if site.google_analytics.pv.proxy_endpoint or site.google_analytics.pv.cache_path %} - - - - + + {% if post.categories.size > 0 %} + + + {% for category in post.categories %} + {{ category }} + {%- unless forloop.last -%},{%- endunless -%} + {% endfor %} + {% endif %} + {% if post.pin %} From 563e8085e8e84c9fc179be7a3e5ba07f99ce0230 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 4 Dec 2021 06:56:33 +0800 Subject: [PATCH 2/5] Redesign the post meta layout - posted date - updated date - read time - license statement of post bottom - also refactor the `timeago.js` --- _data/locales/en.yml | 3 ++- _data/locales/id-ID.yml | 3 ++- _data/locales/zh-CN.yml | 3 ++- _includes/read-time.html | 6 ++--- _includes/timeago.html | 23 ++++++++--------- _javascript/utils/timeago.js | 38 +++++++++++++++------------ _layouts/home.html | 5 ++-- _layouts/post.html | 50 +++++++++++++++++++++--------------- _sass/addon/commons.scss | 38 ++++++++++++--------------- _sass/addon/module.scss | 8 +++--- _sass/layout/home.scss | 8 ++++-- _sass/layout/post.scss | 36 +++++++++----------------- assets/js/dist/home.min.js | 2 +- assets/js/dist/post.min.js | 2 +- 14 files changed, 113 insertions(+), 112 deletions(-) diff --git a/_data/locales/en.yml b/_data/locales/en.yml index 65c2df0..93e4d15 100644 --- a/_data/locales/en.yml +++ b/_data/locales/en.yml @@ -59,7 +59,8 @@ not_found: # ----- Posts related labels ----- post: - published: 'on' + written_by: By + posted: Posted updated: Updated timeago: day: days ago diff --git a/_data/locales/id-ID.yml b/_data/locales/id-ID.yml index 851d5a9..4693c5e 100644 --- a/_data/locales/id-ID.yml +++ b/_data/locales/id-ID.yml @@ -59,7 +59,8 @@ not_found: # ----- Posts related labels ----- post: - published: "pada" + written_by: Oleh + posted: Diterbitkan updated: Diperbarui timeago: day: hari yang lalu diff --git a/_data/locales/zh-CN.yml b/_data/locales/zh-CN.yml index 0d479a3..83f2376 100644 --- a/_data/locales/zh-CN.yml +++ b/_data/locales/zh-CN.yml @@ -58,7 +58,8 @@ not_found: # ----- Posts related labels ----- post: - published: 发表于 + written_by: 作者 + posted: 发表于 updated: 更新于 timeago: day: 天前 diff --git a/_includes/read-time.html b/_includes/read-time.html index 2822d69..fbbc0b2 100644 --- a/_includes/read-time.html +++ b/_includes/read-time.html @@ -22,9 +22,9 @@ - {{- read_time -}}{{" "}}{{- site.data.locales[lang].post.read_time.unit -}} + {{- read_time -}}{{" "}}{{- site.data.locales[lang].post.read_time.unit -}} {%- if include.prompt -%} - {% assign _prompt_words = read_prompt | number_of_words: 'auto' %} - {% unless _prompt_words > 1 %}{{" "}}{% endunless %}{{ read_prompt }} + {%- assign _prompt_words = read_prompt | number_of_words: 'auto' -%} + {%- unless _prompt_words > 1 -%}{{ " " }}{%- endunless -%}{{ read_prompt }} {%- endif -%} diff --git a/_includes/timeago.html b/_includes/timeago.html index b68e08b..bd0ed8a 100644 --- a/_includes/timeago.html +++ b/_includes/timeago.html @@ -1,27 +1,26 @@ {% assign tooltip_df = site.data.locales[lang].date_format.tooltip %} {% assign post_long_df = site.data.locales[lang].date_format.post.long %} {% assign post_short_df = site.data.locales[lang].date_format.post.short %} -{% if include.preposition %} - {{ include.preposition }} -{% endif %} - + + {%- assign this_year = site.time | date: "%Y" -%} {%- assign post_year = include.date | date: "%Y" -%} + {%- if post_year == this_year -%} {{ include.date | date: post_short_df }} {%- else -%} {{ include.date | date: post_long_df }} {%- endif -%} - {{ include.date | date_to_xmlschema }} - + diff --git a/_javascript/utils/timeago.js b/_javascript/utils/timeago.js index 428a41c..371231a 100644 --- a/_javascript/utils/timeago.js +++ b/_javascript/utils/timeago.js @@ -3,11 +3,8 @@ */ $(function() { - const timeagoElem = $(".timeago"); - - let toRefresh = timeagoElem.length; - + let tasks = timeagoElem.length; let intervalId = void 0; const dPrompt = $("meta[name=day-prompt]").attr("content"); @@ -15,20 +12,19 @@ $(function() { const minPrompt = $("meta[name=minute-prompt]").attr("content"); const justnowPrompt = $("meta[name=justnow-prompt]").attr("content"); - function timeago(isoDate, dateStr) { + function timeago(date, initDate) { let now = new Date(); - let past = new Date(isoDate); + let past = new Date(date); if (past.getFullYear() !== now.getFullYear() || past.getMonth() !== now.getMonth()) { - return dateStr; + return initDate; } let seconds = Math.floor((now - past) / 1000); let day = Math.floor(seconds / 86400); if (day >= 1) { - toRefresh -= 1; return ` ${day} ${dPrompt}`; } @@ -47,22 +43,30 @@ $(function() { function updateTimeago() { $(".timeago").each(function() { - if ($(this).children("i").length > 0) { - let dateStr = $(this).clone().children().remove().end().text(); - let node = $(this).children("i"); - let iosDate = node.text(); /* ISO Date: "YYYY-MM-DDTHH:MM:SSZ" */ - $(this).text(timeago(iosDate, dateStr)); - $(this).append(node); + if ($(this)[0].hasAttribute("date") === false) { + tasks -= 1; + return; } + + let date = $(this).attr("date"); + let initDate = $(this).text(); + let relativeDate = timeago(date, initDate); + + if (relativeDate === initDate) { + $(this).removeAttr("date"); + } else { + $(this).text(relativeDate); + } + }); - if (toRefresh === 0 && typeof intervalId !== "undefined") { + if (tasks === 0 && typeof intervalId !== "undefined") { clearInterval(intervalId); /* stop interval */ } - return toRefresh; + return tasks; } - if (toRefresh === 0) { + if (tasks === 0) { return; } diff --git a/_layouts/home.html b/_layouts/home.html index 1233e10..279feed 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -57,9 +57,9 @@ layout: page
-