1 // SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU Affero General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 "github.com/go-git/go-git/v5/plumbing"
34 var ImgTypes = map[string]string{
36 ".webp": "image/webp",
39 func listImgs(cfg *Cfg, what plumbing.Hash) (out []Img) {
40 if cfg.ImgPath == "" {
44 sub := path.Join(w[:2], w[2:4], w[4:])
45 ents, err := os.ReadDir(path.Join(cfg.ImgPath, sub))
49 out = make([]Img, 0, len(ents))
50 for _, ent := range ents {
53 info, err := ent.Info()
55 log.Println("imgs: Info():", err)
60 typ = "application/octet-stream"
62 out = append(out, Img{
63 Path: path.Join(sub, strings.ReplaceAll(ent.Name(), " ", "%20")),
64 Alt: strings.TrimSuffix(name, ext),