fix: sitemap dates
This commit is contained in:
parent
5177c3688e
commit
928711aa54
4 changed files with 37 additions and 34 deletions
|
@ -20,7 +20,7 @@ const tagsToHashtags = (tags) => {
|
|||
}).join('')
|
||||
return '#' + hashtag
|
||||
})
|
||||
return hashtags.join(' ');
|
||||
return hashtags.join(' ')
|
||||
}
|
||||
|
||||
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, 'MM/dd/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) => {
|
||||
if (items) {
|
||||
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(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'])
|
||||
|
|
10
package-lock.json
generated
10
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "20.12.6",
|
||||
"version": "20.12.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "20.12.6",
|
||||
"version": "20.12.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cdransf/api-text": "^1.4.0",
|
||||
|
@ -2586,9 +2586,9 @@
|
|||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/morphdom": {
|
||||
"version": "2.7.3",
|
||||
"resolved": "https://registry.npmjs.org/morphdom/-/morphdom-2.7.3.tgz",
|
||||
"integrity": "sha512-rvGK92GxSuPEZLY8D/JH07cG3BxyA+/F0Bxg32OoGAEFFhGWA3OqVpqPZlOgZTCR52clXrmz+z2pYSJ6gOig1w==",
|
||||
"version": "2.7.4",
|
||||
"resolved": "https://registry.npmjs.org/morphdom/-/morphdom-2.7.4.tgz",
|
||||
"integrity": "sha512-ATTbWMgGa+FaMU3FhnFYB6WgulCqwf6opOll4CBzmVDTLvPMmUPrEv8CudmLPK0MESa64+6B89fWOxP3+YIlxQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "20.12.6",
|
||||
"version": "20.12.7",
|
||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
@ -7,7 +7,7 @@ eleventyExcludeFromCollections: true
|
|||
{% for page in collections.siteMap %}
|
||||
<url>
|
||||
<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>
|
||||
<priority>{% if page.data.priority %}{{ page.data.priority }}{% else %}0.5{% endif %}</priority>
|
||||
</url>
|
||||
|
|
Reference in a new issue