mirror of
https://github.com/dzeiocom/markblog.git
synced 2025-07-30 00:19:49 +00:00
28
pages/portfolio/[slug].tsx
Normal file
28
pages/portfolio/[slug].tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { NextPage, NextPageContext } from "next"
|
||||
|
||||
import React from 'react'
|
||||
import Post from "../../components/Post"
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
|
||||
interface Props {
|
||||
post: Post
|
||||
}
|
||||
|
||||
const PostPage: NextPage<Props> = (props: Props) => {
|
||||
// React.
|
||||
return (
|
||||
<main>
|
||||
<ReactMarkdown source={props.post.content}/>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
PostPage.getInitialProps = async (context: NextPageContext) => {
|
||||
const { slug } = context.query
|
||||
if (typeof slug === "object") throw new Error("Slug is not correct")
|
||||
const post = new Post(slug)
|
||||
await post.fetch()
|
||||
return {post}
|
||||
}
|
||||
|
||||
export default PostPage
|
58
pages/portfolio/index.tsx
Normal file
58
pages/portfolio/index.tsx
Normal file
@ -0,0 +1,58 @@
|
||||
import { NextPage, NextPageContext } from "next"
|
||||
import Link from 'next/link'
|
||||
import Post from "../../components/Post"
|
||||
// import posts from '../../posts/pages.json'
|
||||
// import firstline from 'firstline'
|
||||
// import 'fs'
|
||||
|
||||
interface Props {
|
||||
files: fileInformations[]
|
||||
}
|
||||
|
||||
interface fileInformations {
|
||||
title: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
const PortfolioIndex: NextPage<Props> = (props: Props) => {
|
||||
|
||||
const el: JSX.Element[] = []
|
||||
for (const post of props.files) {
|
||||
el.push(
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{props.files.map(post => (
|
||||
<li key={post.slug}>
|
||||
<Link href="/portfolio/[slug]" as={`/portfolio/${post.slug}`}>
|
||||
<a>{post.title}</a>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
|
||||
const arr: fileInformations[] = []
|
||||
for (const post of await Post.fetchAll()) {
|
||||
if (!post.isStarted) await post.fetch()
|
||||
arr.push({
|
||||
slug: post.slug,
|
||||
title: post.title
|
||||
})
|
||||
}
|
||||
return {files: arr}
|
||||
}
|
||||
|
||||
export default PortfolioIndex
|
||||
|
||||
function l(args: any) {
|
||||
console.log(arguments)
|
||||
}
|
||||
|
||||
async function test() {
|
||||
}
|
Reference in New Issue
Block a user