commit
message
Small clean up tasks, prepping for multi-repo generation
author
Ben Vogt <[email protected]>
date
2023-04-04 21:59:17
stats
2 file(s) changed,
3 insertions(+),
10 deletions(-)
files
Makefile
main.go
1diff --git a/Makefile b/Makefile
2index 3ebed4c..030420c 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -24,8 +24,7 @@ target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin: Makefile target $(wildcard *.go)
6
7 dev: Makefile target target/output target/cloning target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin
8 ./target/gshr-${OS}-${ARCH}-${ENVIRONMENT}.bin \
9- --name="gshr" \
10- --desc="git static host repo -- generates static html for repo" \
11+ --desc="git static host repo -- generates static html for repos" \
12 --repo=/Users/bvogt/dev/src/ben/gshr \
13 --git-url="[email protected]:vogtb/gshr.git" \
14 --output=$(PWD)/target/output \
15diff --git a/main.go b/main.go
16index 63f0888..ac1bef3 100644
17--- a/main.go
18+++ b/main.go
19@@ -11,7 +11,6 @@ import (
20 "os"
21 "path"
22
23- "github.com/alecthomas/chroma"
24 "github.com/alecthomas/chroma/formatters/html"
25 "github.com/alecthomas/chroma/lexers"
26 "github.com/alecthomas/chroma/styles"
27@@ -41,7 +40,6 @@ func Init() {
28 flag.StringVar(&config.CloneDir, "clone", "", "Dir to clone into. Default is /tmp/${rand}")
29 flag.StringVar(&config.RepoData.BaseURL, "base-url", "/", "Base URL for serving.")
30 flag.StringVar(&config.RepoData.GitURL, "git-url", "", "Show where repo is hosted.")
31- flag.StringVar(&config.RepoData.Name, "name", "untitled repo", "Name to show")
32 flag.StringVar(&config.RepoData.Description, "desc", "<no description>", "Description to show.")
33 flag.Parse()
34
35@@ -54,6 +52,7 @@ func Init() {
36 }
37
38 config.RepoData.BaseURL = path.Join(config.RepoData.BaseURL, "/")
39+ config.RepoData.Name = path.Clean(path.Base(config.Repo))
40
41 debug("repo = %v", config.Repo)
42 debug("output = %v", config.OutputDir)
43@@ -85,7 +84,7 @@ func debug(format string, a ...any) {
44 }
45 }
46
47-func syntaxHighlightTools(pathOrExtension string) (chroma.Lexer, *chroma.Style, *html.Formatter) {
48+func highlight(pathOrExtension string, data *string) string {
49 lexer := lexers.Match(pathOrExtension)
50 if lexer == nil {
51 lexer = lexers.Fallback
52@@ -99,11 +98,6 @@ func syntaxHighlightTools(pathOrExtension string) (chroma.Lexer, *chroma.Style,
53 html.WithLineNumbers(true),
54 html.LinkableLineNumbers(true, ""),
55 )
56- return lexer, style, formatter
57-}
58-
59-func highlight(pathOrExtension string, data *string) string {
60- lexer, style, formatter := syntaxHighlightTools(pathOrExtension)
61 iterator, err := lexer.Tokenise(nil, *data)
62 buf := bytes.NewBufferString("")
63 err = formatter.Format(buf, style, iterator)