Query sitemap dates with status and visibility

This commit is contained in:
Jan-Lukas Else 2023-02-24 21:41:46 +01:00
parent 80dfaf4814
commit 7052b686fb
1 changed files with 12 additions and 6 deletions

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"database/sql"
"encoding/xml" "encoding/xml"
"fmt"
"io" "io"
"net/http" "net/http"
"time" "time"
@ -187,15 +187,16 @@ func (a *goBlog) writeSitemapXML(w http.ResponseWriter, _ *http.Request, sm any)
} }
const sitemapDatePathsSql = ` const sitemapDatePathsSql = `
with alldates as ( with filteredposts as ( %s ),
alldates as (
select distinct select distinct
substr(published, 1, 4) as year, substr(published, 1, 4) as year,
substr(published, 6, 2) as month, substr(published, 6, 2) as month,
substr(published, 9, 2) as day substr(published, 9, 2) as day
from ( from (
select tolocal(coalesce(published, '')) as published select tolocal(published) as published
from posts from filteredposts
where blog = @blog and status = @status and published != '' where coalesce(published, '') != ''
) )
) )
select distinct '/' || year from alldates select distinct '/' || year from alldates
@ -212,7 +213,12 @@ select distinct '/x/x/' || day from alldates;
` `
func (a *goBlog) sitemapDatePaths(blog string) (paths []string, err error) { func (a *goBlog) sitemapDatePaths(blog string) (paths []string, err error) {
rows, err := a.db.Query(sitemapDatePathsSql, sql.Named("blog", blog), sql.Named("status", statusPublished)) query, args := buildPostsQuery(&postsRequestConfig{
blog: blog,
status: []postStatus{statusPublished},
visibility: []postVisibility{visibilityPublic},
}, "published")
rows, err := a.db.Query(fmt.Sprintf(sitemapDatePathsSql, query), args...)
if err != nil { if err != nil {
return nil, err return nil, err
} }