From 9815abf4bb312f7a2d3d9801549e8f78009e7b0e Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Wed, 3 Nov 2021 18:52:41 +0100 Subject: [PATCH] Fix date based archive routes --- httpRouters.go | 6 +++--- search_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 search_test.go diff --git a/httpRouters.go b/httpRouters.go index 5da3c27..221380f 100644 --- a/httpRouters.go +++ b/httpRouters.go @@ -220,17 +220,17 @@ func (a *goBlog) blogDatesRouter(conf *configBlog) func(r chi.Router) { a.cacheMiddleware, ) - yearPath := conf.getRelativePath(`/{year:x|\d\d\d\d}`) + yearPath := conf.getRelativePath(`/{year:(x|\d{4})}`) r.Get(yearPath, a.serveDate) r.Get(yearPath+feedPath, a.serveDate) r.Get(yearPath+paginationPath, a.serveDate) - monthPath := yearPath + `/{month:x|\d\d}` + monthPath := yearPath + `/{month:(x|\d{2})}` r.Get(monthPath, a.serveDate) r.Get(monthPath+feedPath, a.serveDate) r.Get(monthPath+paginationPath, a.serveDate) - dayPath := monthPath + `/{day:\d\d}` + dayPath := monthPath + `/{day:(\d{2})}` r.Get(dayPath, a.serveDate) r.Get(dayPath+feedPath, a.serveDate) r.Get(dayPath+paginationPath, a.serveDate) diff --git a/search_test.go b/search_test.go new file mode 100644 index 0000000..465d030 --- /dev/null +++ b/search_test.go @@ -0,0 +1,15 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_searchEncoding(t *testing.T) { + + testString := "test" + + assert.Equal(t, testString, searchDecode(searchEncode(testString))) + +}