Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDX Integration for docs and blog pages #129

Closed
8 tasks done
arcticicestudio opened this issue Mar 2, 2019 · 0 comments
Closed
8 tasks done

MDX Integration for docs and blog pages #129

arcticicestudio opened this issue Mar 2, 2019 · 0 comments

Comments

@arcticicestudio
Copy link
Contributor

arcticicestudio commented Mar 2, 2019

Associated epic: #24, #63, #69

This issue documents the integration of MDX with gatsby-mdx to implement the logic and layout for /docs and /blog pages.

Responsive Design

All sections will follow the responsive design concept to adjust the rendered content based on the available width and provide an optimal UX on smaller viewports.

MDX

This issue handles the actual content of the documentation and blog posts.
Gatsby allows to use Markdown for it that comes with the nice side effect that the already existing documentations can simply be adapted and reused, but unfortunately it is limited to it's reduced and simplified syntax.

To also use the great power of React for content and not only layout and design this project will make use of the [MDX specification][gh-mdx-spec], a new language and abstract syntax tree definition.

In order to ensure a vibrant ecosystem and community, tooling needs to exist for formatting, linting, and plugins. This tooling requires a foundational specification and abstract syntax tree so that parsing is properly handled before transforming to JSX/Hyperscript/React/etc and potentially leveraging existing plugin ecosystems.

We will use the official implementation, the fully-featured MDX parser, loader and JSX renderer together with the great Gatsby plugin gatsby-mdx to allow to seamlessly use JSX in Markdown documents by importing components and export metadata or any other ECMAScript compliant data structures like frontmatter.

  • 💻 Everything is a component: Use existing components inside your MDX and import other MDX files as plain components.
  • 🔧 Customizable: Decide which component is rendered for each Markdown element ({ h1: MyHeading }).
  • 📚 Markdown-based: The simplicity and elegance of Markdown remains, you interleave JSX only when you want to.
  • 🔥 Blazingly blazing fast: MDX has no runtime, all compilation occurs during the build stage.

More details are provided by the official MDX and gatsby-mdx websites that include docs to get started, usage examples and advanced configuration and customization information.

Integration

To integrate MDX Gatsby's onCreateNode and createPages APIs will be implemented to handle the generation of the GraphQL MDX nodes and the subsequent automated creation of the docs pages and blog posts.

Image Processing

To get the best performance and quality for images Gatsby's awesome support for the high performance Node.js image processing library “Sharp“ will be used through gatsby-plugin-sharp, gatsby-transformer-sharp and gatsby-image.

To automatically process all images the transformer provides GraphQL query fragments like GatsbyImageSharpFluid. They will be used within custom fragments that'll be implemented to fit the project structure.

Custom Content Components

In order to create great documentations and blog posts with interactive elements a new mdx-elements atom core package will be created initially including some custom React components that can be imported and placed in MDX based content.

To reduce the requirement of imports and "logical Markdown" almost all HTML elements supported by the official Markdown as well as the GitHub Flavored Markdown Specification the MDXProvider component will be used to map the project's base components to their specific HTML elements.

Docs Pages

The design of docs pages will imitate a paper sheet where the overall styles will use a darker background so that the white paper stands out for a clear and sharp content visualization.

Blog Posts

The last remaining main page is /blog which will present an overview of Nord's blog posts in a three-column grid of card components sorted descending by their publish date. Each card will consist of an cover image together with the title of the post. The latest post will span over two columns at the top for a nice visual structure and better recognizability.
While a one-column card will use a cover image the latest post will use a banner that will either be the same image with a larger width, a variant of it or a completly different one.

A blog post itself will make use of the MDX features and the custom MDX components mentioned in the paragraph above. To simplify the usage of the cover and banner image they will be processed with Gatsby's onCreateNode API in combination with Gatsby's mapping configuration feature. This allows to map the paths of images to a File node that will then be handled by the Gatsby image processing plugin workflow also documented in the Image Processing section above.

Another required node will be the heroImage field that queries for a hero.(png|jpg|jpeg) image that'll be used as the hero of a blog post.
To also allow the usage of videos in blog posts or even as header a custom Video MDX component will be implemented including the optional heroVideo and heroVideoPoster GraphQL node fields.

