mirror of https://github.com/jlelse/GoBlog
Query sitemap dates with status and visibility
This commit is contained in:
parent
80dfaf4814
commit
7052b686fb
18
sitemap.go
18
sitemap.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue