]> Sergey Matveev's repositories - public-inbox.git/blob - examples/cgit-commit-filter.lua
examples/varnish-4.vcl: comments and tweaks
[public-inbox.git] / examples / cgit-commit-filter.lua
1 -- Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 -- License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
3 -- This commit filter maps a subject line to a search URL of a public-inbox
4 -- disclaimer: written by someone who does not know Lua.
5 --
6 -- This requires cgit linked with Lua
7 -- Usage (in your cgitrc(5) config file):
8 --
9 --   commit-filter=lua:/path/to/this/script.lua
10 --
11 -- Example: http://bogomips.org/public-inbox.git/
12
13 local urls = {}
14 urls['public-inbox.git'] = 'http://public-inbox.org/meta/'
15 -- additional URLs here...
16
17 function filter_open(...)
18         lineno = 0
19         buffer = ""
20         subject = ""
21 end
22
23 function filter_close()
24         if lineno == 1 and string.find(buffer, "\n") == nil then
25                 u = urls[os.getenv('CGIT_REPO_URL')]
26                 if u == nil then
27                         html(buffer)
28                 else
29                         html('<a href="' .. u .. '?x=t&q=')
30                         html_url_arg('"' .. buffer .. '"')
31                         html('"><tt>')
32                         html_txt(buffer)
33                         html('</tt></a>')
34                 end
35         else
36                 html(buffer)
37         end
38         return 0
39 end
40
41 function filter_write(str)
42         lineno = lineno + 1
43         buffer = buffer .. str
44 end