feat: add back links to post pages; add tags to post pages

This commit is contained in:
Cory Dransfeldt 2023-06-05 08:45:57 -07:00
parent 857caf144a
commit 476a7a53ff
No known key found for this signature in database
4 changed files with 36 additions and 3 deletions

View file

@ -57,4 +57,16 @@ module.exports = {
return data
},
pageNumberOf: (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)
},
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}/`
},
}