You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

import Layout from "../../components/Layout";
import BlogList from "../../components/BlogList";
4 years ago
import matter from "gray-matter";
4 years ago
const Index = (props) => {
return (
<Layout pathname="/" siteTitle="~/garrit" siteDescription="">
4 years ago
<section>
<BlogList posts={props.posts} />
</section>
</Layout>
);
};
export async function getStaticProps() {
//get posts & context from folder
const posts = ((context) => {
const keys = context.keys();
const values = keys.map(context);
const data = keys.map((key, index) => {
// Create slug from filename
const slug = key
.replace(/^.*[\\\/]/, "")
.split(".")
.slice(0, -1)
.join(".");
const value = values[index];
// Parse yaml metadata & markdownbody in document
const document = matter(value.default);
return {
frontmatter: document.data,
markdownBody: document.content,
slug,
};
});
return data;
})(require.context("../../content/posts", true, /\.md$/));
4 years ago
return {
props: {
posts,
title: "~/garrit",
4 years ago
description: "",
},
};
}
4 years ago
export default Index;