From 49889fe083ce8cab6e340f6fb999cc8ebe42ad69 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Fri, 7 Jun 2019 09:09:47 +0200 Subject: Embed CSS in executable the same way as fonts --- Makefile | 3 +-- assets/style.css | 1 + gopherproxy.go | 18 +++++++++++++----- style.go | 3 --- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 assets/style.css delete mode 100644 style.go diff --git a/Makefile b/Makefile index 247b88c..f25707c 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,7 @@ dev: build ./gopherproxy -bind 127.0.0.1:8000 build: clean - sassc -t compressed css/main.scss style.go - sed -i "s/.*/package gopherproxy\n\nvar styletext = \`&\`/" style.go + sassc -t compressed css/main.scss assets/style.css pyftsubset fonts/iosevka-term-ss03-regular.ttf --name-IDs+=0,4,6 --text-file=glyphs.txt --flavor='woff' --output-file='assets/iosevka-term-ss03-regular.woff' pyftsubset fonts/iosevka-term-ss03-regular.ttf --name-IDs+=0,4,6 --text-file=glyphs.txt --flavor='woff2' --output-file='assets/iosevka-term-ss03-regular.woff2' go build -o ./gopherproxy ./cmd/gopherproxy/main.go diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..938e25e --- /dev/null +++ b/assets/style.css @@ -0,0 +1 @@ +@font-face{font-family:'Iosevka Term SS03';font-style:normal;font-weight:normal;src:url("/iosevka-term-ss03-regular.woff2") format("woff2"),url("/iosevka-term-ss03-regular.woff") format("woff")}body{margin:0;padding:0;background-color:#14171a;color:#cad1d8}.wrap{text-align:center}.content{display:inline-block;min-width:50em;min-width:85ch;margin:0;padding:2em 1em;text-align:left;font-family:'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1em;line-height:1.5}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}.link-type{color:#929ba3} diff --git a/gopherproxy.go b/gopherproxy.go index e41af3d..b65418d 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -208,14 +208,22 @@ func ListenAndServe(bind, robotsfile, uri string) error { } } - styledata, err := ioutil.ReadFile(".style") - if err == nil { - styletext = string(styledata) - } - box := packr.NewBox("./assets") + fontdataw, err := box.Find("iosevka-term-ss03-regular.woff") + if err != nil { + fontdataw = []byte{} + } + fontdataw2, err := box.Find("iosevka-term-ss03-regular.woff2") + if err != nil { + fontdataw2 = []byte{} + } + + styletext, err := box.FindString("style.css") + if err != nil { + styletext = "" + } tpldata, err := ioutil.ReadFile(".template") if err == nil { diff --git a/style.go b/style.go deleted file mode 100644 index 7e1bdb9..0000000 --- a/style.go +++ /dev/null @@ -1,3 +0,0 @@ -package gopherproxy - -var styletext = `@font-face{font-family:'Iosevka Term SS03';font-style:normal;font-weight:normal;src:url("/iosevka-term-ss03-regular.woff2") format("woff2"),url("/iosevka-term-ss03-regular.woff") format("woff")}body{margin:0;padding:0;background-color:#14171a;color:#cad1d8}.wrap{text-align:center}.content{display:inline-block;min-width:50em;min-width:85ch;margin:0;padding:2em 1em;text-align:left;font-family:'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1em;line-height:1.5}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}.link-type{color:#929ba3}` -- cgit v1.2.3-70-g09d2