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
-