import { NextPage, NextPageContext } from "next" import Link from 'next/link' import Post from "../../components/Post" import Element from '../../components/Element' import Error from "../_error" // import posts from '../../posts/pages.json' // import firstline from 'firstline' // import 'fs' interface Props { files: Post[], tag: string } const PortfolioIndex: NextPage = (props: Props) => { const el: JSX.Element[] = [] for (const post of props.files) { el.push( ) } if (props.files.length === 0) { return ( ) } return (

Tag: {props && props.tag}

{props.files.map((post, index) => ( ))}
) } PortfolioIndex.getInitialProps = async (context: NextPageContext) => { const { tag } = context.query if (typeof tag === "object" || tag === "[tag]") return {files: [], tag: ""} const arr: Post[] = [] for (const post of await Post.fetchAll()) { if (!post.isStarted) await post.fetch() let tags = [] for (const tg of post.header.tags) { tags.push(tg.toLowerCase()) } if (!tags.includes(tag)) continue arr.push(post) } return {files: arr, tag: tag} as Props } export default PortfolioIndex