Make cgit go gettable
go get git.icyphox.sh/* works!
go get
requires the presence of the go-import
meta tag1 on the
repository’s web page. cgit doesn’t support it out of the box; instead,
we can make nginx inject it into every page. Enter: sub_filter
.2
sub_filter
is a function that simply performs a string replace. For
example:
location / {
sub_filter '<img src=dog.png>' '<img src=cat.png>';
sub_filter_once on;
}
In our case, we want to have the meta tag injected inside <head>
.
server {
listen 443 ssl;
server_name git.icyphox.sh;
location / {
...
sub_filter '</head>'
'<meta name="go-import" content="$host$uri git https://$host$uri"></head>';
sub_filter_once on;
}
}
The closing </head>
tag gets replaced—injecting the meta tag inside
<head>
. This can also be extended to add the go-source
meta tag as
well.
Questions or comments? Send an email.