parent
447c88febe
commit
1a5693062f
17
.drone.yml
17
.drone.yml
|
@ -1,17 +0,0 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: compliance
|
||||
trigger:
|
||||
event:
|
||||
- pull_request
|
||||
steps:
|
||||
- name: test
|
||||
pull: always
|
||||
image: golang:1.17
|
||||
commands:
|
||||
- go test -race ./...
|
||||
- name: vet
|
||||
pull: always
|
||||
image: golang:1.17
|
||||
commands:
|
||||
- go vet -race ./...
|
|
@ -0,0 +1,23 @@
|
|||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
archives:
|
||||
- replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
release:
|
||||
gitea:
|
||||
owner: jolheiser
|
||||
name: blog
|
||||
gitea_urls:
|
||||
api: https://git.jojodev.com/api/v1/
|
||||
download: https://git.jojodev.com
|
|
@ -0,0 +1,39 @@
|
|||
clone:
|
||||
git:
|
||||
image: woodpeckerci/plugin-git
|
||||
settings:
|
||||
tags: true
|
||||
|
||||
pipeline:
|
||||
compliance:
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go test -race ./...
|
||||
- go vet ./...
|
||||
- go run github.com/rs/zerolog/cmd/lint@latest go.jolheiser.com/blog
|
||||
when:
|
||||
event: pull_request
|
||||
|
||||
build:
|
||||
image: goreleaser/goreleaser
|
||||
commands:
|
||||
- goreleaser build --snapshot
|
||||
when:
|
||||
event: pull_request
|
||||
|
||||
release:
|
||||
image: goreleaser/goreleaser
|
||||
commands:
|
||||
- goreleaser release
|
||||
secrets: [ gitea_token ]
|
||||
when:
|
||||
event: tag
|
||||
|
||||
prune:
|
||||
image: jolheiser/drone-gitea-prune
|
||||
settings:
|
||||
base: https://git.jojodev.com
|
||||
token:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
event: tag
|
|
@ -1,75 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goyek/goyek"
|
||||
)
|
||||
|
||||
const zerologLintVer = "1.24.0"
|
||||
|
||||
func main() {
|
||||
flow().Main()
|
||||
}
|
||||
|
||||
func flow() *goyek.Flow {
|
||||
flow := &goyek.Flow{}
|
||||
|
||||
fmt := flow.Register(taskFmt)
|
||||
test := flow.Register(taskTest)
|
||||
vet := flow.Register(taskVet)
|
||||
lint := flow.Register(taskLint)
|
||||
|
||||
flow.DefaultTask = flow.Register(goyek.Task{
|
||||
Name: "all",
|
||||
Usage: "Run all flows",
|
||||
Deps: []goyek.RegisteredTask{
|
||||
fmt,
|
||||
lint,
|
||||
test,
|
||||
vet,
|
||||
},
|
||||
})
|
||||
|
||||
return flow
|
||||
}
|
||||
|
||||
var taskFmt = goyek.Task{
|
||||
Name: "fmt",
|
||||
Usage: "go fmt",
|
||||
Action: func(tf *goyek.TF) {
|
||||
if err := tf.Cmd("go", "fmt", "./...").Run(); err != nil {
|
||||
tf.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var taskTest = goyek.Task{
|
||||
Name: "test",
|
||||
Usage: "go test",
|
||||
Action: func(tf *goyek.TF) {
|
||||
if err := tf.Cmd("go", "test", "-race", "./...").Run(); err != nil {
|
||||
tf.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var taskVet = goyek.Task{
|
||||
Name: "vet",
|
||||
Usage: "go vet",
|
||||
Action: func(tf *goyek.TF) {
|
||||
if err := tf.Cmd("go", "vet", "-race", "./...").Run(); err != nil {
|
||||
tf.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var taskLint = goyek.Task{
|
||||
Name: "lint",
|
||||
Usage: "Run linter(s)",
|
||||
Action: func(tf *goyek.TF) {
|
||||
if err := tf.Cmd("go", "run", fmt.Sprintf("github.com/rs/zerolog/cmd/lint@v%s", zerologLintVer), ".").Run(); err != nil {
|
||||
tf.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
9
go.mod
9
go.mod
|
@ -3,19 +3,16 @@ module go.jolheiser.com/blog
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/alecthomas/chroma v0.7.2-0.20200305040604-4f3623dce67a
|
||||
github.com/alecthomas/chroma v0.10.0
|
||||
github.com/go-chi/chi/v5 v5.0.4
|
||||
github.com/goyek/goyek v0.6.0
|
||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.3
|
||||
github.com/peterbourgon/ff/v3 v3.1.0
|
||||
github.com/rs/zerolog v1.24.0
|
||||
github.com/yuin/goldmark v1.4.0
|
||||
github.com/yuin/goldmark-emoji v1.0.1
|
||||
github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01
|
||||
go.jolheiser.com/chroma-catppuccin v0.0.2
|
||||
go.jolheiser.com/emdbed v0.0.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
|
||||
github.com/dlclark/regexp2 v1.2.0 // indirect
|
||||
)
|
||||
require github.com/dlclark/regexp2 v1.4.0 // indirect
|
||||
|
|
20
go.sum
20
go.sum
|
@ -1,31 +1,28 @@
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
|
||||
github.com/alecthomas/chroma v0.7.2-0.20200305040604-4f3623dce67a h1:3v1NrYWWqp2S72e4HLgxKt83B3l0lnORDholH/ihoMM=
|
||||
github.com/alecthomas/chroma v0.7.2-0.20200305040604-4f3623dce67a/go.mod h1:fv5SzZPFJbwp2NXJWpFIX7DZS4HgV1K4ew4Pc2OZD9s=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo=
|
||||
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
|
||||
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
|
||||
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
||||
github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
|
||||
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
|
||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk=
|
||||
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
|
||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/go-chi/chi/v5 v5.0.4 h1:5e494iHzsYBiyXQAHHuI4tyJS9M3V84OuX3ufIIGHFo=
|
||||
github.com/go-chi/chi/v5 v5.0.4/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/goyek/goyek v0.6.0 h1:2YQ4V3X7q+zFF98IBWMc1WRwfzs0TQ8jrwOKY3XRQRk=
|
||||
github.com/goyek/goyek v0.6.0/go.mod h1:UGjZz3juJL2l2eMqRbxQYjG8ieyKb7WMYPv0KB0KVxA=
|
||||
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
|
||||
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=
|
||||
|
@ -41,11 +38,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.24.0 h1:76ivFxmVSRs1u2wUwJVg5VZDYQgeH1JpoS6ndgr9Wy8=
|
||||
github.com/rs/zerolog v1.24.0/go.mod h1:7KHcEGe0QZPOm2IE4Kpb5rTh6n1h2hIgS5OOnu1rUaI=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU=
|
||||
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
@ -57,6 +54,8 @@ github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18W
|
|||
github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ=
|
||||
github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01 h1:0SJnXjE4jDClMW6grE0xpNhwpqbPwkBTn8zpVw5C0SI=
|
||||
github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01/go.mod h1:TwKQPa5XkCCRC2GRZ5wtfNUTQ2+9/i19mGRijFeJ4BE=
|
||||
go.jolheiser.com/chroma-catppuccin v0.0.2 h1:s5iK/XgmeagVGnq/3ybaxccDxZf4ohrkzAUFANQK3wA=
|
||||
go.jolheiser.com/chroma-catppuccin v0.0.2/go.mod h1:eHY2bDa7Zryc+2Q9f51YUNUSZGQUl3tOU8lJdsZCViA=
|
||||
go.jolheiser.com/emdbed v0.0.2 h1:nFxYD7VOlsp9Mv0nKnWe8Zj9n43yLJU5Yge/Va7my1E=
|
||||
go.jolheiser.com/emdbed v0.0.2/go.mod h1:8ReMCKEDv6UT89SqYZ+wzbPTGs3xNuX8q2RAsmSSG1M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -72,7 +71,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
1
main.go
1
main.go
|
@ -41,6 +41,7 @@ func main() {
|
|||
|
||||
r := router.New(b)
|
||||
go func() {
|
||||
log.Info().Msgf("Listening at http://localhost:%d", *port)
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), r); err != nil {
|
||||
log.Error().Err(err).Msg("could not open server")
|
||||
}
|
||||
|
|
|
@ -11,13 +11,14 @@ import (
|
|||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
_ "go.jolheiser.com/chroma-catppuccin/chroma1"
|
||||
)
|
||||
|
||||
var gm = goldmark.New(
|
||||
goldmark.WithExtensions(
|
||||
extension.GFM,
|
||||
highlighting.NewHighlighting(
|
||||
highlighting.WithStyle("monokai"),
|
||||
highlighting.WithStyle("catppuccin"),
|
||||
highlighting.WithFormatOptions(
|
||||
chromahtml.WithLineNumbers(true),
|
||||
chromahtml.LinkableLineNumbers(true, "code-"),
|
||||
|
|
69
post/post.go
69
post/post.go
|
@ -1,29 +1,32 @@
|
|||
package post
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.jolheiser.com/blog/markdown"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.jolheiser.com/emdbed"
|
||||
)
|
||||
|
||||
func NewBlog(basePath string) (*Blog, error) {
|
||||
posts, err := Scan(basePath)
|
||||
posts, err := scan(basePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Blog{
|
||||
Path: basePath,
|
||||
Posts: posts,
|
||||
posts: posts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Scan(basePath string) (map[string]*Post, error) {
|
||||
func scan(basePath string) (map[string]*Post, error) {
|
||||
posts := make(map[string]*Post)
|
||||
ents, err := os.ReadDir(basePath)
|
||||
if err != nil {
|
||||
|
@ -55,22 +58,40 @@ func Scan(basePath string) (map[string]*Post, error) {
|
|||
continue
|
||||
}
|
||||
posts[post.Slug] = post
|
||||
|
||||
if err := fi.Close(); err != nil {
|
||||
log.Error().Err(err).Msg("could not close file")
|
||||
continue
|
||||
}
|
||||
|
||||
if err := post.Load(); err != nil {
|
||||
log.Err(err).Msg("could not load post")
|
||||
continue
|
||||
}
|
||||
}
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
type Blog struct {
|
||||
Path string
|
||||
Posts map[string]*Post
|
||||
posts map[string]*Post
|
||||
mx sync.RWMutex
|
||||
}
|
||||
|
||||
func (b *Blog) Scan() error {
|
||||
posts, err := scan(b.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.mx.Lock()
|
||||
defer b.mx.Unlock()
|
||||
b.posts = posts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Blog) SortedPosts() []*Post {
|
||||
posts := make([]*Post, 0, len(b.Posts))
|
||||
for _, post := range b.Posts {
|
||||
posts := make([]*Post, 0, len(b.posts))
|
||||
for _, post := range b.posts {
|
||||
posts = append(posts, post)
|
||||
}
|
||||
sort.Slice(posts, func(i, j int) bool {
|
||||
|
@ -79,11 +100,47 @@ func (b *Blog) SortedPosts() []*Post {
|
|||
return posts
|
||||
}
|
||||
|
||||
func (b *Blog) Post(name string) (*Post, bool) {
|
||||
b.mx.RLock()
|
||||
defer b.mx.RUnlock()
|
||||
if post, ok := b.posts[name]; ok {
|
||||
return post, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
Path string `toml:"-"`
|
||||
Slug string `toml:"-"`
|
||||
Content template.HTML `toml:"-"`
|
||||
Title string `toml:"title"`
|
||||
Author string `toml:"author"`
|
||||
Date time.Time `toml:"date"`
|
||||
Tags []string `toml:"tags"`
|
||||
}
|
||||
|
||||
func (p *Post) Load() error {
|
||||
fi, err := os.Open(p.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
|
||||
mdContent, err := markdown.Content(fi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
emdbedContent, err := emdbed.Convert(filepath.Dir(p.Path), strings.NewReader(mdContent))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
md, err := markdown.Convert(strings.NewReader(emdbedContent))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.Content = template.HTML(md)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.jolheiser.com/emdbed"
|
||||
|
||||
"go.jolheiser.com/blog/markdown"
|
||||
"go.jolheiser.com/blog/post"
|
||||
"go.jolheiser.com/blog/static"
|
||||
|
||||
|
@ -26,7 +20,10 @@ func New(blog *post.Blog) *chi.Mux {
|
|||
|
||||
m.Get("/", indexHandler(blog))
|
||||
m.Get("/{post}", fileHandler(blog))
|
||||
m.Get("/sakura.css", static.SakuraCSS)
|
||||
m.Route("/_", func(r chi.Router) {
|
||||
r.Get("/reload", reloadHandler(blog))
|
||||
r.Get("/sakura.css", static.SakuraCSS)
|
||||
})
|
||||
|
||||
return m
|
||||
}
|
||||
|
@ -44,45 +41,38 @@ func indexHandler(blog *post.Blog) http.HandlerFunc {
|
|||
func fileHandler(blog *post.Blog) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
postName := chi.URLParam(r, "post")
|
||||
p, ok := blog.Posts[postName]
|
||||
p, ok := blog.Post(postName)
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fi, err := os.Open(p.Path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not open post")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer fi.Close()
|
||||
|
||||
mdContent, err := markdown.Content(fi)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not get content")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
emdbedContent, err := emdbed.Convert(filepath.Dir(p.Path), strings.NewReader(mdContent))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not emdbed")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
md, err := markdown.Convert(strings.NewReader(emdbedContent))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not convert")
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := static.PostTemplate.Execute(w, map[string]interface{}{
|
||||
"Post": p,
|
||||
"Content": template.HTML(md),
|
||||
}); err != nil {
|
||||
log.Error().Err(err).Msg("could not execute template")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func reloadHandler(blog *post.Blog) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil || !ip.IsLoopback() {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Msg("reloading posts")
|
||||
if err := blog.Scan(); err != nil {
|
||||
http.Error(w, "could not re-scan", http.StatusInternalServerError)
|
||||
log.Error().Err(err).Msg("could not re-scan")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>Blog</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" href="sakura.css"/>
|
||||
<link rel="stylesheet" href="_/sakura.css"/>
|
||||
<style>
|
||||
.tag {
|
||||
font-size: .7em;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>{{.Post.Title}}</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" href="sakura.css"/>
|
||||
<link rel="stylesheet" href="_/sakura.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a style="position: absolute; left: 1em;" href="../">Index</a>
|
||||
{{.Content}}
|
||||
<a style="position: absolute; left: 1em;" href="../../">Index</a>
|
||||
{{.Post.Content}}
|
||||
</body>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
|
|
@ -26,24 +26,30 @@
|
|||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; }
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 1.8rem;
|
||||
line-height: 1.618;
|
||||
max-width: 50%;
|
||||
max-width: 38em;
|
||||
margin: auto;
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-bg);
|
||||
padding: 13px; }
|
||||
padding: 13px;
|
||||
}
|
||||
|
||||
@media (max-width: 684px) {
|
||||
body {
|
||||
font-size: 1.53rem; } }
|
||||
font-size: 1.53rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 382px) {
|
||||
body {
|
||||
font-size: 1.35rem; } }
|
||||
font-size: 1.35rem;
|
||||
}
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
line-height: 1.1;
|
||||
|
@ -54,52 +60,69 @@ h1, h2, h3, h4, h5, h6 {
|
|||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
-ms-word-break: break-all;
|
||||
word-break: break-word; }
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.35em; }
|
||||
font-size: 2.35em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2.00em; }
|
||||
font-size: 2.00em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.75em; }
|
||||
font-size: 1.75em;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 1.5em; }
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
h5 {
|
||||
font-size: 1.25em; }
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
h6 {
|
||||
font-size: 1em; }
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 2.5rem; }
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
small, sub, sup {
|
||||
font-size: 75%; }
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
hr {
|
||||
border-color: var(--color-blossom); }
|
||||
border-color: var(--color-blossom);
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: var(--color-blossom); }
|
||||
color: var(--color-blossom);
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--color-fade);
|
||||
border-bottom: 2px solid var(--color-text); }
|
||||
border-bottom: 2px solid var(--color-text);
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: var(--color-blossom); }
|
||||
color: var(--color-blossom);
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 1.4em;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 2.5rem; }
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 0.4em; }
|
||||
margin-bottom: 0.4em;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin-left: 0px;
|
||||
|
@ -110,16 +133,19 @@ blockquote {
|
|||
padding-right: 0.8em;
|
||||
border-left: 5px solid var(--color-blossom);
|
||||
margin-bottom: 2.5rem;
|
||||
background-color: var(--color-bg-alt); }
|
||||
background-color: var(--color-bg-alt);
|
||||
}
|
||||
|
||||
blockquote p {
|
||||
margin-bottom: 0; }
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
img, video {
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 2.5rem; }
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
/* Pre and Code */
|
||||
pre {
|
||||
|
@ -128,37 +154,46 @@ pre {
|
|||
padding: 1em;
|
||||
overflow-x: auto;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 2.5rem; }
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 0.9em;
|
||||
padding: 0 0.5em;
|
||||
background-color: var(--color-bg-alt);
|
||||
white-space: pre-wrap; }
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
pre > code {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
white-space: pre; }
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
table {
|
||||
text-align: justify;
|
||||
width: 100%;
|
||||
border-collapse: collapse; }
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
td, th {
|
||||
padding: 0.5em;
|
||||
border-bottom: 1px solid var(--color-bg-alt); }
|
||||
border-bottom: 1px solid var(--color-bg-alt);
|
||||
}
|
||||
|
||||
/* Buttons, forms and input */
|
||||
input, textarea {
|
||||
border: 1px solid var(--color-text); }
|
||||
border: 1px solid var(--color-text);
|
||||
}
|
||||
|
||||
input:focus, textarea:focus {
|
||||
border: 1px solid var(--color-blossom); }
|
||||
border: 1px solid var(--color-blossom);
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%; }
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.button, button, input[type="submit"], input[type="reset"], input[type="button"] {
|
||||
display: inline-block;
|
||||
|
@ -171,15 +206,20 @@ textarea {
|
|||
border-radius: 1px;
|
||||
border: 1px solid var(--color-blossom);
|
||||
cursor: pointer;
|
||||
box-sizing: border-box; }
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] {
|
||||
cursor: default;
|
||||
opacity: .5; }
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.button:focus:enabled, .button:hover:enabled, button:focus:enabled, button:hover:enabled, input[type="submit"]:focus:enabled, input[type="submit"]:hover:enabled, input[type="reset"]:focus:enabled, input[type="reset"]:hover:enabled, input[type="button"]:focus:enabled, input[type="button"]:hover:enabled {
|
||||
background-color: var(--color-fade);
|
||||
border-color: var(--color-fade);
|
||||
color: var(--color-bg);
|
||||
outline: 0; }
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
textarea, select, input {
|
||||
color: var(--color-text);
|
||||
|
@ -187,18 +227,23 @@ textarea, select, input {
|
|||
/* The 6px vertically centers text on FF, ignored by Webkit */
|
||||
margin-bottom: 10px;
|
||||
background-color: var(--color-bg-alt);
|
||||
border: 1px solid var(--color-bg-alt );
|
||||
border: 1px solid var(--color-bg-alt);
|
||||
border-radius: 4px;
|
||||
box-shadow: none;
|
||||
box-sizing: border-box; }
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
textarea:focus, select:focus, input:focus {
|
||||
border: 1px solid var(--color-blossom);
|
||||
outline: 0; }
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
input[type="checkbox"]:focus {
|
||||
outline: 1px dotted var(--color-blossom); }
|
||||
outline: 1px dotted var(--color-blossom);
|
||||
}
|
||||
|
||||
label, legend, fieldset {
|
||||
display: block;
|
||||
margin-bottom: .5rem;
|
||||
font-weight: 600; }
|
||||
font-weight: 600;
|
||||
}
|
Loading…
Reference in New Issue