Add support for hidden pages
This commit is contained in:
parent
c2a99f61c7
commit
5734c9b8fa
8 changed files with 58 additions and 19 deletions
|
@ -1,2 +1,2 @@
|
|||
import './src/styles/global.css';
|
||||
import "prismjs/themes/prism-solarizedlight.css";
|
||||
import 'prismjs/themes/prism-solarizedlight.css';
|
||||
|
|
|
@ -105,5 +105,8 @@ module.exports = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
resolve: 'gatsby-plugin-mdx-frontmatter'
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
node {
|
||||
frontmatter {
|
||||
path
|
||||
hidden
|
||||
}
|
||||
id
|
||||
}
|
||||
|
@ -27,7 +28,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const posts = result.data.allMdx.edges;
|
||||
const posts = result.data.allMdx.edges.filter(({ node }) => !node.frontmatter.hidden);
|
||||
const postsPerPage = 10;
|
||||
const numPages = Math.ceil(posts.length / postsPerPage);
|
||||
const rootPath = "/notes";
|
||||
|
@ -46,7 +47,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
})
|
||||
});
|
||||
|
||||
posts.forEach(({ node }) => {
|
||||
// Must decouple to ensure hidden pages are still rendered, just excluded from
|
||||
// notes mapping
|
||||
result.data.allMdx.edges.forEach(({ node }) => {
|
||||
createPage({
|
||||
path: `${rootPath}/${node.frontmatter.path}`,
|
||||
component: noteTemplate,
|
||||
|
@ -56,3 +59,14 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
});
|
||||
});
|
||||
}
|
||||
exports.createSchemaCustomization = ({ actions: { createTypes } }) => {
|
||||
createTypes(`
|
||||
type Mdx implements Node {
|
||||
frontmatter: MdxFrontmatter
|
||||
}
|
||||
|
||||
type MdxFrontmatter {
|
||||
hidden: Boolean
|
||||
}
|
||||
`);
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"@mdx-js/react": "^1.6.18",
|
||||
"gatsby": "^2.24.63",
|
||||
"gatsby-plugin-mdx": "^1.2.41",
|
||||
"gatsby-plugin-mdx-frontmatter": "^0.0.2",
|
||||
"gatsby-plugin-react-helmet": "^3.3.11",
|
||||
"gatsby-plugin-typography": "^2.5.11",
|
||||
"gatsby-remark-prismjs": "^3.5.13",
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
path: "lorem-ipsum"
|
||||
date: 2020-01-01
|
||||
title: "Lorem Ipsum"
|
||||
hidden: true
|
||||
---
|
||||
|
||||
# h1 Heading 8-)
|
||||
Hey! You've found the secret page that I use to test out style changes.
|
||||
|
||||
# h1 Heading
|
||||
## h2 Heading
|
||||
### h3 Heading
|
||||
#### h4 Heading
|
||||
##### h5 Heading
|
||||
###### h6 Heading
|
||||
|
||||
|
||||
## Horizontal Rules
|
||||
|
||||
___
|
||||
|
@ -103,7 +105,7 @@ Sample text here...
|
|||
|
||||
Syntax highlighting
|
||||
|
||||
``` js
|
||||
```js
|
||||
var foo = function (bar) {
|
||||
return bar++;
|
||||
};
|
|
@ -12,14 +12,13 @@ import Navbar from "../components/navbar";
|
|||
|
||||
-----
|
||||
|
||||
Hey there. I'm just an software engineer with interests in distributed systems,
|
||||
safety and correctness, cybersecurity, homelabbing, homebrewing (both kinds!),
|
||||
and keyboards. My favorite language is Rust, and my most disliked is
|
||||
Python—I've been bitten by its… "features" too many times,
|
||||
unfortunately.
|
||||
Hey there. I'm just an software engineer with varying degrees of interest in
|
||||
distributed systems, safety and correctness, cybersecurity, homelabbing,
|
||||
homebrewing (both kinds!), and keyboards. My favorite language is Rust, and my
|
||||
most disliked is Python.
|
||||
|
||||
#### Contact Info
|
||||
|
||||
The best way to contact me for any reason is by email. My address is [hi (at)
|
||||
this website], and I'll generally respond in a few days. Feel free to send an
|
||||
another email if I don't respond in a week or so.
|
||||
another email if I don't respond in a week or so.
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
/*
|
||||
* This file handles rendering the pages that let users select and find notes.
|
||||
* See note.tsx for rendering a single note.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import Navbar from "../components/navbar";
|
||||
import { graphql, PageProps } from "gatsby";
|
||||
import { graphql } from "gatsby";
|
||||
import style from "./notes.module.css";
|
||||
|
||||
export default ({ data, pageContext }) => {
|
||||
|
@ -14,6 +19,8 @@ export default ({ data, pageContext }) => {
|
|||
prevPageLink = <a href={rootPath + '/' + (currentPage - 1)} className={style.prevPageLink}><<</a>;
|
||||
}
|
||||
|
||||
const shouldDisplayNav = numPages !== 1;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
|
@ -31,11 +38,19 @@ export default ({ data, pageContext }) => {
|
|||
</article>
|
||||
)
|
||||
})}
|
||||
<p className={style.paginationNav}>
|
||||
{prevPageLink}
|
||||
{currentPage}
|
||||
{currentPage !== numPages && <a href={rootPath + '/' + (currentPage + 1)} className={style.nextPageLink}>>></a>}
|
||||
</p>
|
||||
{shouldDisplayNav &&
|
||||
<p className={style.paginationNav}>
|
||||
{prevPageLink}
|
||||
{currentPage}
|
||||
{currentPage !== numPages &&
|
||||
<a
|
||||
href={rootPath + '/' + (currentPage + 1)}
|
||||
className={style.nextPageLink}>
|
||||
>>
|
||||
</a>
|
||||
}
|
||||
</p>
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
@ -44,7 +59,7 @@ export const query = graphql`
|
|||
query IndexQuery($skip: Int!, $limit: Int!) {
|
||||
allMdx(
|
||||
sort: { order: DESC, fields: [frontmatter___date] }
|
||||
filter: { fileAbsolutePath: { glob: "**/src/notes/*" } }
|
||||
filter: { fileAbsolutePath: { glob: "**/src/notes/*" }, frontmatter: {hidden: {ne: true}} }
|
||||
limit: $limit
|
||||
skip: $skip
|
||||
) {
|
||||
|
|
|
@ -5863,6 +5863,11 @@ gatsby-plugin-eslint@^2.0.8:
|
|||
resolved "https://registry.yarnpkg.com/gatsby-plugin-eslint/-/gatsby-plugin-eslint-2.0.8.tgz#1ff7f546a427d274dc2de3932ba29822aae330c3"
|
||||
integrity sha512-vAMy37povmQJNg6ZxY78fkWR3pKwG8MNMhO3u+4vXj2MYT5avhFvHPJTAb126ZCuygf30gAWlpwbV50zP894Jw==
|
||||
|
||||
gatsby-plugin-mdx-frontmatter@^0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/gatsby-plugin-mdx-frontmatter/-/gatsby-plugin-mdx-frontmatter-0.0.2.tgz#5db9d83bc356b2fcd3b360314f79bbf6a2bbb57a"
|
||||
integrity sha512-nGDVNP7gLRnwyRP3rvt27R327GpeY3Ve3OVjiCmrdgkg6ApWCDMlY1XFfuY4iZDJwZXiuhmqrRZUPY5rV5xPJQ==
|
||||
|
||||
gatsby-plugin-mdx@^1.2.41:
|
||||
version "1.2.41"
|
||||
resolved "https://registry.yarnpkg.com/gatsby-plugin-mdx/-/gatsby-plugin-mdx-1.2.41.tgz#56b110050170f6c466d915a39a0094596989c8ef"
|
||||
|
|
Loading…
Reference in a new issue