summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-26 00:01:09 +0200
committerPaul Buetow <paul@buetow.org>2024-12-26 00:01:09 +0200
commit03ed103a69b6b6c2f822706e2d0f00759a4b448b (patch)
tree9316bba1ec643994c1d68c57239d7f751e1bc9af /internal
parent578ed10948186d444c7f05e664794a02d25a06f2 (diff)
more on this
Diffstat (limited to 'internal')
-rw-r--r--internal/oi/oi.go2
-rw-r--r--internal/summary/summary.go38
2 files changed, 38 insertions, 2 deletions
diff --git a/internal/oi/oi.go b/internal/oi/oi.go
index 824c0bd..269be1d 100644
--- a/internal/oi/oi.go
+++ b/internal/oi/oi.go
@@ -12,6 +12,8 @@ import (
"golang.org/x/exp/rand"
)
+// TODO: Rewrite all functions here which use channels with range over functions iterators?
+
var ErrNotFound = errors.New("no file/entry found")
func EnsureDir(dir string) error {
diff --git a/internal/summary/summary.go b/internal/summary/summary.go
index a502d06..8978d66 100644
--- a/internal/summary/summary.go
+++ b/internal/summary/summary.go
@@ -5,6 +5,7 @@ import (
"fmt"
"iter"
"path/filepath"
+ "strings"
"codeberg.org/snonux/gos/internal/colour"
"codeberg.org/snonux/gos/internal/config"
@@ -18,11 +19,44 @@ func Run(ctx context.Context, args config.Args) error {
if err != nil {
return err
}
- fmt.Println(entries)
+
+ title := strings.Join(args.SummaryFor, " ")
+ gemtext, err := fmt.Print(generateGemtext(entries, title))
+ if err != nil {
+ return err
+ }
+ fmt.Print(gemtext)
return nil
}
+func generateGemtext(entries []entry.Entry, title string) (string, error) {
+ var sb strings.Builder
+
+ sb.WriteString("# ")
+ sb.WriteString(title)
+
+ for _, en := range entries {
+ sb.WriteString("\n\n## ")
+ sb.WriteString(en.Name())
+ sb.WriteString("\n\n")
+ content, urls, err := en.Content()
+ if err != err {
+ return "", err
+ }
+ sb.WriteString(content)
+ if len(urls) > 0 {
+ for _, url := range urls {
+ // TODO: Shorten URLs display
+ sb.WriteString("\n\n=> ")
+ sb.WriteString(url)
+ }
+ }
+ }
+
+ return sb.String(), nil
+}
+
func matchingEntries(args config.Args) iter.Seq2[entry.Entry, error] {
return func(yield func(entry.Entry, error) bool) {
for _, dateStr := range args.SummaryFor {
@@ -62,7 +96,7 @@ func deduppedEntries(args config.Args) ([]entry.Entry, error) {
dedup[en.Name()] = en
}
- entries := make([]entry.Entry, len(dedup))
+ var entries []entry.Entry
for _, val := range dedup {
entries = append(entries, val)
}