aboutsummaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-01 16:15:20 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-01 16:15:20 +0200
commit77943f248166c286bcb6dff826bc2b4e1752fd56 (patch)
treee5e1edf9ed6450a1844e00f8f3a15b8e94d98d1f /pages
parent7d2c52b21ff28c80d28a1408cf6abb85d7725848 (diff)
search page sorted by date
Diffstat (limited to 'pages')
-rw-r--r--pages/search.tsx8
1 files changed, 5 insertions, 3 deletions
diff --git a/pages/search.tsx b/pages/search.tsx
index a0eb32c..3eb46ab 100644
--- a/pages/search.tsx
+++ b/pages/search.tsx
@@ -54,7 +54,7 @@ function Posts(props: { posts: Array<Post> }) {
export default function SearchPage() {
var [posts, setPosts] = useState<PostsInfo>({ posts: [], valid_tags: [] });
- var [query, setQuery] = useState("");
+ var [query, setQuery] = useState("-");
var [visiblePosts, setVisiblePosts] = useState<Array<Post>>([]);
var fuse = new Fuse(posts.posts, {
@@ -73,10 +73,12 @@ export default function SearchPage() {
var query = new URLSearchParams(window.location.search).get("q") || "";
if(query)
(document.getElementById("searchInput") as HTMLInputElement).value = query;
- setQuery(query);
var posts = await fetch("/posts.json");
- setPosts(await posts.json());
+ var postsJson: PostsInfo = await posts.json();
+ postsJson.posts = postsJson.posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
+ setPosts(postsJson);
+ setQuery(query);
})()}, []);
useEffect(() => {