aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_data/git.yml5
-rw-r--r--_layouts/default.html2
-rw-r--r--_plugins/filters.rb4
-rw-r--r--_plugins/meta.rb40
-rwxr-xr-x_scripts/postinfo25
5 files changed, 45 insertions, 31 deletions
diff --git a/_data/git.yml b/_data/git.yml
new file mode 100644
index 0000000..4ec920d
--- /dev/null
+++ b/_data/git.yml
@@ -0,0 +1,5 @@
+# These commits are ignored when calculating first/last published dates and
+# edit counts, and is used to ignore commits where git sees a file as touched
+# even though its content hasn't changed.
+ignore_commits:
+ - ce37824c5260dd370c61cf174ea80ca7deeb1058 # next.js -> jekyll
diff --git a/_layouts/default.html b/_layouts/default.html
index a0f06cb..ef50700 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -41,7 +41,7 @@
<span class="title">post info</span>
<ul>
<li>last published on {{ page.meta.date | datefmt }}</li>
- <li>written by {{ page.authors | map: 'nick' | sentence_join }}</li>
+ <li>written by {{ page.authors | map: 'nick' | sentence_join: 'nobody?' }}</li>
<li>first published on {{ page.meta.date_initial | datefmt }}</li>
<li>edited {{ page.meta.edits | plural: 'time' }}</li>
</ul>
diff --git a/_plugins/filters.rb b/_plugins/filters.rb
index 9e9b026..95a5c78 100644
--- a/_plugins/filters.rb
+++ b/_plugins/filters.rb
@@ -3,8 +3,8 @@ module Filters
return input.strftime("%F")
end
- def sentence_join(items)
- return "" if items == nil or items.length == 0
+ def sentence_join(items, fallback = "")
+ return fallback if items == nil or items.length == 0
return "#{items[0]}" if items.length == 1
return "#{items[0..-2].join(", ")} and #{items[-1]}"
end
diff --git a/_plugins/meta.rb b/_plugins/meta.rb
index 85f3a75..6024cca 100644
--- a/_plugins/meta.rb
+++ b/_plugins/meta.rb
@@ -5,30 +5,42 @@ module Meta
site.data = parse_unix_dates(site.data)
for page in site.collections['items'] do
- # directly add generated page metadata to `page.meta` in liquid
- page.data['meta'] = site.data['post'][page.slug]
+ # convert generated page metadata and add directly to `page.meta` in liquid
+ page.data['meta'] = transform_data(site, page.slug)
# set page.authors to author metadata from git+yaml
- page.data['authors'] = site.data['authors'].filter { |author|
+ page.data['authors'] = site.data['authors'].filter do |author|
author['git'].intersect?(page.data['meta']['authors'])
- }
+ end
# set page.date to generated date_initial
- page.data['date'] = page.data['meta']['date_initial']
+ page.data['date'] = page.data['meta']['date']
end
end
def parse_unix_dates(data)
- for key, value in data do
- if value.is_a? Hash
- data[key] = parse_unix_dates(value)
- next
- end
-
- next unless value.is_a? String
- next unless value =~ /^@\d+$/
- data[key] = Time.at(Integer(value[1..]))
+ # recurse deeper
+ return data.transform_values { |val| parse_unix_dates(val) } if data.is_a? Hash
+ return data.map { |val| parse_unix_dates(val) } if data.is_a? Array
+
+ # convert strings matching regex
+ return Time.at(Integer(data[1..])) if data.is_a? String and data =~ /^@\d+$/
+
+ # base case
+ return data
+ end
+
+ def transform_data(site, slug)
+ data = site.data['post'][slug]
+ data['git_log'] = data['git_log'].sort { |c| c['date'].to_i }
+
+ git_log = data['git_log'].filter do |commit|
+ !site.data['git']['ignore_commits'].include?(commit['hash'])
end
+
+ data['authors'] = git_log.map{ |c| c['author'] }.uniq
+ data['date_initial'] = git_log.first['date']
+ data['date'] = git_log.last['date']
return data
end
end
diff --git a/_scripts/postinfo b/_scripts/postinfo
index efc70c2..edc808b 100755
--- a/_scripts/postinfo
+++ b/_scripts/postinfo
@@ -4,20 +4,17 @@ export LANG=C
file="$1"
tab="$(printf '\t')"
-history="$(git log \
+git log \
--follow \
--ignore-all-space --diff-filter=AM \
- --date=unix --pretty=format:"%cd$tab%an" \
- -- "$file")"
-
-dates="$(echo "$history" | cut -d"$tab" -f1)"
-authors="$(echo "$history" | cut -d"$tab" -f2 | sort -u)"
-
-cat << EOF
-date: '@$(echo "$dates" | head -n1)'
-date_initial: '@$(echo "$dates" | tail -n1)'
-edits: $(echo "$dates" | wc -l)
-authors:
-$(echo "$authors" | sed 's/^/- /')
-EOF
+ --date=unix --pretty=format:"%H$tab%cd$tab%an" \
+ -- "$file" |\
+awk -F"$tab" '
+BEGIN { printf("git_log:\n") }
+{
+ printf(" - hash: \"%s\"\n", $1)
+ printf(" date: \"@%s\"\n", $2)
+ printf(" author: \"%s\"\n", $3)
+}
+'