]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/gopher.go
Unify copyright comment format
[sgblog.git] / cmd / sgblog / gopher.go
index f6bc3b4cc7a40aaad0532985653b4c39c077c4d3..0eb5e3e58ff69276e91bcc7812f030cf77473176 100644 (file)
@@ -1,19 +1,17 @@
-/*
-SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU Affero General Public License as
-published by the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
+// Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package main
 
@@ -33,6 +31,7 @@ import (
        "github.com/go-git/go-git/v5"
        "github.com/go-git/go-git/v5/plumbing"
        "github.com/go-git/go-git/v5/plumbing/object"
+       "github.com/vorlif/spreak"
        "go.stargrave.org/sgblog"
 )
 
@@ -50,6 +49,7 @@ type TableMenuEntry struct {
        Commit      *object.Commit
        Title       string
        LinesNum    int
+       ImagesNum   int
        CommentsNum int
        Topics      []string
 }
@@ -62,6 +62,7 @@ func serveGopher(cfgPath string) {
        if cfg.GopherDomain == "" {
                log.Fatalln("GopherDomain is not configured")
        }
+       initLocalizer(cfg.Lang)
 
        headHash, err := initRepo(cfg)
        if err != nil {
@@ -96,19 +97,23 @@ Redirecting to <a href="%s">%s</a>...
                        log.Fatalln(err)
                }
                err = TmplGopherEntry.Execute(os.Stdout, struct {
+                       T            *spreak.Localizer
                        Commit       *object.Commit
                        When         string
                        Cfg          *Cfg
                        Note         string
+                       Images       []Img
                        Comments     []string
                        Topics       []string
                        Version      string
                        TitleEscaped string
                }{
+                       T:        localizer,
                        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,
@@ -171,11 +176,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
@@ -183,6 +193,7 @@ Redirecting to <a href="%s">%s</a>...
                        offsetPrev = 0
                }
                err = TmplGopherMenu.Execute(os.Stdout, struct {
+                       T          *spreak.Localizer
                        Cfg        *Cfg
                        Topic      string
                        Offset     int
@@ -193,6 +204,7 @@ Redirecting to <a href="%s">%s</a>...
                        Topics     []string
                        Version    string
                }{
+                       T:          localizer,
                        Cfg:        cfg,
                        Topic:      topic,
                        Offset:     offset,