From ca020f0455c0bb88da2fc2b2dac6e148fb0ee5d7 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 14 Jul 2025 11:54:16 +0300 Subject: [PATCH] Cleaner internal subpackage --- cmd/sgblog-comment-add/main.go | 2 +- cmd/sgblog-topics/main.go | 2 +- cmd/sgblog/gemini.go | 2 +- cmd/sgblog/gopher.go | 2 +- cmd/sgblog/http.go | 2 +- cmd/sgblog/topics.go | 2 +- internal/comments.go | 47 ++++++++++++++++++++++++++++++++++ common.go => internal/note.go | 47 +--------------------------------- internal/topics.go | 33 ++++++++++++++++++++++++ internal/version.go | 3 +++ internal/when.go | 3 +++ 11 files changed, 93 insertions(+), 52 deletions(-) create mode 100644 internal/comments.go rename common.go => internal/note.go (62%) create mode 100644 internal/topics.go create mode 100644 internal/version.go create mode 100644 internal/when.go diff --git a/cmd/sgblog-comment-add/main.go b/cmd/sgblog-comment-add/main.go index 47a15ef..ccd8abf 100644 --- a/cmd/sgblog-comment-add/main.go +++ b/cmd/sgblog-comment-add/main.go @@ -35,7 +35,7 @@ import ( "time" "go.cypherpunks.su/recfile/v3" - "go.stargrave.org/sgblog" + sgblog "go.stargrave.org/sgblog/internal" ) var hashFinder = regexp.MustCompile("([0-9a-f]{40})") diff --git a/cmd/sgblog-topics/main.go b/cmd/sgblog-topics/main.go index a71a2ac..62e1c0d 100644 --- a/cmd/sgblog-topics/main.go +++ b/cmd/sgblog-topics/main.go @@ -26,7 +26,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/storer" - "go.stargrave.org/sgblog" + sgblog "go.stargrave.org/sgblog/internal" ) func main() { diff --git a/cmd/sgblog/gemini.go b/cmd/sgblog/gemini.go index d7a654e..808fd38 100644 --- a/cmd/sgblog/gemini.go +++ b/cmd/sgblog/gemini.go @@ -33,7 +33,7 @@ import ( "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" + sgblog "go.stargrave.org/sgblog/internal" ) var ( diff --git a/cmd/sgblog/gopher.go b/cmd/sgblog/gopher.go index e9173eb..37aef75 100644 --- a/cmd/sgblog/gopher.go +++ b/cmd/sgblog/gopher.go @@ -31,7 +31,7 @@ import ( "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" + sgblog "go.stargrave.org/sgblog/internal" ) var ( diff --git a/cmd/sgblog/http.go b/cmd/sgblog/http.go index 837320b..e8c36f0 100644 --- a/cmd/sgblog/http.go +++ b/cmd/sgblog/http.go @@ -41,8 +41,8 @@ import ( "github.com/go-git/go-git/v5/plumbing/storer" "github.com/klauspost/compress/zstd" "github.com/vorlif/spreak" - "go.stargrave.org/sgblog" "go.stargrave.org/sgblog/cmd/sgblog/atom" + sgblog "go.stargrave.org/sgblog/internal" "lukechampine.com/blake3" ) diff --git a/cmd/sgblog/topics.go b/cmd/sgblog/topics.go index d6528c1..7a6285e 100644 --- a/cmd/sgblog/topics.go +++ b/cmd/sgblog/topics.go @@ -25,7 +25,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" - "go.stargrave.org/sgblog" + sgblog "go.stargrave.org/sgblog/internal" ) type TopicsCache map[string][]plumbing.Hash diff --git a/internal/comments.go b/internal/comments.go new file mode 100644 index 0000000..ec112dc --- /dev/null +++ b/internal/comments.go @@ -0,0 +1,47 @@ +// SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine +// Copyright (C) 2020-2025 Sergey Matveev +// +// 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 . + +package internal + +import ( + "bytes" + "fmt" + + "go.cypherpunks.su/recfile/v3" +) + +func ParseComments(data []byte) []string { + comments := []string{} + r := recfile.NewReader(bytes.NewReader(data)) + for { + fields, err := r.Next() + if err != nil { + break + } + if len(fields) != 3 || + fields[0].F != "From" || + fields[1].F != "Date" || + fields[2].F != "Body" { + continue + } + comments = append(comments, fmt.Sprintf( + "%s: %s\n%s: %s\n%s", + fields[0].F, fields[0].V, + fields[1].F, fields[1].V, + fields[2].V, + )) + } + return comments +} diff --git a/common.go b/internal/note.go similarity index 62% rename from common.go rename to internal/note.go index 128a745..27c6e42 100644 --- a/common.go +++ b/internal/note.go @@ -13,62 +13,17 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -// SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine -package sgblog +package internal import ( "bytes" - "fmt" "io" - "sort" - "text/scanner" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" - "go.cypherpunks.su/recfile/v3" -) - -const ( - Version = "0.36.0" - WhenFmt = "2006-01-02 15:04:05Z07:00" ) -func ParseComments(data []byte) []string { - comments := []string{} - r := recfile.NewReader(bytes.NewReader(data)) - for { - fields, err := r.Next() - if err != nil { - break - } - if len(fields) != 3 || - fields[0].F != "From" || - fields[1].F != "Date" || - fields[2].F != "Body" { - continue - } - comments = append(comments, fmt.Sprintf( - "%s: %s\n%s: %s\n%s", - fields[0].F, fields[0].V, - fields[1].F, fields[1].V, - fields[2].V, - )) - } - return comments -} - -func ParseTopics(data []byte) []string { - var s scanner.Scanner - s.Init(bytes.NewBuffer(data)) - topics := []string{} - for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() { - topics = append(topics, s.TokenText()) - } - sort.Strings(topics) - return topics -} - func GetNote(repo *git.Repository, tree *object.Tree, what plumbing.Hash) []byte { if tree == nil { return nil diff --git a/internal/topics.go b/internal/topics.go new file mode 100644 index 0000000..ade40e6 --- /dev/null +++ b/internal/topics.go @@ -0,0 +1,33 @@ +// SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine +// Copyright (C) 2020-2025 Sergey Matveev +// +// 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 . + +package internal + +import ( + "bytes" + "sort" + "text/scanner" +) + +func ParseTopics(data []byte) []string { + var s scanner.Scanner + s.Init(bytes.NewBuffer(data)) + topics := []string{} + for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() { + topics = append(topics, s.TokenText()) + } + sort.Strings(topics) + return topics +} diff --git a/internal/version.go b/internal/version.go new file mode 100644 index 0000000..416ad4b --- /dev/null +++ b/internal/version.go @@ -0,0 +1,3 @@ +package internal + +const Version = "0.37.0" diff --git a/internal/when.go b/internal/when.go new file mode 100644 index 0000000..3cdfb60 --- /dev/null +++ b/internal/when.go @@ -0,0 +1,3 @@ +package internal + +const WhenFmt = "2006-01-02 15:04:05Z07:00" -- 2.51.0