From 1cb80b2d9f3245bfc9e3f02f84b6af681054131a Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 15 Dec 2024 19:42:53 +0800 Subject: add cgit --- git/about-filter.sh | 3 ++ git/cgitrc | 19 +++++++++ git/logo.svg | 8 ++++ git/source-filter.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++++ nginx/nginx.conf | 2 +- nginx/sites-available/vps | 52 +++++++++++++++++------ www/scripts/build.sh | 6 +-- www/templates/head.html | 1 + 8 files changed, 178 insertions(+), 17 deletions(-) create mode 100755 git/about-filter.sh create mode 100644 git/cgitrc create mode 100644 git/logo.svg create mode 100755 git/source-filter.sh diff --git a/git/about-filter.sh b/git/about-filter.sh new file mode 100755 index 0000000..a2e2f7c --- /dev/null +++ b/git/about-filter.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +markdown -f fencedcode,autolink,alphalist,autolink,footnote,definitionlist diff --git a/git/cgitrc b/git/cgitrc new file mode 100644 index 0000000..e665ada --- /dev/null +++ b/git/cgitrc @@ -0,0 +1,19 @@ +# http assets +css=/cgit.css +logo=/logo.svg + +# repos +enable-git-config=1 +scan-path=/srv/git/ + +# if you do not want that webcrawler (like google) index your site +robots=noindex, nofollow + +# if cgit messes up links, use a virtual-root. For example, cgit.example.org/ has this value: +virtual-root=/ + +# about page +about-filter=/home/pham/site/git/about-filter.sh +readme=:README.md +readme=:README +readme=:README.txt diff --git a/git/logo.svg b/git/logo.svg new file mode 100644 index 0000000..cde7db3 --- /dev/null +++ b/git/logo.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/git/source-filter.sh b/git/source-filter.sh new file mode 100755 index 0000000..4d3f8da --- /dev/null +++ b/git/source-filter.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +# 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 + +# This is for version 3 +exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null | tee /tmp/highlight diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 605f056..f94c508 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -33,7 +33,7 @@ http { # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; log_format main '$status $request_method\t$http_host$uri\tfrom $http_referer\n' - ' $time_iso8601 $remote_addr\r\t\t\t\t\t $http_user_agent'; + ' $time_iso8601 $remote_addr\r\t\t\t\t\t $http_user_agent'; access_log /var/log/nginx/access.log main; sendfile on; diff --git a/nginx/sites-available/vps b/nginx/sites-available/vps index 75a789b..3985072 100644 --- a/nginx/sites-available/vps +++ b/nginx/sites-available/vps @@ -16,7 +16,7 @@ map $uri $basename { } server { - server_name topo.tw www.topo.tw "~[\d\.]+"; + server_name topo.tw www.topo.tw "~[\d\.]+" localhost; listen 80; listen 443 ssl; @@ -54,7 +54,13 @@ server { error_log /var/log/nginx/error.log debug; #rewrite_log on; - location ~ \.html$ { + # RSS Feed for various names + # ref: https://blog.jim-nielsen.com/2021/feed-urls/ + location ^~ (index.xml|atom.xml|feed.xml|feed.atom)$ { + alias /srv/http/feed.rss; + } + + location ^~ \.html$ { try_files $uri =404; } @@ -68,11 +74,11 @@ server { fancyindex_ignore Makefile fastcgi.*; } - location ~ /cgi/(.*) { + location ^~ /cgi/ { gzip off; include /etc/nginx/fastcgi_params; - fastcgi_pass unix:/srv/cgi/fastcgi.sock; - fastcgi_param SCRIPT_FILENAME /srv/cgi/$1; + fastcgi_pass unix:/run/fcgiwrap.sock; + fastcgi_param SCRIPT_FILENAME /srv/cgi/$basename; error_log /tmp/cgi info; } @@ -317,15 +323,35 @@ server { ssl_certificate /etc/nginx/ssl/git.topo.tw/fullchain.cer; ssl_certificate_key /etc/nginx/ssl/git.topo.tw/git.topo.tw.key; - root /srv/git/www; + root /usr/share/webapps/cgit; + try_files $uri @cgit; + + location = /favicon.ico { + alias /srv/http/favicon.ico; + } + + location = /logo.svg { + alias /home/pham/site/git/logo.svg; + } + + # Configure HTTP transport + location ~ /.+/(info/refs|git-upload-pack) { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; + fastcgi_param PATH_INFO $uri; + fastcgi_param GIT_HTTP_EXPORT_ALL 1; + fastcgi_param GIT_PROJECT_ROOT /srv/git; + fastcgi_param HOME /srv/git; + fastcgi_pass unix:/run/fcgiwrap.sock; + } - location ~ (/.*) { - #include fastcgi_params; - #fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; - ## export all repositories under GIT_PROJECT_ROOT - #fastcgi_param GIT_HTTP_EXPORT_ALL ""; - #fastcgi_param GIT_PROJECT_ROOT /srv/git; - #fastcgi_param PATH_INFO $1; + location @cgit { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /usr/local/lib/cgit/cgit.cgi; + fastcgi_param PATH_INFO $uri; + fastcgi_param QUERY_STRING $args; + fastcgi_param HTTP_HOST $server_name; + fastcgi_pass unix:/run/fcgiwrap.sock; } } diff --git a/www/scripts/build.sh b/www/scripts/build.sh index 23c4a70..8bf6ffc 100755 --- a/www/scripts/build.sh +++ b/www/scripts/build.sh @@ -29,7 +29,7 @@ comment_block() { <<-COMMENT cat
[Comment on this page] - +