1
0
Fork 0

refactor blog and showcase implementation

This commit is contained in:
Enoch Riese 2023-07-18 21:27:36 -06:00
parent 6653e6f5b7
commit 2768adc36c
14 changed files with 266 additions and 297 deletions

View file

@ -0,0 +1,37 @@
import { localePath } from 'shared/utils.mjs'
const preGenerate = 6
export const numPerPage = 12
export const getPostSlugPaths = (order) => {
const paths = []
for (const lang in order) {
for (let i = 0; i < preGenerate; i++) {
const slug = order[lang][i]
paths.push(localePath(lang, `${order[lang][i]}`))
}
}
return paths
}
export const getPostIndexPaths = (order, type) => {
const paths = []
for (const language in order) {
paths.push(localePath(language, `${type}/page/1`))
paths.push(localePath(language, `${type}/page/2`))
}
return paths
}
export const getPostIndexProps = (locale, params, order, postInfo) => {
const pageNum = parseInt(params.page)
const numLocPages = Math.ceil(order[locale].length / numPerPage)
if (pageNum > numLocPages) return false
const postSlugs = order[locale].slice(numPerPage * (pageNum - 1), numPerPage * pageNum)
const posts = postSlugs.map((s) => ({ ...postInfo[locale][s], s }))
return { posts, current: pageNum, total: numLocPages }
}