all repos — flounder @ 646872f120abe310670252db919aaca54c7d17aa

A small site builder for the Gemini protocol

Create page for converting text
alex wennerberg alex@alexwennerberg.com
Sun, 24 Jan 2021 22:29:37 -0800
commit

646872f120abe310670252db919aaca54c7d17aa

parent

23270a1690d48c2b996eef52a942779dbe4c7dfe

4 files changed, 45 insertions(+), 0 deletions(-)

jump to
M go.modgo.mod

@@ -5,6 +5,7 @@

require ( git.sr.ht/~adnano/go-gemini v0.1.8 github.com/BurntSushi/toml v0.3.1 + github.com/LukeEmmet/html2gemini v0.0.0-20201115162526-e63bbe688236 github.com/emersion/go-webdav v0.3.0 github.com/go-co-op/gocron v0.5.0 github.com/gorilla/feeds v1.1.1
M go.sumgo.sum

@@ -16,6 +16,8 @@ git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f h1:f5axCdaRzGDCihN3o1Lq0ydn0VlkhY+11G0JOyY5qss=

git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/LukeEmmet/html2gemini v0.0.0-20201115162526-e63bbe688236 h1:FqsaW6vEhQsER1rqN07RkjYMkGxBORvTNkxUMlJDbTQ= +github.com/LukeEmmet/html2gemini v0.0.0-20201115162526-e63bbe688236/go.mod h1:UFD98yRRVkWrb7yNSXy9UTyHdnSMthMdfLwUYx19PkM= github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

@@ -64,11 +66,15 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=

github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.4 h1:4rQjbDxdu9fSgI/r3KN72G3c2goxknAqHHgPWWs8UlI= github.com/mattn/go-sqlite3 v1.14.4/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= +github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=

@@ -78,6 +84,8 @@ github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=

github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= +github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

@@ -99,6 +107,7 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg= golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
M http.gohttp.go

@@ -4,6 +4,7 @@ import (

"bytes" "fmt" gmi "git.sr.ht/~adnano/go-gemini" + "github.com/LukeEmmet/html2gemini" "github.com/gorilla/handlers" "github.com/gorilla/sessions" _ "github.com/mattn/go-sqlite3"

@@ -735,6 +736,29 @@ http.Redirect(w, r, "/admin", http.StatusSeeOther)

} } +func convertTextHandler(w http.ResponseWriter, r *http.Request) { + text := "" + var err error + if r.Method == "GET" { + text = "" + } else if r.Method == "POST" { + r.ParseForm() + fmt.Println(r.Form.Get("file_text")) + ctx := html2gemini.NewTraverseContext(html2gemini.Options{}) + text, err = html2gemini.FromString(r.Form.Get("file_text"), *ctx) + fmt.Println(text) + if err != nil { + panic(err) + } + // TODO handle error? + } + data := struct { + Config Config + Text string + }{c, text} + t.ExecuteTemplate(w, "convert.html", data) +} + func checkDomainHandler(w http.ResponseWriter, r *http.Request) { domain := r.URL.Query().Get("domain") if domain != "" && domains[domain] != "" {

@@ -764,6 +788,7 @@ serveMux.HandleFunc(hostname+"/me", myAccountHandler)

serveMux.HandleFunc(hostname+"/my_site/flounder-archive.zip", archiveHandler) serveMux.HandleFunc(hostname+"/admin", adminHandler) serveMux.HandleFunc(hostname+"/edit/", editFileHandler) + serveMux.HandleFunc(hostname+"/convert", convertTextHandler) serveMux.HandleFunc(hostname+"/upload", uploadFilesHandler) serveMux.Handle(hostname+"/login", limit(http.HandlerFunc(loginHandler))) serveMux.Handle(hostname+"/register", limit(http.HandlerFunc(registerHandler)))
A templates/convert.html

@@ -0,0 +1,10 @@

+{{template "header" .}} +<h1>Convert HTML to Gemini Text</h1> +<p> +A tool for converting HTML to Gemini Text. Useful if you have an HTML site you want to add to Flounder.</p> +<form id="convert-form" action="/convert" method="POST"> + <textarea rows="27" name="file_text" id="editor">{{.Text}}</textarea> + <br> + <input type="submit" value="Convert" class="button"> +</form> +{{ template "footer" .}}