root/lang/vim/blosxom.vim.cgi/blosxom.vim.cgi @ 633

Revision 633, 2.6 kB (checked in by cho45, 6 years ago)

lang/vim/blosxom.vim.cgi/head.html,
lang/vim/blosxom.vim.cgi/blosxom.vim.cgi:

フレーバー実装

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