cmd/sgblog/gemini-entry.tmpl | 6 +++++- cmd/sgblog/gemini-menu.tmpl | 2 +- cmd/sgblog/gemini.go | 9 ++++++--- cmd/sgblog/gopher-entry.tmpl | 6 +++++- cmd/sgblog/gopher-menu.tmpl | 2 +- cmd/sgblog/gopher.go | 18 +++++++++++++----- cmd/sgblog/http-index.tmpl | 8 +++++--- cmd/sgblog/http.go | 2 ++ cmd/sgblog/img.go | 2 +- common.go | 2 +- diff --git a/cmd/sgblog/gemini-entry.tmpl b/cmd/sgblog/gemini-entry.tmpl index cce2ba87c5019ad0f3b7516d3c91d8782ea95ac1b1dd6d1cd2f5d4739cf11515..16fa888388f84d76064e7dc282fb1204050f38cd9ad3c6a8682fba25a9a5cf31 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}} @@ -10,6 +10,10 @@ ## {{$.T.Get "Note"}}: ``` {{.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"}} diff --git a/cmd/sgblog/gemini-menu.tmpl b/cmd/sgblog/gemini-menu.tmpl index d2a44a5ff8b0c2c382c1c88ed2bad54a0640ac0ac2b1f96792b162c897133d78..7c9004eb02fb316170842eb4f765eefc31c659074a45d1831be5c146515882a5 100644 --- a/cmd/sgblog/gemini-menu.tmpl +++ b/cmd/sgblog/gemini-menu.tmpl @@ -9,7 +9,7 @@ {{- range .Entries -}} {{- $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 cfbb13f59318e0c09a47d7f844bd85d543701f7c7fa69486d8ca0c60a186ee30..b166c7919118e579f72798244fd1fc544cc25e319ba0b0bc0265b638376e4755 100644 --- a/cmd/sgblog/gemini.go +++ b/cmd/sgblog/gemini.go @@ -131,9 +131,10 @@ break } 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 @@ Commit *object.Commit When string Cfg *Cfg Note string + Images []Img Comments []string Topics []string Version string @@ -196,6 +198,7 @@ Commit: commit, 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 5647461412e321055c717069c14bc51fde26da195708abae08791e8340ab2f43..0edcd1be9fec1b89cf97cb9d6975da65ea5045c4035f52f5269c231f0b2b821c 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 0afdde1661a11321fda2fe50984e3957fffecf29cfc6fee1bd7157e0d86751f7..a464f16a4efc8cf9d25d3b818383c19b3eec0e390bb4a23353463d0a348891ed 100644 --- a/cmd/sgblog/gopher-menu.tmpl +++ b/cmd/sgblog/gopher-menu.tmpl @@ -9,7 +9,7 @@ {{- range .Entries -}} {{- $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 aed5377bf1bdf0c989d9f8495abd3eaccb7a3a310f2eb386130347e84c755423..b5dc40f8fe342c39c31ac059a9752258a1320b63382bc3b11fe19991dfe36336 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 @@ Commit *object.Commit When string Cfg *Cfg Note string + Images []Img Comments []string Topics []string Version string @@ -113,6 +115,7 @@ Commit: commit, 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 @@ break } 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 2d6d2ddcf368412b714dfac6010255df7838fae44d14fbb0a7257c4d56041a59..80c514500ac17317c032269a33af3fda1b28c5fd2fe78524db42cac40bb17b18 100644 --- a/cmd/sgblog/http-index.tmpl +++ b/cmd/sgblog/http-index.tmpl @@ -29,15 +29,16 @@ {{- $datePrev := "0001-01-01" -}} - - + + + {{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 17da2643d46e001e624e36657ca91505f026291a8e3e59f9117eb23630e7eb52..b438e9669826f2c61f862ab94af242ff6bf12c440b38671635e65b0eb1810387 100644 --- a/cmd/sgblog/http.go +++ b/cmd/sgblog/http.go @@ -85,6 +85,7 @@ Num int Title string LinesNum int CommentsNum int + ImagesNum int DomainURLs []string Topics []string } @@ -337,6 +338,7 @@ } 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 78b93db9bdc7cb9d2de17edc852166cda59cd0d48a3233ca87e94ffbbb12a454..93843fdb7de79ba9476872ab79d69f4b6dc0f04c11996cf38f7ec826972e135d 100644 --- a/cmd/sgblog/img.go +++ b/cmd/sgblog/img.go @@ -45,7 +45,7 @@ if typ == "" { 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 0ba466da0458735cef9f3b8699db33c103a14d1445d1ef3bc1b7badc94a892c6..96c72a7ee1f382b572e54b12f8c8932ee7904c6d10c97240cc45e04b87cf1f45 100644 --- a/common.go +++ b/common.go @@ -15,7 +15,7 @@ "go.cypherpunks.ru/recfile" ) 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}}
{{.Num}} {{.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}}