feat: aliases #5
@ -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
5
aliases.txt
Normal 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,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
25
src/aliases.go
Normal 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]
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", route)
|
||||
generateAliases()
|
||||
generateTmpl()
|
||||
if err := http.ListenAndServe(":3000", nil); err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -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},
|
||||
}
|
||||
|
||||
|
10
src/views.go
10
src/views.go
@ -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)
|
||||
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user