summaryrefslogtreecommitdiffstats
path: root/_scripts
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2016-03-24 11:29:24 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2016-03-24 11:29:24 +0100
commite361b2dfcba1e38c252ea74e6d3a616d1f54a7a8 (patch)
tree1cf17d3470ad441abf0601db9e7bd968f1a6d3c5 /_scripts
parenta5e6f4df2125b10fa40f35d365e1d70d09b7de75 (diff)
downloadalpine-mksite-e361b2dfcba1e38c252ea74e6d3a616d1f54a7a8.tar.bz2
alpine-mksite-e361b2dfcba1e38c252ea74e6d3a616d1f54a7a8.tar.xz
scripts: grab the article author from git commit
Diffstat (limited to '_scripts')
-rw-r--r--_scripts/generate_index.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/_scripts/generate_index.lua b/_scripts/generate_index.lua
index 8e2bc85..ec56f19 100644
--- a/_scripts/generate_index.lua
+++ b/_scripts/generate_index.lua
@@ -4,6 +4,24 @@ markdown = require('discount')
lyaml = require('lyaml')
lfs = require('lfs')
+function shell_escape(args)
+ local ret = {}
+ for _,a in pairs(args) do
+ s = tostring(a)
+ if s:match("[^A-Za-z0-9_/:=-]") then
+ s = "'"..s:gsub("'", "'\\''").."'"
+ end
+ table.insert(ret,s)
+ end
+ return table.concat(ret, " ")
+end
+
+function run(args)
+ local h = io.popen(shell_escape(args))
+ local outstr = h:read("*a")
+ return h:close(), outstr
+end
+
function read_meta(file)
local f = assert(io.open(file))
local header, body = f:read("*a"):match("^(%-%-%-.-%-%-%-)(.*)$")
@@ -22,6 +40,17 @@ j=1
for i=1, #arg do
local m = read_meta(arg[i])
if m.date then
+ if not m.author then
+ local rc, author = run{'git', 'log', '-n', '1',
+ '--pretty=format:%an',
+ '--', arg[i]}
+ if rc then
+ m.author = author
+ else
+ m.author = "unknown"
+ end
+ end
+
a[j] = m
j = j + 1
end