Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-05-26 00:25:18 +02:00
parent fee40613f1
commit 59a0862d58
7 changed files with 15 additions and 37 deletions

View File

@ -24,11 +24,16 @@ interface States {
export default class PostPage extends Component<Props, States> {
public static async getInitialProps(context: NextPageContext) {
const { slug } = context.query
if (typeof slug === 'object' || slug === '[slug]') {
const { slug, category } = context.query
if (
typeof slug === 'object' ||
slug === '[slug]' ||
typeof category === 'object' ||
category === '[category]'
) {
return {post: undefined}
}
const post = new Post(slug)
const post = new Post(`${category}/${slug}`)
await post.fetch()
return {post}
}

View File

@ -26,14 +26,15 @@ export default class Page extends Component<Props, States> {
const posts = await Post.fetchAll()
const header: Array<PostHeader> = []
const cats: Array<string> = []
posts.forEach(el => {
el.fetchSync()
for (const el of posts) {
await el.fetch()
if (!el.header) {
return
}
header.push(el.header)
cats.push(...el.header.tags || [])
})
}
header.sort((a, b) => (a.date < b.date) ? 1 : -1)
cats.sort((a, b) => (a < b) ? -1 : 1)

View File

@ -80,10 +80,11 @@ PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
if (!post.isStarted) {
await post.fetch()
}
const tags = []
if (!post.header) {
continue
}
const tags = []
for (const tg of post.header.tags || []) {
tags.push(tg.toLowerCase())
}