]> Sergey Matveev's repositories - sgblog.git/commitdiff
Images in gopher/gemini v0.29.0
authorSergey Matveev <stargrave@stargrave.org>
Sun, 30 Jul 2023 11:11:24 +0000 (14:11 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 30 Jul 2023 11:11:24 +0000 (14:11 +0300)
cmd/sgblog/gemini-entry.tmpl
cmd/sgblog/gemini-menu.tmpl
cmd/sgblog/gemini.go
cmd/sgblog/gopher-entry.tmpl
cmd/sgblog/gopher-menu.tmpl
cmd/sgblog/gopher.go
cmd/sgblog/http-index.tmpl
cmd/sgblog/http.go
cmd/sgblog/img.go
common.go

index 4e234fc1b153f099f99245a45d82ee26f18b2e20..67d6fc41902a8764e7504408c6e6eafcef57cb1e 100644 (file)
@@ -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}}
 {{.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}}
index 756b79cbd3f9f53a92a1f640b2d6c18e4a97be09..94c4790a591580bf1d798f0b3c45ea955c5e989c 100644 (file)
@@ -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: {{.}}
index 1b1131bcc67d5f0b418a13d278ff8d138fa23d03..527874eae26488228777311f4369c0745da12d73 100644 (file)
@@ -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,
index 164cb6ca391ddcee20eed2acbab493fc3662696d..3235123507637a24828b647c5fa9a8cfb3c44fbb 100644 (file)
@@ -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"}}:
index f27d4b7eb045a452b7bdd503456fa1dd1b73d0cc..ad897560766b2309d58ad89c65bcd4a66aa67cbe 100644 (file)
@@ -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}}
index ffa259c135a588e920c045b86fbc764fc01b26f4..c70a84d00bf40a364871c3a51b0a751097353c4f 100644 (file)
@@ -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 <a href="%s">%s</a>...
                        When         string
                        Cfg          *Cfg
                        Note         string
+                       Images       []Img
                        Comments     []string
                        Topics       []string
                        Version      string
@@ -113,6 +115,7 @@ Redirecting to <a href="%s">%s</a>...
                        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 <a href="%s">%s</a>...
                        }
                        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
index 6056fc7b7ae607f3c151d3da37cafdb289eb6063..4bff19b6f01e3ebfcf85d3480e67b558f4ceb218 100644 (file)
 <table border=1>
 <tr>
     <th>N</th><th>{{$.T.Get "When"}}</th><th>{{$.T.Get "Title"}}</th>
-    <th size="5%"><a title="{{$.T.Get "Lines"}}">L</a></th>
-    <th size="5%"><a title="{{$.T.Get "Comments"}}">C</a></th>
+    <th size="2%"><a title="{{$.T.Get "Lines"}}">L</a></th>
+    <th size="2%"><a title="{{$.T.Get "Images"}}">I</a></th>
+    <th size="2%"><a title="{{$.T.Get "Comments"}}">C</a></th>
     <th>{{$.T.Get "Linked to"}}</th>
     {{if .TopicsEnabled}}<th>{{$.T.Get "Topics"}}</th>{{end}}
 </tr>
 {{range .Entries -}}
 {{- $dateCur := .Commit.Author.When.Format "2006-01-02" -}}
 {{- if ne $dateCur $datePrev -}}
-    <tr><td colspan={{if $TopicsEnabled}}7{{else}}7{{end}}><center><tt>{{$dateCur}}</tt></center></td></tr>
+    <tr><td colspan={{if $TopicsEnabled}}8{{else}}7{{end}}><center><tt>{{$dateCur}}</tt></center></td></tr>
     {{- $datePrev = $dateCur -}}
 {{- end -}}
 <tr>
@@ -45,6 +46,7 @@
     <td><tt>{{.Commit.Author.When.Format "15:04"}}</tt></td>
     <td><a href="{{$.Cfg.URLPrefix}}/{{.Commit.Hash.String}}">{{.Title}}</a></td>
     <td>{{.LinesNum}}</td>
+    <td>{{if .ImagesNum}}{{.ImagesNum}}{{else}}&nbsp;{{end}}</td>
     <td>{{if .CommentsNum}}{{.CommentsNum}}{{else}}&nbsp;{{end}}</td>
     <td>{{if .DomainURLs}}{{range .DomainURLs}} {{.}} {{end}}{{else}}&nbsp;{{end}}</td>
     {{if $TopicsEnabled}}<td>{{if .Topics}}{{range .Topics}} <a href="{{$.Cfg.URLPrefix}}/?topic={{.}}">{{.}}</a> {{end}}{{else}}&nbsp;{{end}}</td>{{end}}
index 50bb1a882f841715f2d0dee1be079243ef67e858..603e757be430f53703ae66f1f5835d561e22d1aa 100644 (file)
@@ -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
                }
index 7f97d98417bf2af977ef7dc3e1c88b585d0e51d4..46a19216765a9f9ce319dc480df296a4265206b1 100644 (file)
@@ -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,
index e3c092d435b30266d087b4c3347cf8c5053b7ddd..9a33a4a64dd025d46eef30c07c5384b214f82e06 100644 (file)
--- 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"
 )