From: Sergey Matveev Date: Sun, 30 Jul 2023 11:11:24 +0000 (+0300) Subject: Images in gopher/gemini X-Git-Tag: v0.29.0^0 X-Git-Url: http://www.git.stargrave.org/?p=sgblog.git;a=commitdiff_plain;h=fb473fd627f8b146f56e69548998f870ce8f6976 Images in gopher/gemini --- diff --git a/cmd/sgblog/gemini-entry.tmpl b/cmd/sgblog/gemini-entry.tmpl index 4e234fc..67d6fc4 100644 --- a/cmd/sgblog/gemini-entry.tmpl +++ b/cmd/sgblog/gemini-entry.tmpl @@ -1,4 +1,4 @@ -{{$CR := printf "\r"}}20 text/gemini{{$CR}} +{{$Cfg := .Cfg -}}{{$CR := printf "\r"}}20 text/gemini{{$CR}} # {{.Title}} {{$.T.Get "What"}}: {{.Commit.Hash.String}} {{$.T.Get "When"}}: {{.When}} @@ -11,6 +11,10 @@ {{.Note}} ``` {{end -}} +{{- if .Images}} +{{range $idx, $img := .Images}}=> http://{{$Cfg.ImgDomain}}/{{$img.Path}} {{$img.Alt}} +{{end}} +{{end -}} {{- if .Cfg.CommentsEmail}} => mailto:{{.Cfg.CommentsEmail}}?subject={{.TitleEscaped}} {{$.T.Get "leave a comment"}} {{end}}{{range $idx, $comment := .Comments}} diff --git a/cmd/sgblog/gemini-menu.tmpl b/cmd/sgblog/gemini-menu.tmpl index 756b79c..94c4790 100644 --- a/cmd/sgblog/gemini-menu.tmpl +++ b/cmd/sgblog/gemini-menu.tmpl @@ -9,7 +9,7 @@ {{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}} {{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}}## {{$dateCur}} {{end -}} -=> /{{.Commit.Hash.String}} [{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}} +=> /{{.Commit.Hash.String}} [{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .ImagesNum}} ({{.}}I){{end}}{{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}} {{end}} {{range .Topics -}}=> /?topic={{.}} Topic: {{.}} diff --git a/cmd/sgblog/gemini.go b/cmd/sgblog/gemini.go index 1b1131b..527874e 100644 --- a/cmd/sgblog/gemini.go +++ b/cmd/sgblog/gemini.go @@ -131,9 +131,10 @@ func serveGemini(cfgPath string) { } lines := msgSplit(commit.Message) entries = append(entries, TableMenuEntry{ - Commit: commit, - Title: lines[0], - LinesNum: len(lines) - 2, + Commit: commit, + Title: lines[0], + LinesNum: len(lines) - 2, + ImagesNum: len(listImgs(cfg, commit.Hash)), CommentsNum: len(sgblog.ParseComments(sgblog.GetNote( repo, commentsTree, commit.Hash, ))), @@ -185,6 +186,7 @@ func serveGemini(cfgPath string) { When string Cfg *Cfg Note string + Images []Img Comments []string Topics []string Version string @@ -196,6 +198,7 @@ func serveGemini(cfgPath string) { When: commit.Author.When.Format(sgblog.WhenFmt), Cfg: cfg, Note: string(sgblog.GetNote(repo, notesTree, commit.Hash)), + Images: listImgs(cfg, commit.Hash), Comments: sgblog.ParseComments(sgblog.GetNote(repo, commentsTree, commit.Hash)), Topics: sgblog.ParseTopics(sgblog.GetNote(repo, topicsTree, commit.Hash)), Version: sgblog.Version, diff --git a/cmd/sgblog/gopher-entry.tmpl b/cmd/sgblog/gopher-entry.tmpl index 164cb6c..3235123 100644 --- a/cmd/sgblog/gopher-entry.tmpl +++ b/cmd/sgblog/gopher-entry.tmpl @@ -1,9 +1,13 @@ -{{$.T.Get "What"}}: {{.Commit.Hash.String}} +{{$Cfg := .Cfg -}}{{$.T.Get "What"}}: {{.Commit.Hash.String}} {{$.T.Get "When"}}: {{.When}} ------------------------------------------------------------------------ {{if .Topics}}{{$.T.Get "Topics"}}:{{range .Topics}} {{.}}{{end}}{{end}} ------------------------------------------------------------------------ {{.Commit.Message -}} +{{- if .Images}} +------------------------------------------------------------------------ +{{range $idx, $img := .Images}}http://{{$Cfg.ImgDomain}}/{{$img.Path}} +{{end}}{{end -}} {{- if .Note}} ------------------------------------------------------------------------ {{$.T.Get "Note"}}: diff --git a/cmd/sgblog/gopher-menu.tmpl b/cmd/sgblog/gopher-menu.tmpl index f27d4b7..ad89756 100644 --- a/cmd/sgblog/gopher-menu.tmpl +++ b/cmd/sgblog/gopher-menu.tmpl @@ -9,7 +9,7 @@ i{{.Cfg.Title}} {{if .Topic}}({{$.T.Get "topic"}}: {{.Topic}}) {{end}}({{.Offset {{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}} {{- if ne $dateCur $datePrev}}{{$datePrev = $dateCur}} i{{$dateCur}} err{{template "domainPort" $Cfg}}{{$CR}}{{end}} -0[{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}} /{{.Commit.Hash.String}}{{template "domainPort" $Cfg}}{{$CR}}{{end}} +0[{{.Commit.Author.When.Format "15:04"}}] {{.Title}} ({{.LinesNum}}L){{with .ImagesNum}} ({{.}}I){{end}}{{with .CommentsNum}} ({{.}}C){{end}}{{if .Topics}}{{range .Topics}} {{.}}{{end}}{{end}} /{{.Commit.Hash.String}}{{template "domainPort" $Cfg}}{{$CR}}{{end}} {{range .Topics}} 1{{$.T.Get "topic"}}: {{.}} {{.}}/offset/0{{template "domainPort" $Cfg}}{{$CR}}{{end}} i{{$.T.Get "Generated by"}}: SGBlog {{.Version}} err{{template "domainPort" .Cfg}}{{$CR}} diff --git a/cmd/sgblog/gopher.go b/cmd/sgblog/gopher.go index ffa259c..c70a84d 100644 --- a/cmd/sgblog/gopher.go +++ b/cmd/sgblog/gopher.go @@ -51,6 +51,7 @@ type TableMenuEntry struct { Commit *object.Commit Title string LinesNum int + ImagesNum int CommentsNum int Topics []string } @@ -103,6 +104,7 @@ Redirecting to %s... When string Cfg *Cfg Note string + Images []Img Comments []string Topics []string Version string @@ -113,6 +115,7 @@ Redirecting to %s... When: commit.Author.When.Format(sgblog.WhenFmt), Cfg: cfg, Note: string(sgblog.GetNote(repo, notesTree, commit.Hash)), + Images: listImgs(cfg, commit.Hash), Comments: sgblog.ParseComments(sgblog.GetNote(repo, commentsTree, commit.Hash)), Topics: sgblog.ParseTopics(sgblog.GetNote(repo, topicsTree, commit.Hash)), Version: sgblog.Version, @@ -175,11 +178,16 @@ Redirecting to %s... } lines := msgSplit(commit.Message) entries = append(entries, TableMenuEntry{ - Commit: commit, - Title: lines[0], - LinesNum: len(lines) - 2, - CommentsNum: len(sgblog.ParseComments(sgblog.GetNote(repo, commentsTree, commit.Hash))), - Topics: sgblog.ParseTopics(sgblog.GetNote(repo, topicsTree, commit.Hash)), + Commit: commit, + Title: lines[0], + LinesNum: len(lines) - 2, + ImagesNum: len(listImgs(cfg, commit.Hash)), + CommentsNum: len(sgblog.ParseComments(sgblog.GetNote( + repo, commentsTree, commit.Hash, + ))), + Topics: sgblog.ParseTopics(sgblog.GetNote( + repo, topicsTree, commit.Hash, + )), }) } offsetPrev := offset - PageEntries diff --git a/cmd/sgblog/http-index.tmpl b/cmd/sgblog/http-index.tmpl index 6056fc7..4bff19b 100644 --- a/cmd/sgblog/http-index.tmpl +++ b/cmd/sgblog/http-index.tmpl @@ -29,15 +29,16 @@ - - + + + {{if .TopicsEnabled}}{{end}} {{range .Entries -}} {{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}} {{- if ne $dateCur $datePrev -}} - + {{- $datePrev = $dateCur -}} {{- end -}} @@ -45,6 +46,7 @@ + {{if $TopicsEnabled}}{{end}} diff --git a/cmd/sgblog/http.go b/cmd/sgblog/http.go index 50bb1a8..603e757 100644 --- a/cmd/sgblog/http.go +++ b/cmd/sgblog/http.go @@ -85,6 +85,7 @@ type TableEntry struct { Title string LinesNum int CommentsNum int + ImagesNum int DomainURLs []string Topics []string } @@ -337,6 +338,7 @@ func serveHTTP() { entry.DomainURLs = append(entry.DomainURLs, makeA(line, u.Host)) } entry.CommentsNum = len(sgblog.ParseComments(entry.CommentsRaw)) + entry.ImagesNum = len(listImgs(cfg, entry.Commit.Hash)) entry.Topics = sgblog.ParseTopics(entry.TopicsRaw) entries[i] = entry } diff --git a/cmd/sgblog/img.go b/cmd/sgblog/img.go index 7f97d98..46a1921 100644 --- a/cmd/sgblog/img.go +++ b/cmd/sgblog/img.go @@ -45,7 +45,7 @@ func listImgs(cfg *Cfg, what plumbing.Hash) (out []Img) { typ = "application/octet-stream" } out = append(out, Img{ - Path: path.Join(sub, ent.Name()), + Path: path.Join(sub, strings.ReplaceAll(ent.Name(), " ", "%20")), Alt: strings.TrimSuffix(name, ext), Size: info.Size(), Typ: typ, diff --git a/common.go b/common.go index e3c092d..9a33a4a 100644 --- a/common.go +++ b/common.go @@ -15,7 +15,7 @@ import ( ) const ( - Version = "0.28.0" + Version = "0.29.0" WhenFmt = "2006-01-02 15:04:05Z07:00" )
N{{$.T.Get "When"}}{{$.T.Get "Title"}}LCLIC {{$.T.Get "Linked to"}}{{$.T.Get "Topics"}}
{{$dateCur}}
{{$dateCur}}
{{.Commit.Author.When.Format "15:04"}} {{.Title}} {{.LinesNum}}{{if .ImagesNum}}{{.ImagesNum}}{{else}} {{end}} {{if .CommentsNum}}{{.CommentsNum}}{{else}} {{end}} {{if .DomainURLs}}{{range .DomainURLs}} {{.}} {{end}}{{else}} {{end}}{{if .Topics}}{{range .Topics}} {{.}} {{end}}{{else}} {{end}}