X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=examples%2Fcgit-commit-filter.lua;fp=examples%2Fcgit-commit-filter.lua;h=4b90125ff332669dcf2de635c95b3493856b6a8c;hp=0000000000000000000000000000000000000000;hb=2998655db7fce5c7d9714a89f4a7cb54419bc757;hpb=039139b626467790e94ae4b9c9263b03ac44281f
diff --git a/examples/cgit-commit-filter.lua b/examples/cgit-commit-filter.lua
new file mode 100644
index 00000000..4b90125f
--- /dev/null
+++ b/examples/cgit-commit-filter.lua
@@ -0,0 +1,44 @@
+-- Copyright (C) 2015 all contributors
+-- License: GPLv2 or later (https://www.gnu.org/licenses/gpl-2.0.txt)
+-- This commit filter maps a subject line to a search URL of a public-inbox
+-- disclaimer: written by someone who does not know Lua.
+--
+-- This requires cgit linked with Lua
+-- Usage (in your cgitrc(5) config file):
+--
+-- commit-filter=lua:/path/to/this/script.lua
+--
+-- Example: http://bogomips.org/public-inbox.git/
+
+local urls = {}
+urls['public-inbox.git'] = 'http://public-inbox.org/meta/'
+-- additional URLs here...
+
+function filter_open(...)
+ lineno = 0
+ buffer = ""
+ subject = ""
+end
+
+function filter_close()
+ if lineno == 1 and string.find(buffer, "\n") == nil then
+ u = urls[os.getenv('CGIT_REPO_URL')]
+ if u == nil then
+ html(buffer)
+ else
+ html('')
+ html_txt(buffer)
+ html('')
+ end
+ else
+ html(buffer)
+ end
+ return 0
+end
+
+function filter_write(str)
+ lineno = lineno + 1
+ buffer = buffer .. str
+end