diff --git a/httpRouters.go b/httpRouters.go index 5eef059..b036e96 100644 --- a/httpRouters.go +++ b/httpRouters.go @@ -215,6 +215,7 @@ func (a *goBlog) blogSectionsRouter(conf *configBlog) func(r chi.Router) { r.Get(secPath, a.serveIndex) r.Get(secPath+feedPath, a.serveIndex) r.Get(secPath+paginationPath, a.serveIndex) + r.Group(a.dateRoutes(conf, section.Name)) }) } } @@ -251,7 +252,13 @@ func (a *goBlog) blogDatesRouter(conf *configBlog) func(r chi.Router) { a.cacheMiddleware, ) - yearPath := conf.getRelativePath(`/{year:(x|\d{4})}`) + r.Group(a.dateRoutes(conf, "")) + } +} + +func (a *goBlog) dateRoutes(conf *configBlog, pathPrefix string) func(r chi.Router) { + return func(r chi.Router) { + yearPath := conf.getRelativePath(pathPrefix + `/{year:(x|\d{4})}`) r.Get(yearPath, a.serveDate) r.Get(yearPath+feedPath, a.serveDate) r.Get(yearPath+paginationPath, a.serveDate) diff --git a/posts.go b/posts.go index f6c7876..655ab81 100644 --- a/posts.go +++ b/posts.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "path" "reflect" "strings" "time" @@ -224,14 +225,21 @@ func (a *goBlog) serveDate(w http.ResponseWriter, r *http.Request) { a.serve404(w, r) return } - _, bc := a.getBlog(r) - ic := &indexConfig{ - path: bc.getRelativePath(datePath), - title: title, - year: year, - month: month, - day: day, + var ic *indexConfig + if cv := r.Context().Value(indexConfigKey); cv != nil { + origIc := *(cv.(*indexConfig)) + copyIc := origIc + ic = ©Ic + ic.path = path.Join(ic.path, datePath) + ic.titleSuffix = ": " + title + } else { + _, bc := a.getBlog(r) + ic = &indexConfig{ + path: bc.getRelativePath(datePath), + title: title, + } } + ic.year, ic.month, ic.day = year, month, day a.serveIndex(w, r.WithContext(context.WithValue(r.Context(), indexConfigKey, ic))) } @@ -279,6 +287,7 @@ type indexConfig struct { parameter string year, month, day int title string + titleSuffix string description string summaryTemplate summaryTyp status []postStatus @@ -342,6 +351,7 @@ func (a *goBlog) serveIndex(w http.ResponseWriter, r *http.Request) { } else if search != "" { title = fmt.Sprintf("%s: %s", bc.Search.Title, search) } + title += ic.titleSuffix // Description var description string if ic.description != "" { diff --git a/sitemap.go b/sitemap.go index 337bd37..6934c72 100644 --- a/sitemap.go +++ b/sitemap.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "path" "time" "github.com/araddon/dateparse" @@ -117,6 +118,12 @@ func (a *goBlog) serveSitemapBlogArchives(w http.ResponseWriter, r *http.Request sm.Add(&sitemap.URL{ Loc: a.getFullAddress(bc.getRelativePath(section.Name)), }) + datePaths, _ := a.sitemapDatePaths(b, []string{section.Name}) + for _, p := range datePaths { + sm.Add(&sitemap.URL{ + Loc: a.getFullAddress(bc.getRelativePath(path.Join(section.Name, p))), + }) + } } } // Taxonomies @@ -138,7 +145,7 @@ func (a *goBlog) serveSitemapBlogArchives(w http.ResponseWriter, r *http.Request } } // Date based archives - datePaths, _ := a.sitemapDatePaths(b) + datePaths, _ := a.sitemapDatePaths(b, nil) for _, p := range datePaths { sm.Add(&sitemap.URL{ Loc: a.getFullAddress(bc.getRelativePath(p)), @@ -212,9 +219,10 @@ union select distinct '/x/x/' || day from alldates; ` -func (a *goBlog) sitemapDatePaths(blog string) (paths []string, err error) { +func (a *goBlog) sitemapDatePaths(blog string, sections []string) (paths []string, err error) { query, args := buildPostsQuery(&postsRequestConfig{ blog: blog, + sections: sections, status: []postStatus{statusPublished}, visibility: []postVisibility{visibilityPublic}, }, "published")