2023-09-21 23:02:50 +03:00
|
|
|
/* eslint-disable */
|
2023-09-21 01:20:29 +03:00
|
|
|
/* https://strapi.io/blog/how-to-create-an-ssg-static-site-generation-application-with-strapi-webhooks-and-nextjs */
|
|
|
|
import type { InferGetStaticPropsType } from 'next';
|
|
|
|
import Head from "next/head";
|
|
|
|
import Image from "next/image";
|
|
|
|
import Link from "next/link";
|
|
|
|
|
2023-09-21 22:13:54 +03:00
|
|
|
import "@/globals.css";
|
2023-09-21 01:20:29 +03:00
|
|
|
|
|
|
|
type BlogPostAttributes = {
|
|
|
|
imageUrl: string;
|
|
|
|
title: string;
|
|
|
|
description: string;
|
2023-10-23 23:00:42 +03:00
|
|
|
slug: string;
|
|
|
|
publishedAt: string;
|
2023-10-23 22:28:36 +03:00
|
|
|
seo: {
|
|
|
|
metaTitle: string;
|
2023-10-23 23:00:42 +03:00
|
|
|
metaDescription: string;
|
2023-10-23 22:28:36 +03:00
|
|
|
metaImage: {
|
|
|
|
data: {
|
|
|
|
attributes: {
|
|
|
|
formats: {
|
|
|
|
medium: {
|
|
|
|
url: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-09-21 01:20:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
type BlogPost = {
|
|
|
|
id: string;
|
|
|
|
attributes: BlogPostAttributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
export const getStaticProps = async () => {
|
|
|
|
try {
|
2023-10-23 23:00:42 +03:00
|
|
|
const resulting = await fetch("https://cms.quivr.app/api/blogs?populate=seo,seo.metaImage,slug");
|
2023-09-21 01:20:29 +03:00
|
|
|
const data: { data: BlogPost[] } = await resulting.json();
|
|
|
|
|
2023-10-23 23:00:42 +03:00
|
|
|
// Sort blogs by publishedAt in descending order
|
|
|
|
const sortedBlogs = data.data.sort((a, b) => new Date(b.attributes.publishedAt).getTime() - new Date(a.attributes.publishedAt).getTime());
|
|
|
|
|
2023-09-21 01:20:29 +03:00
|
|
|
return {
|
|
|
|
props: {
|
2023-10-23 23:00:42 +03:00
|
|
|
result: sortedBlogs,
|
2023-09-21 01:20:29 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching blogs:", error);
|
|
|
|
|
|
|
|
return {
|
|
|
|
notFound: true, // this will return a 404 page
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
const Blog = ({ result }: InferGetStaticPropsType<typeof getStaticProps>) => {
|
|
|
|
return (
|
2023-10-23 22:28:36 +03:00
|
|
|
<div>
|
|
|
|
<section className="w-full">
|
|
|
|
<Head>
|
|
|
|
<title>Quivr - Blog</title>
|
|
|
|
<meta name="description" content="Quivr.app - Your Generative AI second brain builder's blog" />
|
|
|
|
</Head>
|
2023-09-21 22:13:54 +03:00
|
|
|
|
2023-10-23 22:28:36 +03:00
|
|
|
<header className="bg-white text-zinc-900 py-4 border-b">
|
|
|
|
<div className="container mx-auto px-4 md:px-6">
|
|
|
|
<nav className="flex items-center justify-between">
|
2023-10-23 23:00:42 +03:00
|
|
|
<Link href="/blog">
|
|
|
|
<div className="text-2xl font-bold cursor-pointer">Quivr</div>
|
|
|
|
</Link>
|
2023-10-23 22:28:36 +03:00
|
|
|
<div className="space-x-4">
|
|
|
|
<Link className="text-zinc-900 hover:text-zinc-700" href="/">Try Quivr</Link>
|
2023-10-23 20:24:00 +03:00
|
|
|
</div>
|
2023-10-23 22:28:36 +03:00
|
|
|
</nav>
|
2023-10-23 20:24:00 +03:00
|
|
|
</div>
|
2023-10-23 22:28:36 +03:00
|
|
|
</header>
|
|
|
|
|
|
|
|
<main className="container mx-auto px-4 md:px-6 py-8">
|
|
|
|
<section className="mb-8">
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
|
|
|
{result.map(post => (
|
|
|
|
<div key={post.id}>
|
2023-10-23 23:00:42 +03:00
|
|
|
<Link href={`/blog/${post.attributes.slug}`}>
|
|
|
|
<Image
|
|
|
|
src={`${post.attributes.seo.metaImage.data.attributes.formats.medium.url}`}
|
|
|
|
alt="Blog Post Image"
|
|
|
|
width={600}
|
|
|
|
height={400}
|
|
|
|
className="w-full rounded-lg object-cover cursor-pointer"
|
|
|
|
/>
|
|
|
|
</Link>
|
2023-10-23 22:28:36 +03:00
|
|
|
<h3 className="text-xl font-bold mb-2 mt-4">{post.attributes.seo.metaTitle}</h3>
|
2023-10-23 23:00:42 +03:00
|
|
|
<p className="text-zinc-500">{post.attributes.seo.metaDescription}</p>
|
|
|
|
<Link className="text-blue-500 hover:text-blue-700 mt-4" href={`/blog/${post.attributes.slug}`}>
|
2023-10-23 22:28:36 +03:00
|
|
|
Read More
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
</section>
|
|
|
|
</div>
|
2023-10-23 20:24:00 +03:00
|
|
|
);
|
|
|
|
}
|
2023-09-21 22:13:54 +03:00
|
|
|
|
2023-10-23 20:24:00 +03:00
|
|
|
export default Blog;
|