From 121d2877cc7ed0aaf0bbe5c57b86abba982b0441 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 11 Dec 2024 23:09:28 +0200 Subject: initial summary support --- internal/entry/entry.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'internal/entry') diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 70b8396..b866a19 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "regexp" "slices" "strings" @@ -105,6 +106,24 @@ func (en *Entry) Content() (string, []string, error) { return content, extractURLs(content), err } +// Returns the Name, e.g. foo.bar.baz from /path/foo.bar.baz.TIMESTAMP.posted +func (en *Entry) Name() string { + base := filepath.Base(en.Path) + parts := strings.Split(base, ".") + + offset := len(parts) - 1 + + switch en.State { + case Queued: + fallthrough + case Posted: + offset -= 2 + } + + // TODO: Unit test this + return strings.Join(parts[:offset], ".") +} + // Returns the content and also checks for the size limit func (en Entry) ContentWithLimit(sizeLimit int) (string, []string, error) { content, urls, err := en.Content() -- cgit v1.2.3