readme & about-filter improvements: auto selection

Jason A. Donenfeld Jason at zx2c4.com
Sat May 25 17:21:05 CEST 2013


Hi guys,

Cgit has for a long time had the ability to show the /about content
from the git repo itself by specifying branch:file, for example,
"master:README.md" makes the /about content show the README.md file
from the master branch. We use this on the cgit homepage [1] to show
the wiki using readme=wiki:index and about-filter=/path/to/markdown.

In the jd/auto-about branch [2], I have a few commits that make readme
and about-filter much more dynamic.

  * On readme=, if the branch is not specified, the default branch is
used. Thus "master:README.md" may become ":README.md" in many cases.
If defbranch= is specified, it will pick up the defbranch setting. Of
course, the case without the prepended colon is still used for actual
files.

  * On about-filter=, depending on the discussion in [3], we now pass
the filename (the part after the colon) to the filter program, so that
the program may use that information to infer how the file should be
modified.

  * On readme=, multiple items may be specified, separated by a space,
and if multiple items exist, cgit will display the first one that it's
able to find.

Combined, they allow for the following setup. In cgitrc, I have these specified:

    about-filter=/var/www/uwsgi/cgit/filters/about-selector.sh
    readme=:README.md :readme.md :README.mkd :readme.mkd :README.rst
:readme.rst :README.txt :readme.txt :README :readme :INSTALL.txt
:install.txt :INSTALL :install

about-selector.sh reads:

    #!/bin/sh
    cd "$(dirname $(readlink -f "$0"))"
    case "$(tr '[:upper:]' '[:lower:]' <<<"$1")" in
            *.md|*.mkd) exec ./markdown; ;;
            *.rst) exec ./rst2html; ;;
            *.[1-9]) exec ./man2html; ;;
            *.txt|*) exec ./txt2html; ;;
    esac

Now, on git.zx2c4.com, if any repo contains, say, a README.md file in
the default branch, it will automatically receive an about page, and
likewise for the other possibilities, each one correctly filtered. For
the cgit homepage [1], I of course still provide a repo-specific
cgitrc pointing to wiki:index.

As well, at some point, I'd like to revamp the /filters directory we
ship with releases. I've got a number of filters in my own personal
branch [4] for git.zx2c4.com, and I may work to bring some of these,
especially the syntax highlighting [5], into the main repo.

Enjoy! And please do test this branch out.

Jason


[1] http://git.zx2c4.com/cgit/about/
[2] http://git.zx2c4.com/cgit/log/?h=jd/auto-about
[3] http://lists.zx2c4.com/pipermail/cgit/2013-May/001387.html
[4] http://git.zx2c4.com/cgit/tree/filters?h=jd/zx2c4-deployment
[5] http://git.zx2c4.com/cgit/plain/filters/syntaxhighlight?h=jd/zx2c4-deployment


More information about the CGit mailing list