fix: sitemap dates

This commit is contained in:
Cory Dransfeldt 2024-07-19 09:27:55 -07:00
parent 5177c3688e
commit 928711aa54
No known key found for this signature in database
4 changed files with 37 additions and 34 deletions

View file

@ -20,7 +20,7 @@ const tagsToHashtags = (tags) => {
}).join('') }).join('')
return '#' + hashtag return '#' + hashtag
}) })
return hashtags.join(' '); return hashtags.join(' ')
} }
export const popularPosts = (collection) => { export const popularPosts = (collection) => {
@ -53,9 +53,37 @@ export const processContent = (collection) => {
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'yyyy-MM-dd') if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'yyyy-MM-dd')
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'MM/dd/yyyy') if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'MM/dd/yyyy')
if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'dd-MM-yyyy') if (!parsedDate.isValid) parsedDate = DateTime.fromFormat(date, 'dd-MM-yyyy')
return parsedDate.isValid ? parsedDate.toISO() : null return parsedDate.isValid ? parsedDate : null
} }
const addSiteMapContent = (items, getTitle, getDate) => {
const addedUrls = new Set()
if (items) {
items.forEach((item) => {
let url
if (item?.['url']) url = item['url']
if (item?.['permalink']) url = item['permalink']
if (item?.['slug']) url = item['slug']
if (!url || addedUrls.has(url)) return
const parsedDate = getDate ? parseDate(getDate(item)) : null
const formattedDate = parsedDate ? parsedDate.toFormat("yyyy-MM-dd'T'HH:mm:ssZZ") : null
const content = {
url,
title: getTitle(item),
date: formattedDate
}
siteMapContent.push(content)
addedUrls.add(url)
})
}
}
const movieData = movies['movies'].filter((movie) => movie['review']?.length && movie['rating'])
const bookData = books.all.filter((book) => book['review']?.length && book['rating'])
const addItemToIndex = (items, icon, getUrl, getTitle, getTags) => { const addItemToIndex = (items, icon, getUrl, getTitle, getTags) => {
if (items) { if (items) {
items.forEach((item) => { items.forEach((item) => {
@ -101,31 +129,6 @@ export const processContent = (collection) => {
} }
} }
const addSiteMapContent = (items, getTitle, getDate) => {
const addedUrls = new Set()
if (items) {
items.forEach((item) => {
let url
if (item?.['url']) url = item['url']
if (item?.['permalink']) url = item['permalink']
if (item?.['slug']) url = item['slug']
if (!url || addedUrls.has(url)) return
const content = {
url,
title: getTitle(item),
date: getDate ? parseDate(getDate(item)) : null
}
siteMapContent.push(content)
addedUrls.add(url)
})
}
}
const movieData = movies['movies'].filter((movie) => movie['review']?.length && movie['rating'])
const bookData = books.all.filter((book) => book['review']?.length && book['rating'])
addItemToIndex(posts, '📝', (item) => new URL(item['slug'], BASE_URL).toString(), (item) => item['title'], (item) => item['tags']) addItemToIndex(posts, '📝', (item) => new URL(item['slug'], BASE_URL).toString(), (item) => item['title'], (item) => item['tags'])
addItemToIndex(links, '🔗', (item) => item['link'], (item) => item['title'], (item) => item['tags']) addItemToIndex(links, '🔗', (item) => item['link'], (item) => item['title'], (item) => item['tags'])
if (movieData) addItemToIndex(movieData, '🎥', (item) => item['url'], (item) => `${item['title']} (${item['rating']})`, (item) => item['tags']) if (movieData) addItemToIndex(movieData, '🎥', (item) => item['url'], (item) => `${item['title']} (${item['rating']})`, (item) => item['tags'])

10
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.12.6", "version": "20.12.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.12.6", "version": "20.12.7",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.4.0", "@cdransf/api-text": "^1.4.0",
@ -2586,9 +2586,9 @@
"license": "BSD-3-Clause" "license": "BSD-3-Clause"
}, },
"node_modules/morphdom": { "node_modules/morphdom": {
"version": "2.7.3", "version": "2.7.4",
"resolved": "https://registry.npmjs.org/morphdom/-/morphdom-2.7.3.tgz", "resolved": "https://registry.npmjs.org/morphdom/-/morphdom-2.7.4.tgz",
"integrity": "sha512-rvGK92GxSuPEZLY8D/JH07cG3BxyA+/F0Bxg32OoGAEFFhGWA3OqVpqPZlOgZTCR52clXrmz+z2pYSJ6gOig1w==", "integrity": "sha512-ATTbWMgGa+FaMU3FhnFYB6WgulCqwf6opOll4CBzmVDTLvPMmUPrEv8CudmLPK0MESa64+6B89fWOxP3+YIlxQ==",
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.12.6", "version": "20.12.7",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -7,7 +7,7 @@ eleventyExcludeFromCollections: true
{% for page in collections.siteMap %} {% for page in collections.siteMap %}
<url> <url>
<loc>{{ globals.url }}{{ page.url }}</loc> <loc>{{ globals.url }}{{ page.url }}</loc>
<lastmod>{{ page.date | date: '%Y-%m-%d' }}</lastmod> <lastmod>{{ page.date | date: '%Y-%m-%dT%H:%M:%S%:z' }}</lastmod>
<changefreq>{% if page.data.changeFreq %}{{ page.data.changeFreq }}{% else %}monthly{% endif %}</changefreq> <changefreq>{% if page.data.changeFreq %}{{ page.data.changeFreq }}{% else %}monthly{% endif %}</changefreq>
<priority>{% if page.data.priority %}{{ page.data.priority }}{% else %}0.5{% endif %}</priority> <priority>{% if page.data.priority %}{{ page.data.priority }}{% else %}0.5{% endif %}</priority>
</url> </url>