All together that results in the following required and optional images/videos mapped to specific node fields with reserved file names per blog post directory for simple usage via GraphQL queries:

  • bannerImagebanner.(png|jpg|jpeg) — The required banner image of a blog post card (used when currently the latest two-column wide post placed on top of the grid).
  • coverImagecover.(png|jpg|jpeg) — The required cover image of a one-column blog post.
  • heroImagehero.(png|jpg|jpeg) — The required hero image of a blog post.
  • heroVideohero.(mp4|webm) — The optional hero video of a blog post.
  • heroVideoPosterheroposter.(png|jpg|jpeg) — The optional poster image of a blog post heroVideo.

Known Problems

To prevent the unknwon field GraphQL error during build time (e.g. when there are no blog posts yet) a dummy/placeholder blog post and docs page will be created.
Anyway, they will be removed as soon as there is finally the first blog post and docs page. Later on the project will migrate to the shiny new schema customization API.

Tasks

  • Install dependencies:
  • Install development dependencies:
  • Implement Gatsby onCreateNode and createPages APIs.
  • Configure gatsby-plugin-sharp, gatsby-transformer-sharp and gatsby-mdx including custom GraphQL fragments with the GatsbyImageSharpFluid type.
  • Rename HTMLElements package to html-elements to reflect its purpose as package and not as a React component.
  • Initially implement MDX-specific components Image (wraps GatsbyImage), ShinkedWidth and Video placed in the new atom core package mdx-elements.
  • Implement DocsPage and BlogPost template components
    • Implement PaperSheet styled component for uniform docs design
    • Use MDXProvider to map custom HTML components to default Markdown elements
    • Implement wrapper component for doc pages to define specific style like Inter UI font family.
  • Implement blog post grid and card components including the corresponsing GraphQL node fields and queries.
@arcticicestudio arcticicestudio added this to the 0.10.0 milestone Mar 2, 2019
@arcticicestudio arcticicestudio self-assigned this Mar 2, 2019
arcticicestudio added a commit that referenced this issue Mar 3, 2019
arcticicestudio added a commit that referenced this issue Mar 3, 2019
To integrate MDX Gatsby's `onCreateNode` () and `createPages` (2) APIs
has been implemented to handle the generation of the GraphQL MDX nodes
and the subsequent automated creation of the docs pages and blog posts.

References:
  (1) https://www.gatsbyjs.org/docs/node-apis/#onCreateNode
  (2) https://www.gatsbyjs.org/docs/node-apis/#createPages

GH-129
arcticicestudio added a commit that referenced this issue Mar 3, 2019
To get the best performance and quality for images the awesome Gatsby's
awesome support for the high performance Node.js image processing
library "Sharp" (1) is used through `gatsby-plugin-sharp` (2),
`gatsby-transformer-sharp` (3) and gatsby-image (4).

To automatically process all images the transformer provides GraphQL
query fragments like `GatsbyImageSharpFluid`. They are used within
custom fragments that have been implemented to fit the project structure.

References:
  (1) https://github.com/lovell/sharp
  (2) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-sharp
  (3) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-sharp
  (4) https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-image

GH-129
arcticicestudio added a commit that referenced this issue Mar 3, 2019
The new name now reflect its purpose as package and not as a React
component.

GH-129
arcticicestudio added a commit that referenced this issue Mar 3, 2019
This commit initially includes the `Image` (wraps `GatsbyImage`) and
`ShinkWidth` component placed in the new atom core package
`mdx-elements`.

GH-129
arcticicestudio added a commit that referenced this issue Mar 3, 2019
This includes styled components like `PaperSheet` for a uniform docs
design. The `MDXProvider` has been configured to map custom HTML
components to default Markdown elements and a wrapper component for doc
pages has been implemented to define specific styles like "Inter UI"
font family.

GH-129
arcticicestudio added a commit that referenced this issue Mar 5, 2019
Previously the parsed date was automatically fomratted as UTC resulting
in a added time of 00:00:00.000+0000 which conflicts with the way the
date will be rendered through the UI.
This commit changes the date to only use the "pure" date format
(yyyy-MM-dd) without including any time and zone information.

