Hi… I am well aware that this diff view is very suboptimal. It will be fixed when the refactored server comes along!
Serve tarball of source rather than using individual source files
/forge /version.go /vendor
/source.tar.gz
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
.PHONY: clean version.go man
.PHONY: clean version.go man source.tar.gz
CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99 -D_GNU_SOURCE MAN_PAGES = forge.5 hookc.1
forge: version.go hookc/*.c hookc/hookc man # TODO go mod vendor
forge: source.tar.gz version.go hookc/*.c hookc/hookc man # TODO
go build . man: $(MAN_PAGES:%=man/%.html) $(MAN_PAGES:%=man/%.txt) man/%.html: man/% mandoc -Thtml -O style=./mandoc.css $< > $@ man/%.txt: man/% utils/colb mandoc $< | ./utils/colb > $@ utils/colb: utils/colb.c hookc/hookc: version.go: printf 'package main\n\nconst VERSION = "%s"\n' `git describe --tags --always --dirty` > $@ clean: $(RM) forge version.go vendor
source.tar.gz: rm -f source.tar.gz go mod vendor git ls-files -z | xargs -0 tar -czf source.tar.gz vendor
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileContributor: Runxi Yu <https://runxiyu.org> package main import ( "embed" "html/template" "io/fs" "net/http" "github.com/tdewolff/minify/v2" "github.com/tdewolff/minify/v2/html" )
// We embed all source for easy AGPL compliance. // //go:embed .gitignore .gitattributes //go:embed LICENSE README.md //go:embed *.go go.mod go.sum //go:embed *.scfg //go:embed Makefile //go:embed static/* templates/* scripts/* sql/* man/* //go:embed hookc/*.c //go:embed vendor/*
//go:embed LICENSE source.tar.gz
var sourceFS embed.FS
var sourceHandler = http.StripPrefix(
"/:/source/",
http.FileServer(http.FS(sourceFS)),
)
//go:embed templates/* static/* hookc/hookc man/*.html man/*.txt man/*.css
var resourcesFS embed.FS
var templates *template.Template
func loadTemplates() (err error) {
minifier := minify.New()
minifierOptions := html.Minifier{
TemplateDelims: [2]string{"{{", "}}"},
KeepDefaultAttrVals: true,
} //exhaustruct:ignore
minifier.Add("text/html", &minifierOptions)
templates = template.New("templates").Funcs(template.FuncMap{
"first_line": firstLine,
"base_name": baseName,
"path_escape": pathEscape,
"query_escape": queryEscape,
"dereference_error": dereferenceOrZero[error],
"minus": minus,
})
err = fs.WalkDir(resourcesFS, "templates", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() {
content, err := fs.ReadFile(resourcesFS, path)
if err != nil {
return err
}
minified, err := minifier.Bytes("text/html", content)
if err != nil {
return err
}
_, err = templates.Parse(bytesToString(minified))
if err != nil {
return err
}
}
return nil
})
return err
}
var (
staticHandler http.Handler
manHandler http.Handler
)
func init() {
staticFS, err := fs.Sub(resourcesFS, "static")
if err != nil {
panic(err)
}
staticHandler = http.StripPrefix("/:/static/", http.FileServer(http.FS(staticFS)))
manFS, err := fs.Sub(resourcesFS, "man")
if err != nil {
panic(err)
}
manHandler = http.StripPrefix("/:/man/", http.FileServer(http.FS(manFS)))
}
{{/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
*/}}
{{- define "footer" -}}
<a href="https://lindenii.runxiyu.org/forge/">Lindenii Forge</a>
{{ .global.forge_version }}
(<a href="/:/source/">source</a>,
(<a href="/:/source/source.tar.gz">source</a>,
<a href="https://forge.lindenii.runxiyu.org/lindenii/forge/:/repos/server/">upstream</a>,
<a href="/:/source/LICENSE">license</a>)
{{- end -}}