~ritho/rweb

f95960404a8e6d252105038520a1e490c96792fa — Ritho 2 months ago 52a68ee
Parse the posts date as RFC3339.

Signed-off-by: Ritho <palvarez@ritho.net>
1 files changed, 12 insertions(+), 1 deletions(-)

M internal/engine/storage/blog/blog.go
M internal/engine/storage/blog/blog.go => internal/engine/storage/blog/blog.go +12 -1
@@ 26,6 26,7 @@ import (
	"path"
	"sort"
	"strings"
	"time"

	"git.sr.ht/~ritho/rweb/internal/engine/storage/blog/article"
)


@@ 146,7 147,17 @@ func (s *storage) FetchAll() ([]article.Article, error) {
	}

	sort.Slice(res, func(i, j int) bool {
		return res[i].Metadata["date"] > res[j].Metadata["date"]
		iDate, err := time.Parse(time.RFC3339, res[i].Metadata["date"])
		if err != nil {
			return res[i].Metadata["date"] > res[j].Metadata["date"]
		}

		jDate, err := time.Parse(time.RFC3339, res[j].Metadata["date"])
		if err != nil {
			return res[i].Metadata["date"] > res[j].Metadata["date"]
		}

		return iDate.After(jDate)
	})

	return res, nil