gemini-homepage

Gemini homepage for knutsen.co
git clone git://git.knutsen.co/gemini-homepage
Log | Files | Refs | LICENSE

commit e1967df54720b7578c9246b3c67b1b633090b541
Author: Demonstrandum <moi@knutsen.co>
Date:   Fri,  5 Feb 2021 20:32:55 +0000

Added server and .gmi files.

Diffstat:
A.gitignore | 6++++++
Ago.mod | 9+++++++++
Ago.sum | 35+++++++++++++++++++++++++++++++++++
Amain.go | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aviews/index.gmi | 34++++++++++++++++++++++++++++++++++
Aviews/music.gmi | 18++++++++++++++++++
6 files changed, 192 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +# Binary files +main +static/* + +# Pem +*.pem diff --git a/go.mod b/go.mod @@ -0,0 +1,9 @@ +module git.sr.ht/~knutsen/gemini-homepage + +go 1.15 + +require ( + github.com/pitr/gig v0.9.7 // indirect + golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect + golang.org/x/tools v0.1.0 // indirect +) diff --git a/go.sum b/go.sum @@ -0,0 +1,35 @@ +github.com/matryer/is v1.3.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= +github.com/pitr/gig v0.9.7 h1:VMwGTynX2LHppwOJTlEeUtIZnPOG/iwOMWvDZ61/RXQ= +github.com/pitr/gig v0.9.7/go.mod h1:YHUShtPtgG/zAsdlVG2HyzfGA1EKB+QBVFKxJ2qzxhU= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4= +github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go @@ -0,0 +1,90 @@ +package main + +import ("os"; "io"; "fmt"; "log") +import ("os/exec"; "time"; "bufio") +import "strings" +import "text/template" + +import "github.com/pitr/gig" + +var GEMINI_CERT = os.Getenv("GEMINI_CERT") +var GEMINI_KEY = os.Getenv("GEMINI_KEY") + +type Template struct { + templates *template.Template +} + +func (t *Template) Render(writer io.Writer, name string, + data interface{}, c gig.Context) error { + return t.templates.ExecuteTemplate(writer, name, data) +} + +type DefaultTemplate struct { + Date time.Time + Fortune string + Copyright string + Footer string +} + +func NewDefaultTemplate() (t DefaultTemplate) { + t = DefaultTemplate{} + t.Date = time.Now() + t.Copyright = "\U0001F12F Copyleft, all wrongs reserved." + t.Fortune = "Failed to run `fortune`." + + fortune := exec.Command("fortune", "-n", "short") + stdout, _ := fortune.StdoutPipe() + + err := fortune.Start() + if err == nil { + t.Fortune = "" + buf := bufio.NewReader(stdout) + for { + line, _, err := buf.ReadLine() + if err != nil { + if err == io.EOF { break } + log.Println("Error reading line.", err) + } + l := string(line) + l = strings.ReplaceAll(l, "--", "\u2014") + t.Fortune += "\n> " + l + } + } + + t.Footer = fmt.Sprintf("\n" + + "## \u2E3B\n" + + "%s\n" + + "```The date.\n" + + "~%04d.%02d.%02d\n" + + "```\n\n" + + "%s", + t.Fortune, + t.Date.Year(), t.Date.Month(), t.Date.Day(), + t.Copyright) + return +} + +func main() { + fmt.Println("[~] CERT:", GEMINI_CERT) + fmt.Println("[~] KEY:", GEMINI_KEY) + + s := gig.Default() + s.Renderer = &Template{ + templates: template.Must(template.ParseGlob("views/*.gmi")), + } + + defaultView := func (file string) (func(gig.Context) error) { + return func(c gig.Context) error { + defaultTemplate := NewDefaultTemplate() + return c.Render(file + ".gmi", defaultTemplate); + } + } + + s.Static("/static", "static") + s.Handle("/", defaultView("index")) + s.Handle("/:path", func(c gig.Context) error { + return defaultView(c.Param("path"))(c) + }) + + s.Run(GEMINI_CERT, GEMINI_KEY) +} diff --git a/views/index.gmi b/views/index.gmi @@ -0,0 +1,34 @@ +```ASCII Art. +───────────────▄▄───▐█ +───▄▄▄───▄██▄──█▀───█─▄ ╻┏ ┏┓╻╻ ╻╺┳╸┏━┓┏━╸┏┓╻ ┏━╸┏━┓ +─▄██▀█▌─██▄▄──▐█▀▄─▐█▀ ┣┻┓┃┗┫┃ ┃ ┃ ┗━┓┣╸ ┃┗┫ ┃ ┃ ┃ +▐█▀▀▌───▄▀▌─▌─█─▌──▌─▌ ╹ ╹╹ ╹┗━┛ ╹ ┗━┛┗━╸╹ ╹╹┗━╸┗━┛ +▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄ +``` +# Home, Sweet Home +Gemini homepage, hosted on a VPS somewhere in London. + +### Contact me +=> mailto:samuel@knutsen.co samuel@knutsen.co + +### Keys +=> /static/pgp_4096_rsa.pub PGP: 693BD1EE8BD77B43 +=> /static/ssh_4096_rsa.pub SSH: 4b:42:d8:30:43:65:53:21:be:53:97:49:bc:5f:96:44 + +### IDs +* ETH: 0x1C7fC5d267C3CEBc4AC875abB424b29dE5113071 +* Urbit: ~minten-migmug + +### WWW +View my homepage on the world-wide-web. +=> https://knutsen.co www.knutsen.co + +## ⸻ +{{ .Fortune }} +```The date. +~{{ .Date.Year }}.{{ printf "%02d" .Date.Month }}.{{ printf "%02d" .Date.Day }} +``` + +{{ .Copyright }} + + diff --git a/views/music.gmi b/views/music.gmi @@ -0,0 +1,18 @@ +# Music? + +Enjoy some tunes. + +```ASCII grammarphone +♫░░░█▄ +░♫░░████▄▄▄▄ +♫░░░██▀▀░░░░█ +░░♫░▀░░▓▓▓▓▀ +░░░░░▄██████▄ +``` + +> Music is an agreeable harmony for the honor of God and the permissible delights of the soul. +> — J. S. Bach + +=> /static/BWV1052_Allegro.ogg + +{{ .Footer }}