website/src/templates/notes.tsx

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-11-27 20:25:22 +00:00
/*
* This file handles rendering the pages that let users select and find notes.
* See note.tsx for rendering a single note.
*/
2020-11-28 00:39:21 +00:00
import Navbar from '../components/navbar';
2020-11-28 03:35:36 +00:00
import PaginationNav from '../components/pagination';
import React from 'react';
2020-11-28 00:39:21 +00:00
import { graphql } from 'gatsby';
2021-05-02 01:03:17 +00:00
import { noteTitle } from './notes.module.css';
2020-11-27 19:07:44 +00:00
2020-11-27 21:12:09 +00:00
export default ({ data, pageContext }): JSX.Element => {
2020-11-27 19:07:44 +00:00
const posts = data.allMdx.edges;
const { currentPage, numPages, rootPath } = pageContext;
2020-11-27 20:25:22 +00:00
2020-11-27 19:07:44 +00:00
return (
<>
<Navbar />
{posts.map(({ node }) => {
2020-11-28 00:39:21 +00:00
const frontmatter = node.frontmatter;
2020-11-27 19:07:44 +00:00
return (
<article key={frontmatter.title}>
2021-05-02 01:03:17 +00:00
<div className={noteTitle}>
2020-11-27 19:07:44 +00:00
<h3>
2020-11-28 00:39:21 +00:00
<a href={`${rootPath + '/' + frontmatter.path}`}>
{frontmatter.title}
</a>
2020-11-27 19:07:44 +00:00
</h3>
<time dateTime={frontmatter.date}>{frontmatter.date}</time>
</div>
<p>{node.excerpt}</p>
</article>
2020-11-28 00:39:21 +00:00
);
2020-11-27 19:07:44 +00:00
})}
2020-11-28 03:35:36 +00:00
<PaginationNav
currentPage={currentPage}
numPages={numPages}
rootPath={rootPath}
/>
2020-11-27 19:07:44 +00:00
</>
2020-11-28 00:39:21 +00:00
);
};
2020-11-27 19:07:44 +00:00
export const query = graphql`
2020-11-28 03:35:36 +00:00
query NotesIndexQuery($skip: Int!, $limit: Int!) {
2020-11-27 19:07:44 +00:00
allMdx(
sort: { order: DESC, fields: [frontmatter___date] }
2020-11-28 00:39:21 +00:00
filter: {
fileAbsolutePath: { glob: "**/src/notes/*" }
frontmatter: { hidden: { ne: true } }
}
2020-11-27 19:07:44 +00:00
limit: $limit
skip: $skip
) {
edges {
node {
excerpt(pruneLength: 250)
frontmatter {
title
date(formatString: "YYYY-MM-DD")
path
}
id
}
}
}
}
2020-11-28 00:39:21 +00:00
`;