Skip to content

Commit cdca8c4

Browse files
committed
feat: better theme support
1 parent 01c88ba commit cdca8c4

File tree

9 files changed

+77
-223
lines changed

9 files changed

+77
-223
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static: build clean
2828
--desc "static site generator for git" \
2929
--clone-url "https://github.com/picosh/pgit.git" \
3030
--home-url "https://git.erock.io" \
31-
--theme "algol" \
31+
--theme "dracula" \
3232
--revs main
3333
.PHONY:
3434

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ To learn more about the options run:
2323
./pgit --help
2424
```
2525

26+
## themes
27+
28+
We support all [chroma](https://xyproto.github.io/splash/docs/all.html) themes.
29+
We do our best to adapt the theme of the entire site to match the chroma syntax
30+
highlighting theme. This is a "closet approximation" as we are not testing every
31+
single theme.
32+
33+
```bash
34+
./pgit --revs main --label pico --out ./public --theme onedark
35+
```
36+
37+
The default theme is `dracula`. If you want to change the colors for your site,
38+
we generate a `vars.css` file that you are welcome to overwrite before
39+
deploying, it will _not_ change the syntax highlighting colors, only the main
40+
site colors.
41+
2642
# inspiration
2743

2844
This project was heavily inspired by

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/picosh/pgit
33
go 1.18
44

55
require (
6-
github.com/alecthomas/chroma v0.10.0
6+
github.com/alecthomas/chroma/v2 v2.13.0
77
github.com/dustin/go-humanize v1.0.0
88
github.com/gogs/git-module v1.6.0
99
)
1010

1111
require (
12-
github.com/dlclark/regexp2 v1.7.0 // indirect
12+
github.com/dlclark/regexp2 v1.11.0 // indirect
1313
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 // indirect
1414
github.com/stretchr/testify v1.8.1 // indirect
1515
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect

go.sum

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
2-
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
1+
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
2+
github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI=
3+
github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk=
4+
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
46
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
57
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
7-
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
8-
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
8+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
9+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
910
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
1011
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
1112
github.com/gogs/git-module v1.6.0 h1:71GdRM9/pFxGgSUz8t2DKmm3RYuHUnTjsOuFInJXnkM=
1213
github.com/gogs/git-module v1.6.0/go.mod h1:8jFYhDxLUwEOhM2709l2CJXmoIIslobU1xszpT0NcAI=
14+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
1315
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 h1:Pijfgr7ZuvX7QIQiEwLdRVr3RoMG+i0SbBO1Qu+7yVk=
1416
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
1517
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -18,7 +20,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
1820
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
1921
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
2022
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
21-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2223
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2324
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
2425
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=

html/base.layout.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
{{template "meta" .}}
1212

13+
<link rel="stylesheet" href="/vars.css" />
1314
<link rel="stylesheet" href="/smol.css" />
1415
<link rel="stylesheet" href="/main.css" />
1516
</head>

html/log.page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<div class="flex items-center gap-xs">
2828
<span>{{.AuthorStr}}</span>
29-
<span>&centerdot;</span>
29+
<span>&nbsp;&centerdot;&nbsp;</span>
3030
<span>{{.WhenStr}}</span>
3131
</div>
3232

main.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"sync"
1717
"unicode/utf8"
1818

19-
"github.com/alecthomas/chroma"
20-
formatterHtml "github.com/alecthomas/chroma/formatters/html"
21-
"github.com/alecthomas/chroma/lexers"
22-
"github.com/alecthomas/chroma/styles"
19+
"github.com/alecthomas/chroma/v2"
20+
formatterHtml "github.com/alecthomas/chroma/v2/formatters/html"
21+
"github.com/alecthomas/chroma/v2/lexers"
22+
"github.com/alecthomas/chroma/v2/styles"
2323
"github.com/dustin/go-humanize"
2424
git "github.com/gogs/git-module"
2525
)
@@ -1008,6 +1008,30 @@ func (c *Config) writeRevision(repo *git.Repository, pageData *PageData, refs []
10081008
return output
10091009
}
10101010

1011+
func style(theme chroma.Style) string {
1012+
bg := theme.Get(chroma.Background)
1013+
txt := theme.Get(chroma.Text)
1014+
kw := theme.Get(chroma.Keyword)
1015+
nv := theme.Get(chroma.NameVariable)
1016+
cm := theme.Get(chroma.Comment)
1017+
ln := theme.Get(chroma.LiteralNumber)
1018+
return fmt.Sprintf(`:root {
1019+
--bg-color: %s;
1020+
--text-color: %s;
1021+
--border: %s;
1022+
--link-color: %s;
1023+
--hover: %s;
1024+
--visited: %s;
1025+
}`,
1026+
bg.Background.String(),
1027+
txt.Colour.String(),
1028+
cm.Colour.String(),
1029+
nv.Colour.String(),
1030+
kw.Colour.String(),
1031+
ln.Colour.String(),
1032+
)
1033+
}
1034+
10111035
func main() {
10121036
var outdir = flag.String("out", "./public", "output directory")
10131037
var rpath = flag.String("repo", ".", "path to git repo")
@@ -1043,7 +1067,7 @@ func main() {
10431067

10441068
formatter := formatterHtml.New(
10451069
formatterHtml.WithLineNumbers(true),
1046-
formatterHtml.LinkableLineNumbers(true, ""),
1070+
formatterHtml.WithLinkableLineNumbers(true, ""),
10471071
formatterHtml.WithClasses(true),
10481072
)
10491073

@@ -1071,6 +1095,13 @@ func main() {
10711095
config.writeRepo()
10721096
config.copyStatic("static")
10731097

1098+
styles := style(*theme)
1099+
fmt.Println(styles)
1100+
err = os.WriteFile(filepath.Join(out, "vars.css"), []byte(styles), 0644)
1101+
if err != nil {
1102+
panic(err)
1103+
}
1104+
10741105
fp := filepath.Join(out, "syntax.css")
10751106
w, err := os.OpenFile(fp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
10761107
if err != nil {

static/main.css

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
pre {
2+
border: 1px solid var(--border);
3+
}
4+
5+
body {
6+
max-width: 900px;
7+
}
8+
19
.border-b {
2-
border-bottom: 1px solid var(--grey);
10+
border-bottom: 1px solid var(--border);
311
}
412

513
.border-b:last-child {
614
border-bottom: 0;
715
}
816

9-
body {
10-
max-width: 900px;
11-
}
12-
1317
.box {
1418
margin: 1rem 0;
1519
}
@@ -24,7 +28,7 @@ body {
2428
}
2529

2630
.tree-row:hover {
27-
background-color: var(--grey);
31+
background-color: var(--border);
2832
}
2933

3034
@media only screen and (max-width: 900px) {

0 commit comments

Comments
 (0)