Add styling
This commit is contained in:
parent
ee6c1c82cb
commit
5f75ba5c3e
13
github-fixup.css
Normal file
13
github-fixup.css
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
.markdown-body {
|
||||||
|
box-sizing: border-box;
|
||||||
|
min-width: 200px;
|
||||||
|
max-width: 980px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
.markdown-body {
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
}
|
1036
github-markdown.css
Normal file
1036
github-markdown.css
Normal file
File diff suppressed because it is too large
Load Diff
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.16
|
|||||||
require (
|
require (
|
||||||
github.com/FooSoft/goldsmith v0.0.0-20220410034610-83530f1b2fe4
|
github.com/FooSoft/goldsmith v0.0.0-20220410034610-83530f1b2fe4
|
||||||
github.com/FooSoft/goldsmith-components v0.0.0-20220410175545-c35ca9cfd9d4
|
github.com/FooSoft/goldsmith-components v0.0.0-20220410175545-c35ca9cfd9d4
|
||||||
|
github.com/PuerkitoBio/goquery v1.8.0
|
||||||
github.com/toqueteos/webbrowser v1.2.0
|
github.com/toqueteos/webbrowser v1.2.0
|
||||||
github.com/yuin/goldmark v1.4.12
|
github.com/yuin/goldmark v1.4.12
|
||||||
)
|
)
|
||||||
|
50
main.go
50
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -8,12 +9,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/FooSoft/goldsmith"
|
"github.com/FooSoft/goldsmith"
|
||||||
"github.com/FooSoft/goldsmith-components/devserver"
|
"github.com/FooSoft/goldsmith-components/devserver"
|
||||||
|
"github.com/FooSoft/goldsmith-components/plugins/document"
|
||||||
"github.com/FooSoft/goldsmith-components/plugins/livejs"
|
"github.com/FooSoft/goldsmith-components/plugins/livejs"
|
||||||
"github.com/FooSoft/goldsmith-components/plugins/markdown"
|
"github.com/FooSoft/goldsmith-components/plugins/markdown"
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/toqueteos/webbrowser"
|
"github.com/toqueteos/webbrowser"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
"github.com/yuin/goldmark/extension"
|
"github.com/yuin/goldmark/extension"
|
||||||
@ -21,11 +25,30 @@ import (
|
|||||||
"github.com/yuin/goldmark/renderer/html"
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed github-markdown.css
|
||||||
|
var githubStyle string
|
||||||
|
|
||||||
|
//go:embed github-fixup.css
|
||||||
|
var githubFixup string
|
||||||
|
|
||||||
type builder struct {
|
type builder struct {
|
||||||
port int
|
port int
|
||||||
browsing bool
|
browsing bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func embedCss(file *goldsmith.File, doc *goquery.Document) error {
|
||||||
|
var styleBuilder strings.Builder
|
||||||
|
styleBuilder.WriteString("<style type=\"text/css\">\n")
|
||||||
|
styleBuilder.WriteString(githubStyle)
|
||||||
|
styleBuilder.WriteString(githubFixup)
|
||||||
|
styleBuilder.WriteString("</style>")
|
||||||
|
|
||||||
|
doc.Find("body").AddClass("markdown-body")
|
||||||
|
doc.Find("head").SetHtml(styleBuilder.String())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *builder) Build(contentDir, buildDir, cacheDir string) {
|
func (self *builder) Build(contentDir, buildDir, cacheDir string) {
|
||||||
log.Print("building...")
|
log.Print("building...")
|
||||||
|
|
||||||
@ -39,6 +62,7 @@ func (self *builder) Build(contentDir, buildDir, cacheDir string) {
|
|||||||
Clean(true).
|
Clean(true).
|
||||||
Chain(markdown.NewWithGoldmark(gm)).
|
Chain(markdown.NewWithGoldmark(gm)).
|
||||||
Chain(livejs.New()).
|
Chain(livejs.New()).
|
||||||
|
Chain(document.New(embedCss)).
|
||||||
End(buildDir)
|
End(buildDir)
|
||||||
|
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
@ -60,11 +84,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestPath := flag.Arg(0)
|
requestPath := flag.Arg(0)
|
||||||
buildDir, err := ioutil.TempDir("", "mvd-*")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := os.Stat(requestPath)
|
info, err := os.Stat(requestPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -75,6 +94,18 @@ func main() {
|
|||||||
contentDir = filepath.Dir(requestPath)
|
contentDir = filepath.Dir(requestPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildDir, err := ioutil.TempDir("", "mvd-*")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
log.Println("cleaning up...")
|
||||||
|
if err := os.RemoveAll(buildDir); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
b := &builder{port: *port}
|
b := &builder{port: *port}
|
||||||
devserver.DevServe(b, *port, contentDir, buildDir, "")
|
devserver.DevServe(b, *port, contentDir, buildDir, "")
|
||||||
@ -83,12 +114,5 @@ func main() {
|
|||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
for {
|
<-sigs
|
||||||
<-sigs
|
|
||||||
log.Println("terminating...")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err := os.RemoveAll(buildDir); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user