Skip to content

Commit

Permalink
Merge pull request #3811 from owid/larsyencken/add-author-pages-to-si…
Browse files Browse the repository at this point in the history
…temap

Add author pages to sitemap
  • Loading branch information
larsyencken authored Aug 2, 2024
2 parents bacc2c3 + f02d01f commit 15b8fa5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions baker/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js"
import { ExplorerProgram } from "../explorer/ExplorerProgram.js"
import { getPostsFromSnapshots } from "../db/model/Post.js"
import { calculateDataInsightIndexPageCount } from "../db/model/Gdoc/gdocUtils.js"
import { getMinimalAuthors } from "../db/model/Gdoc/GdocAuthor.js"

interface SitemapUrl {
loc: string
Expand Down Expand Up @@ -74,6 +75,7 @@ export const makeSitemap = async (
(postrow) => !alreadyPublishedViaGdocsSlugsSet.has(postrow.slug)
)
const gdocPosts = await db.getPublishedGdocPosts(knex)
const authorPages = await getMinimalAuthors(knex)

const publishedDataInsights = await db.getPublishedDataInsights(knex)
const dataInsightFeedPageCount = calculateDataInsightIndexPageCount(
Expand Down Expand Up @@ -140,6 +142,12 @@ export const makeSitemap = async (
}))
)
.concat(explorers.flatMap(explorerToSitemapUrl))
.concat(
authorPages.map((a) => ({
loc: urljoin(BAKED_BASE_URL, "team", a.slug),
lastmod: dayjs(a.updatedAt).format("YYYY-MM-DD"),
}))
)

const sitemap = `<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Expand Down
4 changes: 3 additions & 1 deletion db/model/Gdoc/GdocAuthor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ export async function getMinimalAuthors(
SELECT
slug,
content->>'$.title' as name,
content->>'$."featured-image"' as featuredImage
content->>'$."featured-image"' as featuredImage,
-- updatedAt is often set to the unix epoch instead of null
COALESCE(NULLIF(updatedAt, '1970-01-01'), createdAt) updatedAt
FROM posts_gdocs
WHERE type = 'author'
AND published = 1`
Expand Down
4 changes: 3 additions & 1 deletion db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,9 @@ export async function getMinimalAuthorsByNames(
SELECT
slug,
content->>'$.title' AS name,
content->>'$."featured-image"' AS featuredImage
content->>'$."featured-image"' AS featuredImage,
-- updatedAt is often set to the unix epoch instead of null
COALESCE(NULLIF(updatedAt, '1970-01-01'), createdAt) updatedAt
FROM posts_gdocs
WHERE type = 'author'
AND content->>'$.title' in (:names)
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/types/src/gdocTypes/Gdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface LinkedAuthor {
name: string
slug: string
featuredImage: string | null
updatedAt: Date
}

// A minimal object containing metadata needed for rendering prominent links etc in the client
Expand Down

0 comments on commit 15b8fa5

Please sign in to comment.