import React from 'react' import { NextPage, NextPageContext } from 'next' import Element from '../../components/Element' import Post from '../../components/Post' import Error from '../_error' interface Props { files: Array tag: string } const PortfolioIndex: NextPage = (props: Props) => { if (props.files.length === 0) { return ( ) } return (

Tag: {props && props.tag}

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