From d0c5be4444ee2c1b8371456adb2f65bf6ef62234 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 25 May 2023 22:10:49 +0700 Subject: cmd/www-go-proposal: static HTTP server to serve proposal with HTML --- .gitignore | 4 + Makefile | 20 ++++ assets/go-logo-blue.svg | 1 + assets/style.css | 245 ++++++++++++++++++++++++++++++++++++++++++++ cmd/www-go-proposal/main.go | 38 +++++++ go.mod | 21 ++++ go.sum | 18 ++++ html.tmpl | 73 +++++++++++++ 8 files changed, 420 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 assets/go-logo-blue.svg create mode 100644 assets/style.css create mode 100644 cmd/www-go-proposal/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 html.tmpl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1936a20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.html +/cmd/www-go-proposal/memfs.go +/design/draft-module-local.md +/www-go-proposal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0223d8d --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: embed +embed: + ciigo -exclude "(cmd|go.mod|go.sum)" \ + -template ./html.tmpl \ + -out cmd/www-go-proposal/memfs.go \ + embed . + +.PHONY: dev +dev: + DEBUG=1 go run ./cmd/www-go-proposal + +.PHONY: deploy +deploy: embed + go build ./cmd/www-go-proposal + rsync ./www-go-proposal golang-id.org:~/bin/ + +.PHONY: deploy-vm +deploy-vm: embed + go build ./cmd/www-go-proposal + rsync ./www-go-proposal golang-id.local:~/bin/ diff --git a/assets/go-logo-blue.svg b/assets/go-logo-blue.svg new file mode 100644 index 0000000..da6ea83 --- /dev/null +++ b/assets/go-logo-blue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..8700ad2 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,245 @@ +body { + margin: 0; + font-family: Arial, sans-serif; + background-color: #fff; + line-height: 1.3; + text-align: center; + color: #222; +} +pre, +code { + font-family: Menlo, monospace; + font-size: 0.875rem; +} +pre { + line-height: 1.4; + overflow-x: auto; + background: #efefef; + padding: 0.625rem; + border-radius: 0.3125rem; +} +a { + color: #007d9c; + text-decoration: none; +} +a.anchor { + position: absolute; + z-index: 1001; + width: 1.5ex; + margin-left: -1.5ex; + display: block; + text-decoration: none !important; + visibility: hidden; + text-align: center; + font-weight: 400; +} +a.anchor:hover { + cursor: pointer; + outline: 0; + visibility: visible; +} +a.anchor::before { + content: "\00A7"; + font-size: 0.85em; + display: block; + padding-top: 0.1em; +} + +p, +li { + max-width: 50rem; + word-wrap: break-word; +} +p, +pre, +ul, +ol { + margin: 1.25rem; +} + +h1, +h2, +h3, +h4, +h5, +h6 { + margin: 1.25rem 0 1.25rem; + padding: 0.5rem 0.5rem 0.5rem 1.25rem; + color: #007d9c; + font-weight: bold; +} +h1 { + padding: 0.5rem 0; + font-size: 1.75rem; + line-height: 1; +} +h1 .text-muted { + color: #777; +} +h2 { + clear: right; + font-size: 1.25rem; + background: #e0ebf5; + line-height: 1.25; + font-weight: normal; + overflow: auto; + overflow-wrap: break-word; +} +h2 a { + font-weight: bold; +} +h3 { + font-size: 1.25rem; + line-height: 1.25; + overflow: auto; + overflow-wrap: break-word; +} +h3, +h4 { + margin: 1.25rem 0rem; +} +h4 { + font-size: 1rem; +} + +h2 > span, +h3 > span { + float: right; + margin: 0 25px 0 0; + font-weight: normal; + color: #5279c7; +} +h1:hover > a.anchor, +h2:hover > a.anchor, +h3:hover > a.anchor, +h4:hover > a.anchor, +h5:hover > a.anchor, +h6:hover > a.anchor { + visibility: visible; +} + +dl { + margin: 1.25rem; +} +dd { + margin: 0 0 0 1.25rem; +} +dd p { + margin: 0.5rem 0 1.25rem 1.25rem; +} +td p { + margin: 0 0 0 1.25rem; +} + +/** + * Custom classes for pages + */ + +.topbar { + background: #e0ebf5; + height: 4rem; + overflow: hidden; +} + +.topbar .top-heading, +.topbar .menu { + padding: 1.313rem 0; + font-size: 1.25rem; + font-weight: normal; +} +.topbar .top-heading { + float: left; +} +.topbar .top-heading a { + color: #222; + text-decoration: none; +} + +.top-heading .header-logo { + height: 2rem; + width: 5.125rem; +} + +.topbar .menu { + float: right; +} +.topbar .menu a { + margin: 0.625rem 0.125rem; + padding: 0.625rem; + color: white; + background: #007d9c; + border: 0.0625rem solid #007d9c; + border-radius: 5px; +} +.topbar .menu form { + display: inline-block; +} + +.page { + width: 100%; +} + +.page > .container, +.topbar > .container, +.footer > .container { + margin-left: auto; + margin-right: auto; + padding: 0 1.25rem; + max-width: 59.38rem; +} + +.page > .container { + text-align: left; +} + +.container .meta { + font-style: italic; + margin: 1.25rem; +} + +#footer { + display: none; +} +.footer { + text-align: center; + color: #666; + font-size: 0.875rem; + margin: 2.5rem 0; +} + +/** Custom classes for asciidoc */ +#toctitle { + display: none; +} +#toc li { + list-style: none; +} +#toc ul .sectlevel1 { + padding: 0px; + margin: 4px; +} +#toc ul .sectlevel2 { + margin: 4px; +} + +.admonitionblock { + margin: 0 auto; +} +.admonitionblock.note { + background-color: #e0ebf5; + border-radius: 0.5em; +} +.admonitionblock .icon { + border-right: 1px solid white; + font-weight: bold; + padding: 0.5em; + text-transform: uppercase; +} +.admonitionblock .content { + padding: 0.5em; +} +@media screen and (max-width: 992px) { + #toc { + all: unset; + } +} diff --git a/cmd/www-go-proposal/main.go b/cmd/www-go-proposal/main.go new file mode 100644 index 0000000..d319a16 --- /dev/null +++ b/cmd/www-go-proposal/main.go @@ -0,0 +1,38 @@ +// Copyright 2021, The golang-id.org Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package main + +import ( + "flag" + "log" + "os" + + "git.sr.ht/~shulhan/ciigo" + "github.com/shuLhan/share/lib/memfs" +) + +var memFS *memfs.MemFS + +func main() { + var port string + + flag.StringVar(&port, `port`, `5001`, `HTTP port server`) + flag.Parse() + + var serveOpts = &ciigo.ServeOptions{ + ConvertOptions: ciigo.ConvertOptions{ + Root: `.`, + Exclude: `(cmd|go.mod|go.sum)`, + HtmlTemplate: `html.tmpl`, + }, + Mfs: memFS, + Address: `0.0.0.0:` + port, + IsDevelopment: len(os.Getenv(`DEBUG`)) > 0, + } + var err = ciigo.Serve(serveOpts) + if err != nil { + log.Fatal(err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..527829b --- /dev/null +++ b/go.mod @@ -0,0 +1,21 @@ +module git.sr.ht/~shulhan/go-x-proposal + +go 1.19 + +require ( + git.sr.ht/~shulhan/ciigo v0.10.0 + github.com/shuLhan/share v0.46.0 +) + +require ( + git.sr.ht/~shulhan/asciidoctor-go v0.4.1 // indirect + github.com/yuin/goldmark v1.5.4 // indirect + github.com/yuin/goldmark-meta v1.1.0 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/sys v0.5.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) + +//replace github.com/shuLhan/share => ../share + +//replace git.sr.ht/~shulhan/ciigo => ../ciigo diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..abc150f --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +git.sr.ht/~shulhan/asciidoctor-go v0.4.1 h1:Zev0L5HyMjH43sPaoJal8E/Hmbel/akoGOxNykhN4Dw= +git.sr.ht/~shulhan/asciidoctor-go v0.4.1/go.mod h1:vRHDUl3o3UzDkvVR9dEFYQ0JDqOh0TKpOZWvOh/CGZU= +git.sr.ht/~shulhan/ciigo v0.10.0 h1:s1SJ3/NzBcbOLmEZ4z1Cx9Vf7ZdDIvm45b7KMCZKzEY= +git.sr.ht/~shulhan/ciigo v0.10.0/go.mod h1:cG6av+ywJZZp96F43kmLB2QWjm2hYiahbsbeTX/vlgk= +github.com/shuLhan/share v0.46.0 h1:cF0Ngj7wVA6TIcdSmfrqxOwMB3hZ+4df5cJf4GGCun4= +github.com/shuLhan/share v0.46.0/go.mod h1:BhnIWJxq84BTOs3Z2gLFAN8ih9mBfhZbRIjqGupGJag= +github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU= +github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= +github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/html.tmpl b/html.tmpl new file mode 100644 index 0000000..4ab5989 --- /dev/null +++ b/html.tmpl @@ -0,0 +1,73 @@ + + + + + + + + + + + {{.Title}} + + + {{- range .Styles}} + + {{- end}} + + + + + + +
+
+
+ + + +
+ +
+
+ +
+
+ {{.Body}} +
+ +
+ + + + + -- cgit v1.3