-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblosxom.vim.cgi
More file actions
executable file
·93 lines (79 loc) · 2.65 KB
/
blosxom.vim.cgi
File metadata and controls
executable file
·93 lines (79 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
""exec /usr/local/vim7/bin/vim -u NONE -i NONE --noplugin -e --cmd ":so $0"
" vim:ft=vim:
" -e で ex モードにすることで、エスケープシーケンスを排除してる。
" 完全じゃないっぽい?
function Out(out)
silent exe "normal a" . a:out
endfunction
try
set hidden
set termencoding=utf-8
set encoding=utf-8
set fileencodings=utf-8
set fileencoding=utf-8
function Inspect(obj)
call Out(string(a:obj) . "\n")
endfunction
function Template(filename, dict)
let retv = join(readfile(a:filename), "\n")
for key in keys(a:dict)
silent let retv = substitute(retv, "#{".key."}", substitute(a:dict[key], '\', '\\', 'g'), "g")
endfor
call Out(retv)
endfunction
let flavour = fnamemodify($PATH_INFO, ":e")
if flavour == ""
let flavour = "html"
endif
silent let $PATH_INFO = substitute($PATH_INFO, "\\v(index){0,1}\\..*", "", "")
call Template("head.".flavour, {"title": "This is Vim.", "home": $SCRIPT_NAME})
function CompareByTime(a, b)
let a = a:a["time"]
let b = a:b["time"]
return a == b ? 0 : a > b ? -1 : 1
endfunction
function FilteringByPathInfo(entries)
let pathinfo = split($PATH_INFO, "/")
if len(pathinfo) > 0
if str2nr(pathinfo[0]) == 0
let pathinfo[len(pathinfo)-1] = fnamemodify($PATH_INFO, ":t:r")
call filter(a:entries, '!match(v:val["name"], "^'.$PATH_INFO.'")')
else
"call Inspect('strftime("%Y", v:val["time"]) == '.string(pathinfo[0]))
call filter(a:entries, 'strftime("%Y", v:val["time"]) == '.string(pathinfo[0]))
if len(pathinfo) > 1
call filter(a:entries, 'strftime("%m", v:val["time"]) == '.string(pathinfo[1]))
if len(pathinfo) > 2
call filter(a:entries, 'strftime("%d", v:val["time"]) == '.string(pathinfo[2]))
end
endif
endif
endif
endfunction
let files = split(glob("data/**/*.txt"), "\n")
let entries = sort(map(files, '{"path": v:val, "time": getftime(v:val)}'), "CompareByTime")
for ent in entries
let file = readfile(ent["path"])
let ent["title"] = file[0]
let ent["body"] = join(file[1:], "\n")
let ent["name"] = substitute(ent["path"], '^data\|.[^.]*$', "", "g")
let ent["date"] = strftime("%Y-%m-%d %H:%M:%S", ent["time"])
let ent["home"] = $SCRIPT_NAME
let ent["path"] = join(split(ent["home"], "/")[0:-1], "/")
endfor
call FilteringByPathInfo(entries)
for ent in entries
call Template("story.".flavour, ent)
endfor
call Template("foot.".flavour, {"version": version})
catch /.*/
call Out("Content-Type: text/plain; charset=UTF-8\n\n")
call Out(v:exception . "\n")
call Out(v:throwpoint)
endtry
" Output
silent exe "w " . tempname()
silent exe "!cat %"
"silent echo join(getline(1, line("$")), "\n")
q!