From 2929b4279c7a8128bd305290cc4187b6afb11cde Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 13 May 2022 11:47:29 -0600 Subject: Implement rendering Posts to html --- srv/src/post/post.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'srv/src/post/post.go') diff --git a/srv/src/post/post.go b/srv/src/post/post.go index bdc48af..5835995 100644 --- a/srv/src/post/post.go +++ b/srv/src/post/post.go @@ -5,7 +5,6 @@ import ( "database/sql" "errors" "fmt" - "path" "regexp" "strings" "time" @@ -37,6 +36,12 @@ type Post struct { Body string } +// HTTPPath returns the relative URL path of the StoredPost, when querying it +// over HTTP. +func (p Post) HTTPPath() string { + return fmt.Sprintf("%s.html", p.ID) +} + // StoredPost is a Post which has been stored in a Store, and has been given // some extra fields as a result. type StoredPost struct { @@ -46,19 +51,6 @@ type StoredPost struct { LastUpdatedAt time.Time } -// URL returns the relative URL of the StoredPost. -func (p StoredPost) URL() string { - return path.Join( - fmt.Sprintf( - "%d/%0d/%0d", - p.PublishedAt.Year(), - p.PublishedAt.Month(), - p.PublishedAt.Day(), - ), - p.ID+".html", - ) -} - // Store is used for storing posts to a persistent storage. type Store interface { -- cgit v1.2.3