summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--Makefile67
-rw-r--r--auth.go (renamed from backend/auth.go)0
-rw-r--r--backend/Makefile3
-rw-r--r--bench/Makefile2
-rw-r--r--config.go (renamed from backend/config.go)21
-rw-r--r--courses.go (renamed from backend/courses.go)0
-rw-r--r--db.go (renamed from backend/db.go)0
-rw-r--r--docs/Makefile7
-rw-r--r--docs/admin_handbook.html15
-rw-r--r--docs/cca.scfg.example14
-rw-r--r--frontend/Makefile7
-rw-r--r--frontend/README.md17
-rw-r--r--go.mod (renamed from backend/go.mod)0
-rw-r--r--go.sum (renamed from backend/go.sum)0
-rw-r--r--iadocs/.gitignore5
-rw-r--r--iadocs/Makefile13
-rw-r--r--index.go (renamed from backend/index.go)3
-rw-r--r--main.go (renamed from backend/main.go)34
-rwxr-xr-xscripts/lint.sh1
-rw-r--r--sql/Makefile7
-rw-r--r--tmpl/Makefile15
-rw-r--r--tmpl/login.html21
-rw-r--r--tmpl/staff.html21
-rw-r--r--tmpl/student.html21
-rw-r--r--usem.go (renamed from backend/usem.go)0
-rw-r--r--utils.go (renamed from backend/utils.go)0
-rw-r--r--wsc.go (renamed from backend/wsc.go)0
-rw-r--r--wsh.go (renamed from backend/wsh.go)0
-rw-r--r--wsm.go (renamed from backend/wsm.go)0
-rw-r--r--wsp.go (renamed from backend/wsp.go)0
-rw-r--r--wsx.go (renamed from backend/wsx.go)0
32 files changed, 144 insertions, 151 deletions
diff --git a/.gitignore b/.gitignore
index 02ad029..268e868 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
cca.scfg
dist
+build
diff --git a/Makefile b/Makefile
index bfdb50a..3f384c6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,60 @@
-.PHONY: default backend tmpl frontend docs sql iadocs
+# TODO: Use some variables to clean up the massive documentation file specifiers
-default: backend tmpl frontend docs sql iadocs
+.PHONY: cca default minifier iadocs docs build_iadocs build_docs
-backend:
- make -C backend
+default: dist/cca docs iadocs
-tmpl:
- make -C tmpl
+cca: dist/cca
-frontend:
- make -C frontend
+docs: dist/docs/admin_handbook.html dist/docs/handbook.css dist/docs/cca.scfg.example
-docs:
- make -C docs
+iadocs: dist/iadocs/cover_page.htm dist/iadocs/appendix.pdf dist/iadocs/crita_planning.pdf dist/iadocs/critb_design.pdf dist/iadocs/critb_recordoftasks.pdf dist/iadocs/critc_development.pdf dist/iadocs/critd_functionality.pdf dist/iadocs/crite_evaluation.pdf
-sql:
- make -C sql
+# Final binary which tries to embed stuff
+dist/cca: *.go build/static/style.css build/static/student.js tmpl/* build/docs/admin_handbook.html build/docs/handbook.css build/docs/cca.scfg.example build/iadocs/cover_page.htm build/iadocs/appendix.pdf build/iadocs/crita_planning.pdf build/iadocs/critb_design.pdf build/iadocs/critb_recordoftasks.pdf build/iadocs/critc_development.pdf build/iadocs/critd_functionality.pdf build/iadocs/crite_evaluation.pdf
+ mkdir -p dist
+ go build -o $@
-iadocs:
- make -C iadocs
+# Documentation
+dist/docs/%: build/docs/%
+ mkdir -p dist/docs
+ cp $< $@
+build/docs/%.html: docs/%.html
+ mkdir -p build/docs
+ minify --html-keep-end-tags --html-keep-document-tags -o $@ $<
+build/docs/handbook.css: docs/handbook.css
+ mkdir -p build/docs
+ minify -o $@ $<
+build/docs/cca.scfg.example: docs/cca.scfg.example
+ mkdir -p build/docs
+ cp $< $@
+
+# IA documentation
+dist/iadocs/%.pdf: build/iadocs/%.pdf
+ mkdir -p dist/iadocs
+ cp $< $@
+dist/iadocs/%.htm: build/iadocs/%.htm
+ mkdir -p dist/iadocs
+ cp $< $@
+build/iadocs/%.htm: iadocs/%.htm
+ mkdir -p build/iadocs
+ minify --html-keep-end-tags --html-keep-document-tags -o $@ $<
+build/iadocs/%.pdf: iadocs/%.tex build/iadocs/header.inc
+ mkdir -p build/iadocs
+ lualatex -output-directory=build/iadocs $<
+ lualatex -output-directory=build/iadocs $<
+build/iadocs/%.inc: iadocs/%.inc
+ mkdir -p build/iadocs
+ cp $< $@
+
+# Temporary files in build/ to be embedded into the final binary
+build/static/style.css: frontend/style.css
+ mkdir -p build/static
+ minify -o $@ $<
+build/static/student.js: frontend/student.js
+ mkdir -p build/static
+ minify -o $@ $<
+
+# External dependencies
+minifier:
+ go install github.com/tdewolff/minify/v2/cmd/minify@latest
diff --git a/backend/auth.go b/auth.go
index 9ef1254..9ef1254 100644
--- a/backend/auth.go
+++ b/auth.go
diff --git a/backend/Makefile b/backend/Makefile
deleted file mode 100644
index 22c6e5f..0000000
--- a/backend/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-../dist/cca: *.go
- mkdir -p ../dist
- go build -o ../dist/cca
diff --git a/bench/Makefile b/bench/Makefile
deleted file mode 100644
index c178fbe..0000000
--- a/bench/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-bench: bench.go
- go build -o bench
diff --git a/backend/config.go b/config.go
index e5bea02..f1e48e9 100644
--- a/backend/config.go
+++ b/config.go
@@ -41,9 +41,6 @@ import (
var configWithPointers struct {
URL *string `scfg:"url"`
Prod *bool `scfg:"prod"`
- Tmpl *string `scfg:"tmpl"`
- Static *string `scfg:"static"`
- Source *string `scfg:"source"`
Listen struct {
Proto *string `scfg:"proto"`
Net *string `scfg:"net"`
@@ -78,9 +75,6 @@ var configWithPointers struct {
var config struct {
URL string
Prod bool
- Tmpl string
- Static string
- Source string
Listen struct {
Proto string
Net string
@@ -156,21 +150,6 @@ func fetchConfig(path string) (retErr error) {
}
config.Prod = *(configWithPointers.Prod)
- if configWithPointers.Tmpl == nil {
- return fmt.Errorf("%w: tmpl", errMissingConfigValue)
- }
- config.Tmpl = *(configWithPointers.Tmpl)
-
- if configWithPointers.Static == nil {
- return fmt.Errorf("%w: static", errMissingConfigValue)
- }
- config.Static = *(configWithPointers.Static)
-
- if configWithPointers.Source == nil {
- return fmt.Errorf("%w: source", errMissingConfigValue)
- }
- config.Source = *(configWithPointers.Source)
-
if configWithPointers.Listen.Proto == nil {
return fmt.Errorf("%w: listen.proto", errMissingConfigValue)
}
diff --git a/backend/courses.go b/courses.go
index 4e1ea51..4e1ea51 100644
--- a/backend/courses.go
+++ b/courses.go
diff --git a/backend/db.go b/db.go
index 9ced627..9ced627 100644
--- a/backend/db.go
+++ b/db.go
diff --git a/docs/Makefile b/docs/Makefile
deleted file mode 100644
index 6e023a7..0000000
--- a/docs/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-.PHONY: docs
-
-docs: ../dist/docs/admin_handbook.html ../dist/docs/cca.scfg.example ../dist/docs/handbook.css
-
-../dist/docs/%: %
- mkdir -p ../dist/docs
- cp $< $@
diff --git a/docs/admin_handbook.html b/docs/admin_handbook.html
index 4d3e1db..c746bd3 100644
--- a/docs/admin_handbook.html
+++ b/docs/admin_handbook.html
@@ -25,16 +25,17 @@
<li>To obtain a stable version, go to the <a href="https://git.sr.ht/~runxiyu/cca/refs">release page</a> and download the latest version that is not a pre-release.</li>
<li>To obtain an unstable development version, clone the development repository at <a href="https://git.sr.ht/~runxiyu/cca"><code>https://git.sr.ht/~runxiyu/cca</code></a>, or download the latest development snapshot&rsquo;s tarball at <a href="https://git.runxiyu.org/ykps/cca.git/snapshot/cca-master.tar.gz"><code>https://git.runxiyu.org/ykps/cca.git/snapshot/cca-master.tar.gz</code></a>.</li>
</ul>
- <h2>Building</h2>
+ <h2>External dependencies</h2>
+ <p>
+ You need a <a href="https://go.dev">Go</a> toolchain, <a href="https://www.gnu.org/software/make/">GNU make</a>, <a href="https://tug.org/texlive/">TeX Live</a> and <a href="https://github.com/tdewolff/minify">minify</a>. If you have everything else, you could install minify via <code>make minifier</code>, which would build and install it with your Go toolchain.
+ </p>
<p>
- You need a standard Go toolchain to build the backend. You need <a href="https://github.com/tdewolff/minify">minify</a> to build the minified frontend; read the README in the frontend directory for details; if you don&rsquo;t want to minify, you could just copy the files over.
+ The Go toolchain will fetch more dependencies. You may wish to set a Go proxy (such as via <code>export GOPROXY='https://goproxy.io'</code>) if it stalls or is too slow. This is likely necessary for users in Mainland China due to firewall restrictions.
</p>
- <pre>cd ./backend/
-make
-cd ../frontend/
-make</pre>
+ <h2>Building</h2>
+ <p>Just type <code>make</code>.</p>
<p>
- Your compiled files will appear in <code>dist/</code>.
+ The built files will appear in <code>dist/</code>. The binary, with all runtime resources other than the configuration file embedded, is located at <code>dist/cca</code>. A minified copy of the documentation, including a sample configuration file, is located at <code>dist/docs/</code>.
</p>
<h2>Configuration</h2>
<p>
diff --git a/docs/cca.scfg.example b/docs/cca.scfg.example
index c33293b..cdae443 100644
--- a/docs/cca.scfg.example
+++ b/docs/cca.scfg.example
@@ -6,20 +6,6 @@ url http://localhost:5555
# cookies and may come with other production-related changes in the future.
prod false
-# Where are the template files? Usually this should be a directory inside the
-# source directory, though it might exist in /usr/local/share or /usr/share if
-# this ever gets packaged or something. Remember that this is a file glob, so
-# be sure to use /* or something similar.
-tmpl tmpl/*
-
-# Where is the static directory? Reverse proxy setups are not recommended for
-# performance reasons so we serve the static files ourselves.
-static static/
-
-# Where could the source code of this instance be found? It is important to
-# keep this up to date to comply with the AGPL.
-source https://git.sr.ht/~runxiyu/cca
-
listen {
# Which protocol are we listening for? Currently only "http" is
# supported because it is difficult to configure FastCGI to work with
diff --git a/frontend/Makefile b/frontend/Makefile
deleted file mode 100644
index 86251a9..0000000
--- a/frontend/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-.PHONY: frontend
-
-frontend: ../dist/static/student.js ../dist/static/style.css
-
-../dist/static/%: %
- mkdir -p ../dist/static
- minify $< -o $@
diff --git a/frontend/README.md b/frontend/README.md
deleted file mode 100644
index d586f3a..0000000
--- a/frontend/README.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# Frontend
-
-We do not use a JavaScript package manager because we don't use any JavaScript
-libraries at all.
-
-## JavaScript linting
-
-eslint may be installed separately via pgx if linting is desired.
-
-## Building
-
-Building is actually just minification.
-
-```sh
-go install github.com/tdewolff/minify/v2/cmd/minify@latest
-make
-```
diff --git a/backend/go.mod b/go.mod
index 717f737..717f737 100644
--- a/backend/go.mod
+++ b/go.mod
diff --git a/backend/go.sum b/go.sum
index ca23612..ca23612 100644
--- a/backend/go.sum
+++ b/go.sum
diff --git a/iadocs/.gitignore b/iadocs/.gitignore
deleted file mode 100644
index 1c7499e..0000000
--- a/iadocs/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-*.pdf
-*.log
-*.aux
-*.toc
-*.out
diff --git a/iadocs/Makefile b/iadocs/Makefile
deleted file mode 100644
index 17277a0..0000000
--- a/iadocs/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-.PHONY: iadocs
-
-iadocs: ../dist/iadocs/cover_page.htm ../dist/iadocs/crita_planning.pdf ../dist/iadocs/critb_design.pdf ../dist/iadocs/critb_recordoftasks.pdf ../dist/iadocs/critc_development.pdf ../dist/iadocs/critd_functionality.pdf ../dist/iadocs/crite_evaluation.pdf ../dist/iadocs/appendix.pdf
-
-../dist/iadocs/%.htm: %.htm
- mkdir -p ../dist/iadocs
- cp $< $@
-
-../dist/iadocs/%.pdf: %.tex header.inc
- mkdir -p ../dist/iadocs
- lualatex $<
- lualatex $<
- mv $$(basename $@) $@
diff --git a/backend/index.go b/index.go
index f446072..a75f3d2 100644
--- a/backend/index.go
+++ b/index.go
@@ -46,7 +46,6 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
"login",
map[string]string{
"authURL": authURL,
- "source": config.Source,
/*
* We directly generate the login URL here
* instead of doing so in a redirect to save
@@ -83,7 +82,6 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
map[string]interface{}{
"authURL": authURL,
"notes": "You sent an invalid session cookie.",
- "source": config.Source,
},
)
if err != nil {
@@ -109,7 +107,6 @@ func handleIndex(w http.ResponseWriter, req *http.Request) {
"Department": userDepartment,
},
"courses": courses,
- "source": config.Source,
},
)
}()
diff --git a/backend/main.go b/main.go
index a185de9..20e7fe2 100644
--- a/backend/main.go
+++ b/main.go
@@ -22,7 +22,9 @@ package main
import (
"crypto/tls"
+ "embed"
"flag"
+ "io/fs"
"html/template"
"log"
"net"
@@ -32,6 +34,12 @@ import (
var tmpl *template.Template
+//go:embed build/static/* tmpl/* build/iadocs/* build/docs/*
+var runFS embed.FS
+
+//go:embed *.go docs/* frontend/* README.md LICENSE Makefile iadocs/* sql/* tmpl/* scripts/*
+var srcFS embed.FS
+
func main() {
var err error
@@ -55,7 +63,7 @@ func main() {
}
log.Println("Setting up templates")
- tmpl, err = template.ParseGlob(config.Tmpl)
+ tmpl, err = template.ParseFS(runFS, "tmpl/*")
if err != nil {
log.Fatal(err)
}
@@ -67,8 +75,28 @@ func main() {
}
log.Println("Registering static handle")
- fs := http.FileServer(http.Dir(config.Static))
- http.Handle("/static/", http.StripPrefix("/static/", fs))
+ staticFS, err := fs.Sub(runFS, "build/static")
+ if err != nil {
+ log.Fatal(err)
+ }
+ http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
+
+ log.Println("Registering iadocs handle")
+ iaDocsFS, err := fs.Sub(runFS, "build/iadocs")
+ if err != nil {
+ log.Fatal(err)
+ }
+ http.Handle("/iadocs/", http.StripPrefix("/iadocs/", http.FileServer(http.FS(iaDocsFS))))
+
+ log.Println("Registering docs handle")
+ docsFS, err := fs.Sub(runFS, "build/docs")
+ if err != nil {
+ log.Fatal(err)
+ }
+ http.Handle("/docs/", http.StripPrefix("/docs/", http.FileServer(http.FS(docsFS))))
+
+ log.Println("Registering source handle")
+ http.Handle("/src/", http.StripPrefix("/src/", http.FileServer(http.FS(srcFS))))
log.Println("Registering handlers")
http.HandleFunc("/{$}", handleIndex)
diff --git a/scripts/lint.sh b/scripts/lint.sh
index 75ec46d..73e9878 100755
--- a/scripts/lint.sh
+++ b/scripts/lint.sh
@@ -1,4 +1,3 @@
#!/bin/sh
set -e
-cd backend
golangci-lint run --color=always --enable-all --disable=wsl,funlen,exportloopref,gomnd,execinquery,godox,lll,gochecknoglobals,depguard,cyclop,gosmopolitan,nlreturn,varnamelen,nestif,musttag,mnd,tagliatelle,gocognit,gocyclo,maintidx,dogsled,unparam,nonamedreturns
diff --git a/sql/Makefile b/sql/Makefile
deleted file mode 100644
index eae4c13..0000000
--- a/sql/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-.PHONY: sql
-
-docs: ../dist/sql/schema.sql
-
-../dist/sql/%: %
- mkdir -p ../dist/sql
- cp $< $@
diff --git a/tmpl/Makefile b/tmpl/Makefile
deleted file mode 100644
index 61f3713..0000000
--- a/tmpl/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-.PHONY: default ../dist/tmpl/student.html ../dist/tmpl/staff.html ../dist/tmpl/login.html
-
-default: ../dist/tmpl/student.html ../dist/tmpl/staff.html ../dist/tmpl/login.html
-
-../dist/tmpl/student.html: student.html
- mkdir -p ../dist/tmpl
- cp student.html ../dist/tmpl/student.html
-
-../dist/tmpl/staff.html: staff.html
- mkdir -p ../dist/tmpl
- cp staff.html ../dist/tmpl/staff.html
-
-../dist/tmpl/login.html: login.html
- mkdir -p ../dist/tmpl
- cp login.html ../dist/tmpl/login.html
diff --git a/tmpl/login.html b/tmpl/login.html
index af69519..1f8e89b 100644
--- a/tmpl/login.html
+++ b/tmpl/login.html
@@ -20,9 +20,25 @@
<header>
<div class="header-content">
<div class="header-left">
- <h1><a id="site-title" href="/">CCA Selection System</a></h1>
+ <h1><a id="site-title" href="./">CCA Selection System</a></h1>
</div>
<div class="header-middle">
+ <nav>
+ <ul>
+ <li>
+ <a href="./">Home</a>
+ </li>
+ <li>
+ <a href="./docs/">Docs</a>
+ </li>
+ <li>
+ <a href="./iadocs/">IA Docs</a>
+ </li>
+ <li>
+ <a href="./src/">Source</a>
+ </li>
+ </ul>
+ </nav>
</div>
<div class="header-right">
<p>Unauthenticated</p>
@@ -42,9 +58,6 @@
</p>
</div>
</main>
- <footer>
- CCA Selection System, licensed under the GNU Affero General Public License, version 3.0 or any later version. Source code available at <a href="{{.source}}"><code>{{.source}}</code></a>.
- </footer>
</body>
</html>
{{- end -}}
diff --git a/tmpl/staff.html b/tmpl/staff.html
index 9bc5100..bf74d8b 100644
--- a/tmpl/staff.html
+++ b/tmpl/staff.html
@@ -17,9 +17,25 @@
<header>
<div class="header-content">
<div class="header-left">
- <h1><a id="site-title" href="/">CCASS Staff Page</a></h1>
+ <h1><a id="site-title" href="./">CCASS Staff Page</a></h1>
</div>
<div class="header-middle">
+ <nav>
+ <ul>
+ <li>
+ <a href="./">Home</a>
+ </li>
+ <li>
+ <a href="./docs/">Docs</a>
+ </li>
+ <li>
+ <a href="./iadocs/">IA Docs</a>
+ </li>
+ <li>
+ <a href="./src/">Source</a>
+ </li>
+ </ul>
+ </nav>
</div>
<div class="header-right">
<p>{{- .user.Name }} ({{ .user.Department -}})</p>
@@ -128,9 +144,6 @@
</div>
</div>
</div>
- <footer>
- CCA Selection System, licensed under the GNU Affero General Public License, version 3.0 or any later version. Source code available at <a href="{{.source}}"><code>{{.source}}</code></a>.
- </footer>
<script src="static/staff.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
diff --git a/tmpl/student.html b/tmpl/student.html
index ea5fae5..8b6982b 100644
--- a/tmpl/student.html
+++ b/tmpl/student.html
@@ -17,9 +17,25 @@
<header>
<div class="header-content">
<div class="header-left">
- <h1><a id="site-title" href="/">CCA Selection System</a></h1>
+ <h1><a id="site-title" href="./">CCA Selection System</a></h1>
</div>
<div class="header-middle">
+ <nav>
+ <ul>
+ <li>
+ <a href="./">Home</a>
+ </li>
+ <li>
+ <a href="./docs/">Docs</a>
+ </li>
+ <li>
+ <a href="./iadocs/">IA Docs</a>
+ </li>
+ <li>
+ <a href="./src/">Source</a>
+ </li>
+ </ul>
+ </nav>
</div>
<div class="header-right">
<p>{{- .user.Name }} ({{ .user.Department -}})</p>
@@ -155,9 +171,6 @@
-->
</div>
</div>
- <footer>
- CCA Selection System, licensed under the GNU Affero General Public License, version 3.0 or any later version. Source code available at <a href="{{.source}}"><code>{{.source}}</code></a>.
- </footer>
<script src="static/student.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
diff --git a/backend/usem.go b/usem.go
index 0b839a4..0b839a4 100644
--- a/backend/usem.go
+++ b/usem.go
diff --git a/backend/utils.go b/utils.go
index 3628c80..3628c80 100644
--- a/backend/utils.go
+++ b/utils.go
diff --git a/backend/wsc.go b/wsc.go
index 982c1fb..982c1fb 100644
--- a/backend/wsc.go
+++ b/wsc.go
diff --git a/backend/wsh.go b/wsh.go
index abf4e61..abf4e61 100644
--- a/backend/wsh.go
+++ b/wsh.go
diff --git a/backend/wsm.go b/wsm.go
index 5f271ff..5f271ff 100644
--- a/backend/wsm.go
+++ b/wsm.go
diff --git a/backend/wsp.go b/wsp.go
index 7a1f6ab..7a1f6ab 100644
--- a/backend/wsp.go
+++ b/wsp.go
diff --git a/backend/wsx.go b/wsx.go
index a51b976..a51b976 100644
--- a/backend/wsx.go
+++ b/wsx.go