From 8e3f93ed503864670476d322639a8b9051d5e740 Mon Sep 17 00:00:00 2001 From: SayaAndy Date: Sat, 2 Aug 2025 16:22:53 +0700 Subject: feat: add geolocation of places in blog --- internal/frontmatter/parser.go | 1 + main.go | 13 +++++++++ static/input.css | 16 ++++++++++ static/output.css | 15 ++++++++++ views/index.html | 2 +- views/layouts/blog-page.html | 66 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) 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/main.go b/main.go index 37d6e8d..447329b 100644 --- a/main.go +++ b/main.go @@ -101,12 +101,25 @@ func main() { return c.Status(fiber.ErrNotFound.Code).SendString(fmt.Sprintf("failed to find '%s' post", c.Params("title"))) } + geolocationParts := strings.Split(metadata.Geolocation, " ") + var x, y, areaError string + if len(geolocationParts) >= 2 { + x = geolocationParts[0] + y = geolocationParts[1] + } + if len(geolocationParts) >= 3 { + areaError = geolocationParts[2] + } + return c.Render("layouts/blog-page", fiber.Map{ "Title": metadata.Title, "PublishedDate": metadata.PublishedTime.Format("2006-01-02 15:04:05 -07:00"), "PublishedYear": strconv.Itoa(metadata.PublishedTime.Year()), "ParsedMarkdownDesktop": template.HTML(parsedMarkdownDesktop), "ParsedMarkdownMobile": template.HTML(parsedMarkdownMobile), + "MapLocationX": x, + "MapLocationY": y, + "MapLocationAreaMeters": areaError, }) }) diff --git a/static/input.css b/static/input.css index 4058cb1..c105d8f 100644 --- a/static/input.css +++ b/static/input.css @@ -227,14 +227,26 @@ width: 90vw; } +.w-p60 { + width: 60%; +} + .w-p80 { width: 80%; } +.w-p100 { + width: 100%; +} + .w-vmax4 { width: 4vmax; } +.h-vh40 { + height: 40vh; +} + .h-vh90 { height: 90vh; } @@ -288,6 +300,10 @@ padding-right: 1.2vmin; } +.p-vmin0-8 { + padding: 0.8vmin; +} + .p-vmin2-4 { padding: 2.4vmin; } diff --git a/static/output.css b/static/output.css index ea57d8f..b07fd94 100644 --- a/static/output.css +++ b/static/output.css @@ -259,6 +259,9 @@ .flex-5 { flex: 5; } + .flex-none { + flex: none; + } .flex-grow { flex-grow: 1; } @@ -584,12 +587,21 @@ .w-vw90 { width: 90vw; } +.w-p60 { + width: 60%; +} .w-p80 { width: 80%; } +.w-p100 { + width: 100%; +} .w-vmax4 { width: 4vmax; } +.h-vh40 { + height: 40vh; +} .h-vh90 { height: 90vh; } @@ -630,6 +642,9 @@ .pr-vmin1-2 { padding-right: 1.2vmin; } +.p-vmin0-8 { + padding: 0.8vmin; +} .p-vmin2-4 { padding: 2.4vmin; } diff --git a/views/index.html b/views/index.html index 1b6f8c8..ce80db6 100644 --- a/views/index.html +++ b/views/index.html @@ -95,7 +95,7 @@