chore: update back link language

This commit is contained in:
Cory Dransfeldt 2023-06-05 12:18:32 -07:00
parent 58ffbe2474
commit 9382c6a1d7
No known key found for this signature in database
5 changed files with 27 additions and 15 deletions

View file

@ -57,16 +57,17 @@ module.exports = {
return data
},
pageNumberOf: (postUrl, collection, pageSize = 10) => {
pageLinkMeta: (postUrl, collection, pageSize = 10) => {
const index = collection.findIndex((p) => p.data.page.url === postUrl)
if (index === -1) throw new Error(`${postUrl} not found in collection`)
return Math.ceil(collection.length / pageSize) - Math.ceil(index / pageSize)
return {
number: Math.ceil(collection.length / pageSize) - Math.ceil(index / pageSize),
slug: collection[index].fileSlug,
}
},
blogBackLink: (postUrl, collection, pageSize = 10) => {
const index = collection.findIndex((p) => p.data.page.url === postUrl)
if (index === -1) throw new Error(`${postUrl} not found in collection`)
const pageNumber = Math.ceil(collection.length / pageSize) - Math.ceil(index / pageSize)
if (pageNumber === 0) return '/'
return `/${pageNumber}/`
blogListingLink: (postUrl, collection, pageSize = 10) => {
const pageLinkMeta = module.exports.pageLinkMeta(postUrl, collection, pageSize)
if (pageLinkMeta.number === 0) return { uri: `/#${pageLinkMeta.slug}`, number: '1' }
return { uri: `/${pageLinkMeta.number}#${pageLinkMeta.slug}`, number: pageLinkMeta.number + 1 }
},
}