This allows custom links to be added into the section headers by
configuring a filter to be applied in the repository list.

Signed-off-by: Tim Nordell <tim.nord...@logicpd.com>

 create mode 100644 filters/section-example.lua

diff --git a/cgit.c b/cgit.c
index 87ba811..7dac332 100644
--- a/cgit.c
+++ b/cgit.c
@@ -234,6 +234,8 @@ static void config_cb(const char *name, const char *value)
                ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
        else if (!strcmp(name, "owner-filter"))
                ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
+       else if (!strcmp(name, "section-filter"))
+               ctx.cfg.section_filter = cgit_new_filter(value, SECTION);
        else if (!strcmp(name, "auth-filter"))
                ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
        else if (!strcmp(name, "embedded"))
diff --git a/cgit.h b/cgit.h
index b2b2ae9..f0ac36b 100644
--- a/cgit.h
+++ b/cgit.h
@@ -55,7 +55,7 @@ typedef enum {
 } diff_type;
 
 typedef enum {
-       ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
+       ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER, SECTION
 } filter_type;
 
 struct cgit_filter {
@@ -272,6 +272,7 @@ struct cgit_config {
        struct cgit_filter *source_filter;
        struct cgit_filter *email_filter;
        struct cgit_filter *owner_filter;
+       struct cgit_filter *section_filter;
        struct cgit_filter *auth_filter;
 };
 
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 3bca0ab..113b7a0 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -404,6 +404,13 @@ section::
        after this option will inherit the current section name. Default value:
        none.
 
+section-filter::
+       Specifies a command which will be invoked to format section headings.
+       The command will get the section on its STDIN, and the STDOUT from the
+       command will be included verbatim as the section heading.
+       Default value: none.
+       See also: "FILTER API".
+
 section-sort::
        Flag which, when set to "1", will sort the sections on the repository
        listing by name. Set this flag to "0" if the order in the cgitrc file 
should
@@ -695,6 +702,11 @@ owner filter::
        standard input and the filter is expected to write to standard
        output.  The output is included in the Owner column.
 
+section filter::
+       This filter is given no arguments.  The section text is avilable on
+       standard input and the filter is expected to write to standard
+       output.  The output is included in the section heading.
+
 source filter::
        This filter is given a single parameter: the filename of the source
        file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 949c931..952336f 100644
--- a/filter.c
+++ b/filter.c
@@ -436,6 +436,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, 
filter_type filtertype)
                        argument_count = 1;
                        break;
 
+               case SECTION:
                case COMMIT:
                default:
                        argument_count = 0;
diff --git a/filters/section-example.lua b/filters/section-example.lua
new file mode 100644
index 0000000..76076b2
--- /dev/null
+++ b/filters/section-example.lua
@@ -0,0 +1,33 @@
+-- This script is an example of an section-filter.  It replaces the
+-- section title with several links for each subdirectory represented
+-- within the section title.  (It's intended to be used where the section
+-- title is also the same as the path to the repository, similar to
+-- the output from the "section-from-path" option.)  This script may
+-- be used with the section-filter setting in cgitrc with the `lua:`
+-- prefix.
+
+function gen_link(name, path)
+end
+
+function filter_open()
+       buffer = ""
+end
+
+function filter_close()
+       path = "/"
+       cnt = 0
+       for i in string.gmatch(buffer, "[^/]+") do
+               if cnt > 0 then
+                       html("/")
+               end
+               path = path .. i .. "/"
+               html(string.format("<a href=\"%s%s\" class=reposection>%s</a>",
+                       os.getenv("SCRIPT_NAME"), path, i))
+               cnt = cnt + 1
+       end
+       return 0
+end
+
+function filter_write(str)
+       buffer = buffer .. str
+end
diff --git a/ui-repolist.c b/ui-repolist.c
index 30915df..7af77e0 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -322,7 +322,11 @@ void cgit_print_repolist(void)
                     strcmp(section, last_section)))) {
                        htmlf("<tr class='nohover'><td colspan='%d' 
class='reposection'>",
                              columns);
+                       if (ctx.cfg.section_filter)
+                               cgit_open_filter(ctx.cfg.section_filter);
                        html_txt(section);
+                       if (ctx.cfg.section_filter)
+                               cgit_close_filter(ctx.cfg.section_filter);
                        html("</td></tr>");
                        last_section = section;
                }
-- 
2.4.9

_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to