Diffstat (limited to 'internal/b2/client.go')
| -rw-r--r-- | internal/b2/client.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/internal/b2/client.go b/internal/b2/client.go index f2b6cad..d712736 100644 --- a/internal/b2/client.go +++ b/internal/b2/client.go @@ -3,6 +3,7 @@ package b2 import ( "context" "fmt" + "slices" "strings" "time" @@ -33,13 +34,15 @@ func NewB2Client(cfg *config.B2Config) (*B2Client, error) { type BlogPage struct { Link string + FileName string + Lang string Metadata *frontmatter.Metadata } -func (c *B2Client) Scan() ([]*BlogPage, error) { +func (c *B2Client) Scan(prefix string) ([]*BlogPage, error) { filePaths := []*BlogPage{} - iter := c.bucket.List(context.Background(), b2.ListPrefix(c.prefix)) + iter := c.bucket.List(context.Background(), b2.ListPrefix(c.prefix+prefix)) for iter.Next() { obj := iter.Object() @@ -69,17 +72,24 @@ func (c *B2Client) Scan() ([]*BlogPage, error) { return nil, fmt.Errorf("failed to parse published time metadata field: %w", err) } - linkParts := strings.Split(obj.Name(), ".") + linkParts := strings.Split(obj.Name(), "/") + nameParts := strings.Split(linkParts[len(linkParts)-1], ".") + fileName := strings.Join(nameParts[:len(linkParts)-1], ".") + + tags := strings.Split(attrs.Info["tags"], ",") + slices.Sort(tags) filePaths = append(filePaths, &BlogPage{ - Link: strings.Join(linkParts[:len(linkParts)-1], "."), + Link: obj.Name(), + FileName: fileName, Metadata: &frontmatter.Metadata{ Title: attrs.Info["title"], ShortDescription: attrs.Info["short-description"], ActionDate: attrs.Info["action-date"], PublishedTime: publishedTime, Thumbnail: attrs.Info["thumbnail"], - Tags: strings.Split(attrs.Info["tags"], ","), + Tags: tags, + Geolocation: attrs.Info["geolocation"], }, }) } |