Markdown
GitbookGatsby2021-01-25
π Adding Markdown Pages
- Read files into Gatsby from the filesystem:
gatsby-source-filesystem - Transform Markdown to HTML and
frontmatterto data:gatsby-transformer-remark - Add a Markdown file:
src/markdowns/post.md - Create a page component for the Markdown files:
src/templates/post.js,dangerouslySetInnerHTML - Create static pages using Gatsbyβs Node.js
createPageAPI:gatsby-node.js
π Adding a List of Markdown Blog Posts
- Creating posts:
post.md - Creating page list:
src/pages/index.js:pageQuery=graphql... - Creating PostLink component:
src/components/post-link.js
π gatsby-transformer-remark
gatsby-transformer-remark does basic markdown -> HTML transformation but exposes an API to allow other plugins to intervene in the conversion process e.g. gatsby-remark-prismjs which adds highlighting to code blocks.
π my-blog, tags
- templates/tags, template/tag no need query
graphql, can inherit fromcreatePage({context: {...}}) -
when query using
graphql, all feilds are available insidefrontmatter{ allMarkdownRemark { group(field: frontmatter___tags) { tag: fieldValue totalCount } } } -
_allMarkdownRemark_fields- totalCount
- edges
- nodes
- pageInfo
- distinct(field)
- group(field, limit, skip)
export const pageQuery = graphql` query($tag: String) { allMarkdownRemark( limit: 2000 sort: { fields: [frontmatter___date], order: DESC } filter: { frontmatter: { tags: { in: [$tag] } } } ) { totalCount edges { node { fields { slug } frontmatter { title } } } } } `;
π mdx, rebass
- mdx: markdown + jsx
rebass: React Primitive UI components, built withEmotion,Styled Components, andstyled systemstyled-component: css-in-js- How to use styled components with Material UI in a React app
