From f5a356773a1c771b90d73278ec973e7822789826 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Sun, 21 Mar 2021 09:13:33 +0000 Subject: [PATCH] Updated webpage --- Dockerfile | 5 +- README.md | 10 ++++ go.mod | 4 +- index.html | 142 ++++++++++++++++++++++++++++++----------------------- main.go | 10 ++-- 5 files changed, 101 insertions(+), 70 deletions(-) diff --git a/Dockerfile b/Dockerfile index afeedca..c74e6f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine AS builder +FROM golang:1.16-alpine AS builder RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates WORKDIR /app/ ADD go.mod go.sum ./ @@ -7,10 +7,7 @@ ADD . . RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o tweetsvg main.go FROM scratch - WORKDIR /app/ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /app/tweetsvg /app/tweetsvg -ADD tweet.svg.tmpl index.html ./ - ENTRYPOINT ["/app/tweetsvg"] diff --git a/README.md b/README.md index c7691a9..55b46b0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ + + + + + + + + + + # TweetSVG Generate an SVG for a given Tweet ID diff --git a/go.mod b/go.mod index 11adc62..89259d7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module tweetsvg -go 1.15 +go 1.16 require ( github.com/ChimeraCoder/anaconda v2.0.0+incompatible @@ -9,7 +9,7 @@ require ( github.com/dustin/go-jsonpointer v0.0.0-20160814072949-ba0abeacc3dc // indirect github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 // indirect - github.com/grokify/html-strip-tags-go v0.0.1 // indirect + github.com/grokify/html-strip-tags-go v0.0.1 github.com/joho/godotenv v1.3.0 golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect ) diff --git a/index.html b/index.html index 781fb83..8d9c1e1 100644 --- a/index.html +++ b/index.html @@ -3,75 +3,94 @@ + TweetSVG - + + + + + + + + + + + + + + -
-

TweetSVG

- -
- -
Preview
-
+
+

+ TweetSVG + +

+ +
+ Generate an SVG for a given Tweet ID +
+ +

+ Enter the URL or ID of a tweet to have an SVG generated for it, no JavaScript required! +

- - +
+
+
+ +
+ +
Preview
+
-
+ + + + + + + +
+ Source code available on GitHub, GitLab, Bitbucket & my own Gitea server. +
+ + +
+
+
+ +
+
+
diff --git a/main.go b/main.go index 5fed6ba..6bb583b 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,10 @@ package main import ( "bytes" + "embed" "encoding/base64" "fmt" "html/template" - "io/ioutil" "log" "math" "net/http" @@ -20,6 +20,10 @@ import ( "github.com/joho/godotenv" ) +//go:embed index.html tweet.svg.tmpl + +var content embed.FS + var ( api *anaconda.TwitterApi @@ -57,7 +61,7 @@ func main() { if len(r.URL.Path) > 1 { getTweet(w, r) } else { - body, _ := ioutil.ReadFile("index.html") + body, _ := content.ReadFile("index.html") w.Write(body) } }) @@ -144,7 +148,7 @@ func getTweet(w http.ResponseWriter, r *http.Request) { t := template.Must( template.New("tweet.svg.tmpl"). Funcs(templateFuncs). - ParseFiles("tweet.svg.tmpl")) + ParseFS(content, "tweet.svg.tmpl")) w.Header().Set("Content-type", "image/svg+xml") err = t.Execute(w, tweet)