initial broken draft of relays page.

This commit is contained in:
fiatjaf
2023-07-11 18:19:11 -03:00
parent bfa2f5f537
commit d734b189d9
7 changed files with 174 additions and 33 deletions

38
main.go
View File

@@ -1,16 +1,50 @@
package main
import (
"embed"
"html"
"net/http"
"os"
"text/template"
"github.com/rs/zerolog"
)
var log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stdout}).
With().Timestamp().Logger()
//go:embed static/*
var static embed.FS
//go:embed templates/*
var templates embed.FS
var (
tmpl *template.Template
templateMapping = make(map[string]string)
log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
)
func main() {
// initialize templates
// use a mapping to expressly link the templates and share them between more kinds/types
templateMapping["profile"] = "profile.html"
templateMapping["note"] = "note.html"
templateMapping["address"] = "other.html"
templateMapping["relay"] = "relay.html"
funcMap := template.FuncMap{
"basicFormatting": basicFormatting,
"mdToHTML": mdToHTML,
"escapeString": html.EscapeString,
"sanitizeXSS": sanitizeXSS,
}
tmpl = template.Must(
template.New("tmpl").
Funcs(funcMap).
ParseFS(templates, "templates/*"),
)
// routes
http.HandleFunc("/njump/image/", generate)
http.HandleFunc("/njump/proxy/", proxy)
http.Handle("/njump/static/", http.StripPrefix("/njump/", http.FileServer(http.FS(static))))