mirror of https://github.com/jlelse/GoBlog
Remove libsass, add hooks which enable to use custom commands to generate css from scss, but much more, also less dependencies
This commit is contained in:
parent
9846cf2211
commit
5db4067caf
|
@ -10,6 +10,7 @@ type config struct {
|
|||
Cache *configCache `mapstructure:"cache"`
|
||||
Blog *configBlog `mapstructure:"blog"`
|
||||
User *configUser `mapstructure:"user"`
|
||||
Hooks *configHooks `mapstructure:"hooks"`
|
||||
Hugo *configHugo `mapstructure:"hugo"`
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,11 @@ type configUser struct {
|
|||
Password string `mapstructure:"password"`
|
||||
}
|
||||
|
||||
type configHooks struct {
|
||||
Shell string `mapstructure:"shell"`
|
||||
PreStart []string `mapstructure:"prestart"`
|
||||
}
|
||||
|
||||
type configHugo struct {
|
||||
Frontmatter []*frontmatter `mapstructure:"frontmatter"`
|
||||
}
|
||||
|
@ -116,6 +122,7 @@ func initConfig() error {
|
|||
viper.SetDefault("user.nick", "admin")
|
||||
viper.SetDefault("user.name", "Admin")
|
||||
viper.SetDefault("user.password", "secret")
|
||||
viper.SetDefault("hooks.shell", "/bin/bash")
|
||||
viper.SetDefault("hugo.frontmatter", []*frontmatter{{Meta: "title", Parameter: "title"}, {Meta: "tags", Parameter: "tags"}})
|
||||
// Unmarshal config
|
||||
err = viper.Unmarshal(appConfig)
|
||||
|
|
3
go.mod
3
go.mod
|
@ -6,15 +6,14 @@ require (
|
|||
github.com/PuerkitoBio/goquery v1.5.1
|
||||
github.com/andybalholm/cascadia v1.2.0 // indirect
|
||||
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1
|
||||
github.com/bep/golibsass v0.7.0
|
||||
github.com/caddyserver/certmagic v0.12.0
|
||||
github.com/frankban/quicktest v1.11.0 // indirect
|
||||
github.com/go-chi/chi v4.1.2+incompatible
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/jeremywohl/flatten v1.0.1
|
||||
github.com/jinzhu/gorm v1.9.16 // indirect
|
||||
github.com/klauspost/cpuid v1.3.1 // indirect
|
||||
github.com/kr/pretty v0.2.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/kyokomi/emoji v2.2.4+incompatible
|
||||
github.com/lib/pq v1.8.0 // indirect
|
||||
|
|
11
go.sum
11
go.sum
|
@ -30,8 +30,6 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
|
|||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/bep/golibsass v0.7.0 h1:/ocxgtPZ5rgp7FA+mktzyent+fAg82tJq4iMsTMBAtA=
|
||||
github.com/bep/golibsass v0.7.0/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/caddyserver/certmagic v0.12.0 h1:1f7kxykaJkOVVpXJ8ZrC6RAO5F6+kKm9U7dBFbLNeug=
|
||||
|
@ -56,10 +54,6 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
|||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/frankban/quicktest v1.7.2 h1:2QxQoC1TS09S7fhCPsrvqYdvP1H5M1P1ih5ABm3BTYk=
|
||||
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
|
||||
github.com/frankban/quicktest v1.11.0 h1:Yyrghcw93e1jKo4DTZkRFTTFvBsVhzbblBUPNU1vW6Q=
|
||||
github.com/frankban/quicktest v1.11.0/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
|
@ -92,10 +86,6 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
|
|||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
|
@ -436,7 +426,6 @@ golang.org/x/tools v0.0.0-20200918232735-d647fc253266 h1:k7tVuG0g1JwmD3Jh8oAl1vQ
|
|||
golang.org/x/tools v0.0.0-20200918232735-d647fc253266/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func preStartHooks() {
|
||||
for _, cmd := range appConfig.Hooks.PreStart {
|
||||
log.Println("Executing pre-start hook:", cmd)
|
||||
executeCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
func executeCommand(cmd string) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
parsed := exec.Command(appConfig.Hooks.Shell, "-c", cmd)
|
||||
parsed.Stdout = &stdout
|
||||
parsed.Stderr = &stderr
|
||||
cmdErr := parsed.Run()
|
||||
if cmdErr != nil {
|
||||
fmt.Println("Executing command failed:")
|
||||
fmt.Println(cmdErr.Error())
|
||||
}
|
||||
if stdout.Len() > 0 {
|
||||
log.Println("Output:")
|
||||
log.Print(stdout.String())
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
log.Println("Error:")
|
||||
log.Print(stderr.String())
|
||||
}
|
||||
}
|
11
main.go
11
main.go
|
@ -7,17 +7,22 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// Initialize all things
|
||||
log.Println("Initializing...")
|
||||
// Initialize config
|
||||
log.Println("Initialize configuration...")
|
||||
err := initConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// Execute pre-start hooks
|
||||
preStartHooks()
|
||||
// Initialize everything else
|
||||
log.Println("Initialize database...")
|
||||
err = initDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
log.Println("Initialize server components...")
|
||||
initMinify()
|
||||
err = initTemplateAssets() // Needs minify
|
||||
if err != nil {
|
||||
|
@ -36,7 +41,7 @@ func main() {
|
|||
|
||||
// Start the server
|
||||
go func() {
|
||||
log.Println("Starting...")
|
||||
log.Println("Starting server...")
|
||||
err = startServer()
|
||||
if err != nil {
|
||||
log.Println("Failed to start server:")
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"github.com/bep/golibsass/libsass"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -61,20 +60,6 @@ func compileAssets(name string) (compiledFileName string, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
case ".scss":
|
||||
transpiler, err := libsass.New(libsass.Options{OutputStyle: libsass.CompressedStyle})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
result, err := transpiler.Execute(string(originalContent))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
compiledContent, err = minifier.Bytes("text/css", []byte(result.CSS))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
compiledExt = ".css"
|
||||
default:
|
||||
// Just copy the file
|
||||
compiledContent = originalContent
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
.sans-serif, input, textarea, button, .button, body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
html {
|
||||
--background: #fff;
|
||||
--primary: #000;
|
||||
color: #000;
|
||||
scrollbar-color: var(--primary) transparent;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html {
|
||||
--background: #000;
|
||||
--primary: #fff;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: #fff;
|
||||
background: var(--background, #fff);
|
||||
line-height: 1.5;
|
||||
margin: 0 auto;
|
||||
max-width: 700px;
|
||||
padding: 10px;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
body * {
|
||||
color: #000;
|
||||
color: var(--primary, #000);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
header {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
header * {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
h1 a, h2 a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
input, textarea, button, .button {
|
||||
border: 1px solid #000;
|
||||
border: 1px solid var(--primary, #000);
|
||||
background: #fff;
|
||||
background: var(--background, #fff);
|
||||
color: #000;
|
||||
color: var(--primary, #000);
|
||||
padding: 5px 10px;
|
||||
border-radius: 0;
|
||||
box-sizing: border-box;
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border-left: 5px solid #000;
|
||||
border-left: 5px solid var(--primary, #000);
|
||||
padding-left: 20px;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 10px;
|
||||
border: 1px solid #000;
|
||||
border: 1px solid var(--primary, #000);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
:not(pre) > code {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
footer {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
footer * {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.border-top, footer {
|
||||
border-top: 1px solid #000;
|
||||
border-top: 1px solid var(--primary, #000);
|
||||
}
|
||||
|
||||
.border-bottom, header {
|
||||
border-bottom: 1px solid #000;
|
||||
border-bottom: 1px solid var(--primary, #000);
|
||||
}
|
||||
|
||||
.invert, :not(pre) > code {
|
||||
color: #fff;
|
||||
color: var(--background, #fff);
|
||||
background: #000;
|
||||
background: var(--primary, #000);
|
||||
}
|
||||
|
||||
.p {
|
||||
display: block;
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.fw, .fw-form, .fw-form input[type=text], .fw-form input[type=email], .fw-form textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ct {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Twemoji */
|
||||
img.emoji {
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
margin: 0 0.05em 0 0.1em;
|
||||
vertical-align: -0.1em;
|
||||
}
|
||||
|
||||
/* Print */
|
||||
@media print {
|
||||
html {
|
||||
--background: #fff;
|
||||
--primary: #000;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: serif;
|
||||
max-width: inherit;
|
||||
}
|
||||
|
||||
nav,
|
||||
#post-actions,
|
||||
#related,
|
||||
#interactions {
|
||||
display: none;
|
||||
}
|
||||
}
|
|
@ -4,12 +4,8 @@
|
|||
<meta charset=utf-8>
|
||||
<meta name=viewport content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv=x-ua-compatible content="IE=edge">
|
||||
<link rel="stylesheet" href="{{ asset "css/style.scss" }}">
|
||||
<link rel="stylesheet" href="{{ asset "css/styles.css" }}">
|
||||
{{ template "title" . }}
|
||||
<header>
|
||||
<h1><a href="/" rel="home" title="{{ blog.Title }}">{{ blog.Title }}</a></h1>
|
||||
{{ with blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
|
||||
{{ include "menu" . }}
|
||||
</header>
|
||||
{{ include "header" . }}
|
||||
{{ template "main" . }}
|
||||
{{ end }}
|
|
@ -0,0 +1,7 @@
|
|||
{{ define "header" }}
|
||||
<header>
|
||||
<h1><a href="/" rel="home" title="{{ blog.Title }}">{{ blog.Title }}</a></h1>
|
||||
{{ with blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
|
||||
{{ include "menu" . }}
|
||||
</header>
|
||||
{{ end }}
|
Loading…
Reference in New Issue