diff options
| author | Paul Buetow <paul@buetow.org> | 2024-12-11 23:09:28 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-12-11 23:09:28 +0200 |
| commit | 121d2877cc7ed0aaf0bbe5c57b86abba982b0441 (patch) | |
| tree | 46893a05b71aaf6b25e971adda6126ae766eae7b /internal/entry | |
| parent | 0f5ecb2715876d05bed8e54d7bd30754e57bcdc4 (diff) | |
initial summary support
Diffstat (limited to 'internal/entry')
| -rw-r--r-- | internal/entry/entry.go | 19 |
1 files changed, 19 insertions, 0 deletions
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() |
