mirror of
https://github.com/dzeiocom/markblog.git
synced 2025-06-19 22:19:19 +00:00
@ -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}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user