From 8d203094d1f39805670574ddc97ffb3d97497bf8 Mon Sep 17 00:00:00 2001 From: memdmp Date: Wed, 15 Jan 2025 12:46:50 +0100 Subject: feat: nicen up the repo for estrogen.zone --- image/Caddyfile | 4 + image/cgitrc | 138 ++++++++++++++++------------------- image/filters/email-libravatar.lua | 56 ++++++++++++++ image/filters/syntax-highlighting.sh | 126 ++++++++++++++++++++++++++++++++ image/syntax-highlighting.sh | 126 -------------------------------- 5 files changed, 248 insertions(+), 202 deletions(-) create mode 100644 image/filters/email-libravatar.lua create mode 100644 image/filters/syntax-highlighting.sh delete mode 100644 image/syntax-highlighting.sh (limited to 'image') diff --git a/image/Caddyfile b/image/Caddyfile index ab89e8e..56f89a0 100644 --- a/image/Caddyfile +++ b/image/Caddyfile @@ -1,3 +1,7 @@ +{ + admin off +} + http:// { route { root * /var/lib/git/static diff --git a/image/cgitrc b/image/cgitrc index 3dfcc8a..61a5944 100644 --- a/image/cgitrc +++ b/image/cgitrc @@ -1,93 +1,71 @@ +# +# cgit config +# see https://man.archlinux.org/man/cgitrc.5 +# + # Enable caching of up to 1000 output entries cache-size=1000 -# Specify some default clone prefixes -clone-prefix=https://git.mydomain.com/git ssh://git@git.mydomain.com +# The clone prefixes, used to show the user where to clone from +clone-prefix=https://git.estrogen.zone ssh://git@git.estrogen.zone -# Specify the css url -css=/cgit.css - -# Show extra links for each repository on the index page -enable-index-links=1 +# Use /cgit.css or https://git.estrogen.zone/cgit-assets.git/plain/cgit.css if you don't have this repo available +css=/cgit-assets.git/plain/cgit.css -# Show number of affected files per commit on the log pages -enable-log-filecount=1 - -# Show number of added/removed lines per commit on the log pages -enable-log-linecount=1 - -# Enable ASCII art commit history graph on the log pages -enable-commit-graph=1 +# Specify your own icon's URL here +logo=/cgit.png # Add a cgit favicon #favicon=/favicon.ico -# Use a custom logo -logo=/cgit.png +# Allow http transport git clone +enable-http-clone=1 + +# Use git configuration files +enable-git-config=1 -# Enable statistics per week, month and quarter +# The maximum duration of the stats tab max-stats=month -# Set the title and heading of the repository index page -root-title=Welcome ! +# Enable the commit graph +enable-commit-graph=1 -# Set a subheading for the repository index page -root-desc=Some information... +# Log should specify counts +enable-log-linecount=1 +enable-log-filecount=1 -# Include some more info about foobar.com on the index page -#root-readme=/var/www/htdocs/about.html +# Show extra links for each repository on the index page +enable-index-links=1 -# Allow download of tar.gz, tar.bz2, tar.lz and zip-files -snapshots=tar.gz tar.bz2 tar.lz zip +# Enable blame page and create links to it from tree page +enable-blame=1 -# Show libravatar -email-filter=lua:/usr/lib/cgit/filters/email-libravatar.lua +# The title of the root +root-title=git.estrogen.zone +# The description rendered under it +root-desc=uhhh idk -robots=noindex, nofollow -enable-git-config=1 -#source-filter=/opt/highlight.sh -source-filter=/usr/local/lib/cgit/filters/syntax-highlighting.py +# Include some more info about git.estrogen.zone on the index page +#root-readme=/var/www/htdocs/about.html +# if you do not want that webcrawler (like google) index your site +robots=index, nofollow -## -## Search for these files in the root of the default branch of repositories -## for coming up with the about page: -## -readme=:README.md -readme=:readme.md -readme=:README.mkd -readme=:readme.mkd readme=:README.rst readme=:readme.rst -readme=:README.html -readme=:readme.html -readme=:README.htm -readme=:readme.htm -readme=:README.txt -readme=:readme.txt +readme=:README.md +readme=:readme.md readme=:README readme=:readme -readme=:INSTALL.md -readme=:install.md -readme=:INSTALL.mkd -readme=:install.mkd -readme=:INSTALL.rst -readme=:install.rst -readme=:INSTALL.html -readme=:install.html -readme=:INSTALL.htm -readme=:install.htm -readme=:INSTALL.txt -readme=:install.txt -readme=:INSTALL -readme=:install - -about-filter=/usr/local/lib/cgit/filters/about-formatting.sh +#readme=:README.html -## -### List of common mimetypes -### +# if cgit messes up links, use a virtual-root. For example, cgit.example.org/ has this value: +virtual-root=/ + +# Allow download of tar.gz, tar.bz2, tar.lz and zip-files +snapshots=tar.lz tar.gz tar.bz2 zip +# Specify mime types mimetype.git=image/git mimetype.html=text/html mimetype.jpg=image/jpeg @@ -100,11 +78,26 @@ mimetype.js=text/javascript mimetype.css=text/css mimetype.ascii=text/vnd.ascii-art # text/plain is used to prevent XSS -mimetype.html=text/plain+nothtml +mimetype.html=text/plain +# Show libravatar - assumes you're using an avatar handler that handles this properly +email-filter=lua:/usr/lib/cgit/filters/extra/email-libravatar.lua +# If you prefer upstream's: +# email-filter=lua:/usr/lib/cgit/filters/email-libravatar.lua + +# TODO: Create commit filter +# commit-filter=exec:/usr/lib/cgit/filters/extra/commit.sh + +# Handle the about pages +about-filter=/usr/lib/cgit/filters/about-formatting.sh +# Handle syntax highlighting +source-filter=/usr/lib/cgit/filters/syntax-highlighting-uwu.sh + +project-list=/var/lib/git/projects.list +scan-path=/var/lib/git/repositories ## -## List of repositories. +## List of repositories, if you don't wish to use scanning (I RECOMMEND STRONGLY USING SCANNING!!). ## PS: Any repositories listed when repo.group is unset will not be ## displayed under a group heading ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') @@ -113,17 +106,10 @@ mimetype.html=text/plain+nothtml ## #### -section=my repo - +# section=my repo +# #repo.url=testing #repo.path=/var/lib/git/testing.git #repo.desc=Testing repo created by Gitolite #repo.owner=admin@mynetwork.com # - - - -# Auto scan -scan-path=/var/lib/git/repositories - - diff --git a/image/filters/email-libravatar.lua b/image/filters/email-libravatar.lua new file mode 100644 index 0000000..5e8554e --- /dev/null +++ b/image/filters/email-libravatar.lua @@ -0,0 +1,56 @@ +-- This script may be used with the email-filter or repo.email-filter settings in cgitrc. +-- It adds libravatar icons to author names. It is designed to be used with the lua: +-- prefix in filters. +-- +-- Requirements: +-- luaossl +-- +-- + +local digest = require('openssl.digest') + +function sha256_hex(input) + local b = digest.new('sha256'):final(input) + local x = '' + for i = 1, #b do + x = x .. string.format('%.2x', string.byte(b, i)) + end + return x +end + +function filter_open(email, page) + buffer = '' + sha256 = sha256_hex(email:sub(2, -2):lower()) +end + +function filter_close() + baseurl = not os.getenv('FORCE_HTTP') and 'https://seccdn.libravatar.org/' or 'http://cdn.libravatar.org/' + local url = baseurl .. 'avatar/' .. sha256 .. '?d=retro&s=' + local rng = tostring(math.random(0, 10000000)) + -- very bad email obfuscation + html( + '\'Libravatar\'\'Large ' + .. buffer:gsub('@', ''):gsub('%.', '') + .. '' + .. ( + math.random(0, 1000) < 777 + and '' + or '' + ) + ) + return 0 +end + +function filter_write(str) + buffer = buffer .. str +end diff --git a/image/filters/syntax-highlighting.sh b/image/filters/syntax-highlighting.sh new file mode 100644 index 0000000..88f59bf --- /dev/null +++ b/image/filters/syntax-highlighting.sh @@ -0,0 +1,126 @@ +#!/bin/sh +# This script can be used to implement syntax highlighting in the cgit +# tree-view by referring to this file with the source-filter or repo.source- +# filter options in cgitrc. +# +# This script requires a shell supporting the ${var##pattern} syntax. +# It is supported by at least dash and bash, however busybox environments +# might have to use an external call to sed instead. +# +# Note: the highlight command (http://www.andre-simon.de/) uses css for syntax +# highlighting, so you'll probably want something like the following included +# in your css file: +# +# Style definition file generated by highlight 2.4.8, http://www.andre-simon.de/ +# +# table.blob .num { color:#2928ff; } +# table.blob .esc { color:#ff00ff; } +# table.blob .str { color:#ff0000; } +# table.blob .dstr { color:#818100; } +# table.blob .slc { color:#838183; font-style:italic; } +# table.blob .com { color:#838183; font-style:italic; } +# table.blob .dir { color:#008200; } +# table.blob .sym { color:#000000; } +# table.blob .kwa { color:#000000; font-weight:bold; } +# table.blob .kwb { color:#830000; } +# table.blob .kwc { color:#000000; font-weight:bold; } +# table.blob .kwd { color:#010181; } +# +# +# Style definition file generated by highlight 2.6.14, http://www.andre-simon.de/ +# +# body.hl { background-color:#ffffff; } +# pre.hl { color:#000000; background-color:#ffffff; font-size:10pt; font-family:'Courier New';} +# .hl.num { color:#2928ff; } +# .hl.esc { color:#ff00ff; } +# .hl.str { color:#ff0000; } +# .hl.dstr { color:#818100; } +# .hl.slc { color:#838183; font-style:italic; } +# .hl.com { color:#838183; font-style:italic; } +# .hl.dir { color:#008200; } +# .hl.sym { color:#000000; } +# .hl.line { color:#555555; } +# .hl.mark { background-color:#ffffbb;} +# .hl.kwa { color:#000000; font-weight:bold; } +# .hl.kwb { color:#830000; } +# .hl.kwc { color:#000000; font-weight:bold; } +# .hl.kwd { color:#010181; } +# +# +# Style definition file generated by highlight 3.8, http://www.andre-simon.de/ +# +# body.hl { background-color:#e0eaee; } +# pre.hl { color:#000000; background-color:#e0eaee; font-size:10pt; font-family:'Courier New';} +# .hl.num { color:#b07e00; } +# .hl.esc { color:#ff00ff; } +# .hl.str { color:#bf0303; } +# .hl.pps { color:#818100; } +# .hl.slc { color:#838183; font-style:italic; } +# .hl.com { color:#838183; font-style:italic; } +# .hl.ppc { color:#008200; } +# .hl.opt { color:#000000; } +# .hl.lin { color:#555555; } +# .hl.kwa { color:#000000; font-weight:bold; } +# .hl.kwb { color:#0057ae; } +# .hl.kwc { color:#000000; font-weight:bold; } +# .hl.kwd { color:#010181; } +# +# +# Style definition file generated by highlight 3.13, http://www.andre-simon.de/ +# +# body.hl { background-color:#e0eaee; } +# pre.hl { color:#000000; background-color:#e0eaee; font-size:10pt; font-family:'Courier New',monospace;} +# .hl.num { color:#b07e00; } +# .hl.esc { color:#ff00ff; } +# .hl.str { color:#bf0303; } +# .hl.pps { color:#818100; } +# .hl.slc { color:#838183; font-style:italic; } +# .hl.com { color:#838183; font-style:italic; } +# .hl.ppc { color:#008200; } +# .hl.opt { color:#000000; } +# .hl.ipl { color:#0057ae; } +# .hl.lin { color:#555555; } +# .hl.kwa { color:#000000; font-weight:bold; } +# .hl.kwb { color:#0057ae; } +# .hl.kwc { color:#000000; font-weight:bold; } +# .hl.kwd { color:#010181; } +# +# +# The following environment variables can be used to retrieve the configuration +# of the repository for which this script is called: +# CGIT_REPO_URL ( = repo.url setting ) +# CGIT_REPO_NAME ( = repo.name setting ) +# CGIT_REPO_PATH ( = repo.path setting ) +# CGIT_REPO_OWNER ( = repo.owner setting ) +# CGIT_REPO_DEFBRANCH ( = repo.defbranch setting ) +# CGIT_REPO_SECTION ( = section setting ) +# CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) +# + +# store filename and extension in local vars +BASENAME="$1" +EXTENSION="${BASENAME##*.}" + +[ "${BASENAME}" = "${EXTENSION}" ] && EXTENSION=txt +[ -z "${EXTENSION}" ] && EXTENSION=txt + +# map Makefile and Makefile.* to .mk +[ "${BASENAME%%.*}" = "Makefile" ] && EXTENSION=mk + +# highlight versions 2 and 3 have different commandline options. Specifically, +# the -X option that is used for version 2 is replaced by the -O xhtml option +# for version 3. +# +# Version 2 can be found (for example) on EPEL 5, while version 3 can be +# found (for example) on EPEL 6. +# +# This is for version 2 +#exec highlight --force -f -I -X -S "$EXTENSION" 2>/dev/null + +# This is for version 3 +if [[ "$(cat /.highlight-theme)" != "" ]]; then + exec highlight --force --inline-css "--style=$(cat /.highlight-theme)" -f -I -O xhtml -S "$EXTENSION" 2>/dev/null +else + exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null +fi + diff --git a/image/syntax-highlighting.sh b/image/syntax-highlighting.sh deleted file mode 100644 index 88f59bf..0000000 --- a/image/syntax-highlighting.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/sh -# This script can be used to implement syntax highlighting in the cgit -# tree-view by referring to this file with the source-filter or repo.source- -# filter options in cgitrc. -# -# This script requires a shell supporting the ${var##pattern} syntax. -# It is supported by at least dash and bash, however busybox environments -# might have to use an external call to sed instead. -# -# Note: the highlight command (http://www.andre-simon.de/) uses css for syntax -# highlighting, so you'll probably want something like the following included -# in your css file: -# -# Style definition file generated by highlight 2.4.8, http://www.andre-simon.de/ -# -# table.blob .num { color:#2928ff; } -# table.blob .esc { color:#ff00ff; } -# table.blob .str { color:#ff0000; } -# table.blob .dstr { color:#818100; } -# table.blob .slc { color:#838183; font-style:italic; } -# table.blob .com { color:#838183; font-style:italic; } -# table.blob .dir { color:#008200; } -# table.blob .sym { color:#000000; } -# table.blob .kwa { color:#000000; font-weight:bold; } -# table.blob .kwb { color:#830000; } -# table.blob .kwc { color:#000000; font-weight:bold; } -# table.blob .kwd { color:#010181; } -# -# -# Style definition file generated by highlight 2.6.14, http://www.andre-simon.de/ -# -# body.hl { background-color:#ffffff; } -# pre.hl { color:#000000; background-color:#ffffff; font-size:10pt; font-family:'Courier New';} -# .hl.num { color:#2928ff; } -# .hl.esc { color:#ff00ff; } -# .hl.str { color:#ff0000; } -# .hl.dstr { color:#818100; } -# .hl.slc { color:#838183; font-style:italic; } -# .hl.com { color:#838183; font-style:italic; } -# .hl.dir { color:#008200; } -# .hl.sym { color:#000000; } -# .hl.line { color:#555555; } -# .hl.mark { background-color:#ffffbb;} -# .hl.kwa { color:#000000; font-weight:bold; } -# .hl.kwb { color:#830000; } -# .hl.kwc { color:#000000; font-weight:bold; } -# .hl.kwd { color:#010181; } -# -# -# Style definition file generated by highlight 3.8, http://www.andre-simon.de/ -# -# body.hl { background-color:#e0eaee; } -# pre.hl { color:#000000; background-color:#e0eaee; font-size:10pt; font-family:'Courier New';} -# .hl.num { color:#b07e00; } -# .hl.esc { color:#ff00ff; } -# .hl.str { color:#bf0303; } -# .hl.pps { color:#818100; } -# .hl.slc { color:#838183; font-style:italic; } -# .hl.com { color:#838183; font-style:italic; } -# .hl.ppc { color:#008200; } -# .hl.opt { color:#000000; } -# .hl.lin { color:#555555; } -# .hl.kwa { color:#000000; font-weight:bold; } -# .hl.kwb { color:#0057ae; } -# .hl.kwc { color:#000000; font-weight:bold; } -# .hl.kwd { color:#010181; } -# -# -# Style definition file generated by highlight 3.13, http://www.andre-simon.de/ -# -# body.hl { background-color:#e0eaee; } -# pre.hl { color:#000000; background-color:#e0eaee; font-size:10pt; font-family:'Courier New',monospace;} -# .hl.num { color:#b07e00; } -# .hl.esc { color:#ff00ff; } -# .hl.str { color:#bf0303; } -# .hl.pps { color:#818100; } -# .hl.slc { color:#838183; font-style:italic; } -# .hl.com { color:#838183; font-style:italic; } -# .hl.ppc { color:#008200; } -# .hl.opt { color:#000000; } -# .hl.ipl { color:#0057ae; } -# .hl.lin { color:#555555; } -# .hl.kwa { color:#000000; font-weight:bold; } -# .hl.kwb { color:#0057ae; } -# .hl.kwc { color:#000000; font-weight:bold; } -# .hl.kwd { color:#010181; } -# -# -# The following environment variables can be used to retrieve the configuration -# of the repository for which this script is called: -# CGIT_REPO_URL ( = repo.url setting ) -# CGIT_REPO_NAME ( = repo.name setting ) -# CGIT_REPO_PATH ( = repo.path setting ) -# CGIT_REPO_OWNER ( = repo.owner setting ) -# CGIT_REPO_DEFBRANCH ( = repo.defbranch setting ) -# CGIT_REPO_SECTION ( = section setting ) -# CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) -# - -# store filename and extension in local vars -BASENAME="$1" -EXTENSION="${BASENAME##*.}" - -[ "${BASENAME}" = "${EXTENSION}" ] && EXTENSION=txt -[ -z "${EXTENSION}" ] && EXTENSION=txt - -# map Makefile and Makefile.* to .mk -[ "${BASENAME%%.*}" = "Makefile" ] && EXTENSION=mk - -# highlight versions 2 and 3 have different commandline options. Specifically, -# the -X option that is used for version 2 is replaced by the -O xhtml option -# for version 3. -# -# Version 2 can be found (for example) on EPEL 5, while version 3 can be -# found (for example) on EPEL 6. -# -# This is for version 2 -#exec highlight --force -f -I -X -S "$EXTENSION" 2>/dev/null - -# This is for version 3 -if [[ "$(cat /.highlight-theme)" != "" ]]; then - exec highlight --force --inline-css "--style=$(cat /.highlight-theme)" -f -I -O xhtml -S "$EXTENSION" 2>/dev/null -else - exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null -fi - -- cgit v1.2.3