GH-129
arcticicestudio added a commit that referenced this issue Mar 5, 2019
This allows to debug Gatsby's development build process like the
implemented Node APIs (`gatsby-node-js`) and the configuration
(`gatsby-config.js`).

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
This commit initially includes the `Image` (wraps `GatsbyImage`) and
`ShinkWidth` component placed in the new atom core package
`mdx-elements`.

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
This includes styled components like `PaperSheet` for a uniform docs
design. The `MDXProvider` has been configured to map custom HTML
components to default Markdown elements and a wrapper component for doc
pages has been implemented to define specific styles like "Inter UI"
font family.

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
Previously the parsed date was automatically fomratted as UTC resulting
in a added time of 00:00:00.000+0000 which conflicts with the way the
date will be rendered through the UI.
This commit changes the date to only use the "pure" date format
(yyyy-MM-dd) without including any time and zone information.

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
This allows to debug Gatsby's development build process like the
implemented Node APIs (`gatsby-node-js`) and the configuration
(`gatsby-config.js`).

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
To simplify the usage of common and uniform theme mode styles some have
been extracted into a new global `styles/shared` package that allows all
components ti import them.
There are also some "mixins" (functions) that can be used to customize
some dynamic/variable attributes of these styles.

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
The last remaining main page is `/blog` which presents an overview of
Nord's blog posts in a three-column grid of card components sorted
descending by their publish date. Each card consists of an cover image
together with the title of the post. The latest post spans over two
columns at the top for a nice visual structure and better
recognizability.
While a one-column card uses a cover image the latest post will use a
"banner" that will either be the same image with a larger width,
a variant of it or a completly different one.

A blog post itself makes use of the MDX features and the custom MDX
components mentioned in the paragraph above. To simplify the usage of
the "cover" and "banner" image they are be processed with Gatsby's
`onCreateNode` (1) API in combination with Gatsby's `mapping`
configuration feature (2). This allows to map the paths to the images
to a `File` node that will then be handled by the Gatsby image
processing plugin workflow (3) also documented in the commit about
image handling.

Another required node is the `heroImage` field that queries for a
`hero.(png|jpg|jpeg)` image that is used as the hero of a blog post.
To allow to also use videos in blog posts or even as header a custom
`Video` MDX component has been implemented including the optional
`heroVideo` and `heroVideoPoster` GraphQL node fields.

All together that results in the following required and optional
images/videos mapped to specific node fields with reserved file names
per blog post directory for simple usage via GraphQL queries:

- `bannerImage` <-> `banner.(png|jpg|jpeg)` - The required banner image
  of a blog post card (used when currently the latest two-column wide
  post placed on top of the grid).
- `coverImage` <-> `cover.(png|jpg|jpeg)` - The required cover image of
  a one-column blog post.
- `heroImage` <-> `hero.(png|jpg|jpeg)` - The required hero image of a
  blog post.
- `heroVideo` <-> `hero.(mp4|webm)` - The optional hero video of a blog
  post.
- `heroVideoPoster` <-> `heroposter.(png|jpg|jpeg)` - The optional
  poster image of a blog post `heroVideo`.

>>> Known Problems

To prevent the `unknwon field` GraphQL error during build time (4)
(e.g. when there are no blog posts yet) a "dummy"/"placeholder" blog
post and docs page will be created.
Anyway, this will be removed as soon as there is finally the first blog
post and docs page. Later on the project will migrate to the shiny new
schema customization API (5).

References:
  (1) https://www.gatsbyjs.org/docs/node-apis/#onCreateNode
  (2) https://www.gatsbyjs.org/docs/gatsby-config/#mapping-node-types
  (3) https://www.gatsbyjs.org/docs/working-with-images
  (4) gatsbyjs/gatsby#3344
  (5) https://www.gatsbyjs.org/blog/2019-03-04-new-schema-customization

GH-129
arcticicestudio added a commit that referenced this issue Mar 9, 2019
…ration-docs-blog

MDX Integration for docs and blog pages
@arcticicestudio arcticicestudio removed their assignment Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant