Skip to content

Commit

Permalink
Merge pull request #342 from cagov/jbum-fix-sitemap
Browse files Browse the repository at this point in the history
Fixed sitemap to exclude pages with do-not-crawl tag.
  • Loading branch information
jbum authored Aug 14, 2024
2 parents a88b6e3 + 37e68c2 commit 52ba85a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 2 additions & 4 deletions pages/_data/eleventyComputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,15 @@ module.exports = async () => {
if (!perfAudits) {
perfAudits = await fetch(perfApiUrl).then((res) => res.json());
}

return {
title: (article) => article?.data?.title || article.title,
id: (article) => article?.data?.id,
date: (article) => article?.data?.date || article.date,
publishdate: (article) =>
article?.data?.date.split("T")[0] || article.publishdate,
publishdate: (article) => article?.data?.date.split("T")[0] || article.publishdate,
meta: (article) => article?.data?.excerpt || article.meta,
description: (article) => article?.data?.excerpt || article.meta,
author: (article) => article?.data?.author || article.author,
tags: (article) => (isPost(article) ? ["news"] : article.tags),
tags: (article) => article?.data?.tags || (isPost(article) ? ["news"] : article.tags),
permalink: (article) => getPermalink(article),
layout: (article) => getLayout(article),
eleventyNavigation: (article) => getNavigation(article),
Expand Down
14 changes: 7 additions & 7 deletions pages/manual-content/sitemap.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ eleventyExcludeFromCollections: true
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
{% if not sitemap.urls[page.url | url ].exclude %}
<url>
<loc>https://innovation.ca.gov{{ page.url | url }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
<changefreq>daily</changefreq>
</url>
{% endif %}
{% if (page.data.tags and not page.data.tags.includes('do-not-crawl')) and not sitemap.urls[page.url | url ].exclude %}
<url>
<loc>https://innovation.ca.gov{{ page.url | url }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
<changefreq>daily</changefreq>
</url>
{% endif %}
{% endfor %}
</urlset>

0 comments on commit 52ba85a

Please sign in to comment.