diff options
| author | 2025-08-02 15:50:05 +0700 | |
|---|---|---|
| committer | 2025-08-02 15:52:48 +0700 | |
| commit | 140dd55ae162c3fd3337ab5ad96d418acab10deb (patch) | |
| tree | 97eac15f40708e3020a7516ee719edd10e3405a0 | |
| parent | 00c1f7b891d9861ae8ea74e713e0513005d37ced (diff) | |
| download | articlator-140dd55ae162c3fd3337ab5ad96d418acab10deb.tar.gz articlator-140dd55ae162c3fd3337ab5ad96d418acab10deb.zip | |
feat: add geolocation metadata
| -rw-r--r-- | internal/frontmatter/parser.go | 1 | ||||
| -rw-r--r-- | internal/storage/b2.go | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/internal/frontmatter/parser.go b/internal/frontmatter/parser.go index 6cc3ee8..1a521c0 100644 --- a/internal/frontmatter/parser.go +++ b/internal/frontmatter/parser.go @@ -15,6 +15,7 @@ type Metadata struct { PublishedTime time.Time `yaml:"publishedTime"` Thumbnail string `yaml:"thumbnail"` Tags []string `yaml:"tags"` + Geolocation string `yaml:"geolocation"` } func ParseFrontmatter(content []byte) (metadata *Metadata, markdown []byte, err error) { diff --git a/internal/storage/b2.go b/internal/storage/b2.go index 260a015..0c4b673 100644 --- a/internal/storage/b2.go +++ b/internal/storage/b2.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "strconv" "strings" "time" @@ -96,6 +97,24 @@ func (sc *B2StorageClient) WriteMetadata(path string, metadata *frontmatter.Meta return fmt.Errorf("error getting attributes of an object: %w", err) } + geolocationParts := strings.Split(metadata.Geolocation, " ") + if (len(geolocationParts) == 1 && geolocationParts[0] != "") || len(geolocationParts) >= 4 { + return fmt.Errorf("invalid geolocation format, expecting '{x} {y} [areaError]' or an empty string") + } + if len(geolocationParts) >= 2 { + if _, err := strconv.ParseFloat(geolocationParts[0], 64); err != nil { + return fmt.Errorf("invalid geolocation parameter, expected float for X: %w", err) + } + if _, err := strconv.ParseFloat(geolocationParts[1], 64); err != nil { + return fmt.Errorf("invalid geolocation parameter, expected float for Y: %w", err) + } + } + if len(geolocationParts) == 3 { + if _, err := strconv.ParseFloat(geolocationParts[2], 64); err != nil { + return fmt.Errorf("invalid geolocation parameter, expected float for area error: %w", err) + } + } + attrs := &b2.Attrs{ ContentType: "text/markdown; charset=utf-8", Info: map[string]string{ @@ -105,6 +124,7 @@ func (sc *B2StorageClient) WriteMetadata(path string, metadata *frontmatter.Meta "published-time": metadata.PublishedTime.Format(time.RFC3339), "thumbnail": metadata.Thumbnail, "tags": strings.Join(metadata.Tags, ","), + "geolocation": metadata.Geolocation, "metadata-last-update-sha1": oldAttrs.SHA1, }} |