digital-gardeners/pages/directory.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-09-05 16:37:21 +02:00
import Layout from "../components/Layout";
2021-09-06 17:55:45 +02:00
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import Card from "../components/Card";
import { motion } from "framer-motion";
import { gardenFilePath, GARDENS_PATH } from "../utils/mdxUtils";
2021-09-05 16:37:21 +02:00
2021-09-06 17:55:45 +02:00
export default function Directory({ gardens }) {
2021-09-05 16:37:21 +02:00
return (
<Layout>
2021-09-06 17:55:45 +02:00
<motion.ul
initial="hidden"
animate="show"
variants={{
hidden: { opacity: 0, y: 50 },
show: {
opacity: 1,
y: 0,
transition: {
delay: 0.6,
ease: "easeInOut",
duration: 0.7,
},
},
}}
className="flex flex-wrap mt-24"
>
{gardens.map((garden) => (
<Card garden={garden} />
))}
</motion.ul>
2021-09-05 16:37:21 +02:00
</Layout>
);
}
2021-09-06 17:55:45 +02:00
export function getStaticProps() {
const gardens = gardenFilePath.map((filePath) => {
const source = fs.readFileSync(path.join(GARDENS_PATH, filePath));
const { content, data } = matter(source);
return {
content,
data,
filePath,
};
});
return { props: { gardens } };
}