Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author pages to sitemap #3811

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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