feat: aliases #5

Merged
ange merged 3 commits from devel into prod 2025-04-05 10:17:05 +00:00
10 changed files with 43 additions and 9 deletions
Showing only changes of commit d8ecbef86e - Show all commits

View File

@ -1,4 +1,4 @@
FROM docker.io/golang:1.23 AS build
FROM docker.io/golang:1.24 AS build
WORKDIR /build/
COPY go.mod go.sum .
RUN go mod download
@ -11,5 +11,6 @@ COPY html/ html/
COPY css/ css/
COPY static/ static/
COPY tmpl/ tmpl/
COPY aliases.txt aliases.txt
EXPOSE 3000
CMD ["./app"]

5
aliases.txt Normal file
View File

@ -0,0 +1,5 @@
ssh /static/ssh
pgp /static/pgp.asc
termux.sh https://git.gmoker.com/ange/termux/raw/branch/main/install.sh
dotfiles.sh
archinstall.sh

2
go.mod
View File

@ -1,3 +1,3 @@
module main
go 1.23.3
go 1.24.1

View File

@ -2,7 +2,7 @@
<html>
<head>
{{template "head.tmpl" .}}
<script src="static/copy.js"></script>
<script src="copy.js"></script>
</head>
<body>
{{template "header.tmpl" .}}

25
src/aliases.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"bufio"
"log"
"os"
"strings"
)
var ALIASES map[string]string
func generateAliases() {
f, err := os.Open("aliases.txt")
if err != nil {
log.Fatal(err)
}
sc := bufio.NewScanner(f)
ALIASES = make(map[string]string)
for sc.Scan() {
sp := strings.Fields(sc.Text())
ALIASES[sp[0]] = sp[1]
}
}

View File

@ -7,6 +7,7 @@ import (
func main() {
http.HandleFunc("/", route)
generateAliases()
generateTmpl()
if err := http.ListenAndServe(":3000", nil); err != nil {
log.Fatal(err)

View File

@ -17,7 +17,7 @@ var routes = []struct {
}{
{[]string{"GET"}, url(""), index},
{[]string{"GET"}, url("/static/.+"), static},
{[]string{"GET"}, url("/(.+\\.css)"), css},
{[]string{"GET"}, url("/(.+\\.(css|js))"), file},
{[]string{"GET"}, url("/([^/]+)"), html},
}

View File

@ -1,8 +1,8 @@
package main
import (
"path/filepath"
"net/http"
"path/filepath"
)
func index(w http.ResponseWriter, r *http.Request) {
@ -13,12 +13,14 @@ func static(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path)
}
func css(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join("css", getParam(r, 0)))
func file(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(getParam(r, 1), getParam(r, 0)))
}
func html(w http.ResponseWriter, r *http.Request) {
if t, found := TMPL[getParam(r, 0)]; found {
if a, found := ALIASES[getParam(r, 0)]; found {
http.Redirect(w, r, a, http.StatusFound)
} else if t, found := TMPL[getParam(r, 0)]; found {
w.Write(t)
} else {
http.NotFound(w, r)

View File

@ -1,6 +1,6 @@
<div id="header">
<a id="headerLink" href="/">Ange DUHAYON</a>
<span id="headerSubtitle">AAAAAAAAAAAAAAAAAAAAAAAAAAAA</span>
<span id="headerSubtitle">DevOps Engineer</span>
<span id="credits" class="right" style="font-size: .4em;">Website heavily inspired from <a href="//suckless.org/" target="_blank" rel="noreferrer noopener">suckless.org</a></span>
</div>
<div id="menu">