From 910568bc886bc2167c7c136f0ee003163e70af82 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 1 Apr 2021 13:33:51 +0200 Subject: posts fetched from server --- pages/search.tsx | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'pages') diff --git a/pages/search.tsx b/pages/search.tsx index 11cfe2c..8053d4a 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -1,6 +1,9 @@ +import { useState, useEffect } from 'react'; + import Navbar from '../components/navbar'; import { FormEvent } from 'react'; import { ArticleMeta } from './post/[id]'; +import Tags from '../components/tag' import SearchOutlinedIcon from '@material-ui/icons/SearchOutlined'; @@ -16,13 +19,47 @@ function SearchBar(props: { } -export default function SearchPage(props: { - posts: Array<{ - props: { - meta: ArticleMeta +interface Post { + title: string + subtitle: string + author: string + date: string + urlname: string + tags: Array +} + +interface PostsInfo { + valid_tags: Array + posts: Array +} + +function Post(props: { post: Post }) { + return + {props.post.title} + {props.post.subtitle &&

{props.post.subtitle}

} +

Written by {props.post.author} on {new Date(props.post.date).toLocaleString("en-us", { + month: "long", day: "numeric" + })}

+ +
; +} + +function Posts(props: { posts: Array }) { + return
+ { + props.posts.map(post => ) } - }> -}) { +
; +} + +export default function SearchPage() { + var [posts, setPosts] = useState({ posts: [], valid_tags: [] }); + + useEffect(() => {(async () => { + var posts = await fetch("/posts.json"); + setPosts(await posts.json()); + })()}, []); + return
@@ -37,10 +74,9 @@ export default function SearchPage(props: { ) => { event?.preventDefault(); }}/> +
} -// grep -Por "^\[meta\]:\s+\s+\(\K(.+)(?=\)$)" posts - -- cgit v1.2.3