Code Monkey home page Code Monkey logo

gatsby-mdx-suite's Introduction

Repository archived

This project was much fun to explore, but it is time to move on. I leave this available as a reference for using Gatsby with MDX v1 & Contentful. If you want to implement MDX to a project, make sure to check out the Gatsby docs about MDX, which will stay up to date: https://www.gatsbyjs.com/docs/mdx/


Gatsby MDX Suite

This collection of packages provides a drop in solution to support MDX in your GatsbyJS content workflow.

The intention is to provide a feature rich but fully custimizable set of components ready to use for your authors.

πŸš€ Start right away using our GatsbyJS starter

Core features

Implemented features

  • Fully customizable, extend and alterable MDX components. You can modify them by shadowing, overwriting the theme and style them via emotion and tailwindCSS.
  • Simple MDX tag structures to keep editing simple.
  • Full integration with Contentful
  • Build with Gatsby themes for fast integration into your GatsbyJS project
  • A starter to get set up a new Gatsby MDX project within minutes.
  • Full i18n integration with helpers to easily create menus and a language switcher.
  • No to much crazy magic besides MDX. Components are often a few DOM elements with css applied or just a wrapper around a common React package.
  • Automated generation of documentation of all components used within the system. Provides basic information about Markdown and MDX as well. Demo: https://gatsby-mdx-suite-example-full.netlify.app/docs
  • Components to render Menus, Links, Language Switch & more.
  • GDPR/DSGVO compatability. Your visitors have full control over data flow and analytics. Nothing is sent outside if they don't give consent. You can adjust the behavior and style of the privacy manager. Demo: https://gatsby-mdx-suite-example-full.netlify.app/
  • Online MDX editor per project, get real time previews of your MDX. Demo: https://gatsby-mdx-suite-example-full.netlify.app/docs/playground

Work in progress features

Core dependencies

  • React using mostly the hooks API & contexts
  • GatsbyJS with themes -> Emotion & tailwindcss via twin.macro
  • Internationalization support via i18next
  • Optional support for menu rendering, icons, themes, color sets, ...

Project structure

  • GastbyJS themes: ./themes/* or gatsby-theme-mdx-suite-*
    • gatsby-theme-mdx-suite-core:
      • Has some required configuration opions!
      • Connects to Contentful
      • Integrates MDX into your project
      • Initializes the MDX data context and i18next
      • Integrates i18next & emotion
    • gatsby-theme-mdx-suite-base: Adds default components to MDX (https://github.com/axe312ger/gatsby-mdx-suite/blob/master/themes/base/src/gatsby-plugin-theme-ui/components.js)
      • Adds SVG support
      • Adds SEO plugins (Sitemap, Helmet, ...)
      • Adds Icons support
    • gatsby-theme-mdx-suite-docs:
      • Enables /docs with MDX playground, components documentation and theme overview
    • gatsby-theme-mdx-suite-base:
      • Adds a blog to the page with proper pagination, back to the news button, ...
      • Some example blog posts
  • MDX components: ./mdx/* or @gatsby-mdx-suite/mdx-*
    • Basic - Very basic stuff like images and links
    • Layout - Add visual structure to the content. Grids, columns and more.
    • Contentful - Useful components when using Contentful as CMS
    • Bandcamp/Instagram/YoutTube - Render social media content like videos, posts, tracks and whole feeds
    • Media - A media gallery lightbox component which supports mixed content
    • More... ?
  • Helper packages: ./packages/* or @gatsby-mdx-suite/*
    • Contexts: Important and required package. Provides the contexts to get data available within MDX
    • i18n: Helpers to generate paths and render language switch component
    • seo: SEO helper components
    • menu: generate single menu levels or whole menu trees
  • Examples: ./starters/*
    • Minimal:
      • Integrates required core theme: gatsby-theme-mdx-suite-core
      • Just a minimal selection of MDX components
      • Minimal default styling
    • Base:
      • Features of minimal plus:
      • Enables optional base theme: gatsby-theme-mdx-suite-base
      • Simple demo content
      • Some more default styling
      • Enabled optional video support
      • Includes the docs
    • Full:
      • Features of base plus:
      • Complex demo content
      • Demonstrates how to shadow components
      • Enabled optional blog theme gatsby-theme-mdx-suite-blog
      • Additional theme overwrites

Getting started

Either go for one of the starters and start hacking.

Or integrate the gatsby-theme-mdx-suite like the starters do into your project.

Or wait till somebody found time to write a tutorial how to do it.

Automated documentation

Within the /docs route a documentation apge will be generated. This provides:

  • Provide an introduction to Markdown and MDX to help new users getting into editing
  • Give an overview of all components integrated into the project
  • Renders interactive playgrounds for all components, including a list of available attributes.
  • Provides further information for developers:
    • Which data needs to be available for rendering?
    • Any extra information on how to alter and customize the components.
    • ...?

The problem of availability of data within MDX

  • Data needs to be available within MDX but is queried via static graphQL (#7)
  • The data layer needs to provide information which assets/data is used within MDX (#8)

Configuration

The most accurate documentation are the starters. Especially https://github.com/axe312ger/gatsby-mdx-suite/tree/master/starters/contentful.

Integrate into your project

Note: This is outdated. Have a look at the examples in /examples

This is just a quick listing, the whole readme will be improved soon and a getting starting guide provided.

How to alter the design

The idea is to support these options to alter the design:

Currently possible

gatsby-mdx-suite's People

Contributors

axe312ger avatar dependabot[bot] avatar renovate-bot avatar zcei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

techboi mac-mann

gatsby-mdx-suite's Issues

Replace mdx asset link resolver / parser with Contentful references

The approach of automatically parsing asset ids from MDX is to complicated to maintain. We should replace this technique via Contentful:

  • New ContentType "MediaReference". Fields:
    • Asset ID
    • Asset context (to determine how it will be rendered)

Our custom editor / field UI extension could fill the field for the user. Investigation is need how to achieve this properly.

See: https://github.com/axe312ger/gatsby-mdx-suite/blob/master/gatsby-theme-mdx-suite/gatsby-node.js#L22-L54

Github Actions: Add action that checks for dependency issues

While developing, you can accidentally use dependencies from other packages. This works fine on your machine, but as soon your publish this, it might cause issus in other people projects

For this we already have the npm run check-dependencies script in the root package.

  • create a action that executes that script
  • exclude starters + theme or go crazy and add gatsby support to depcheck

Docs: Add playground page

Add a playground to test and edit MDX

  • create subpage in docs
  • inline live editor fullscreen
  • add useful default content

Add notification / modal when service worker loaded new version

It can be very confusing, especially for clients, when the website needs time x (depending on the size of the new page payload) till they can reload to see new changes

We can improve the experience via:

Introduce horizontal gap theme sizing

To allow container elements like viewport, section and so on have the same distance to each other, they should share the same theme config variable.

Add dev docs page to document creation of new MDX components

Add a page to the website that explains how to:

  • write custom components and add it to your project
  • how to parse and access asset referenced within the MDX source
  • explain how we parse components for docs
    • react-docgen
    • MDX support for all descriptions
    • Uses @example doclet to parse examples
    • List available tokens (randomImageId, ...)

speed up docs asset generation

  • reduce image resolutation
  • use superfast preset for videos
  • limit number of assets being prepared for the docs rendering

Rework <Grid /> & <Columns /> Component

As we have tailwind css now available, reworking these components is pretty straight forward.

columns will become , with smart but not-configurable adaptive behavior. We can simply use https://tailwindcss.com/docs/grid-template-columns

grid becomes a advanced, configurable, wrapping css grid wrapper with configurable adaptive behavior (users basically pass value for grid-template-rows && grid-template-columns)

implement color modes

theme ui supports color modes out of the box, change the default theme to use all (useful) features of this

https://theme-ui.com/color-modes/

  • add color mode switch to docs
  • how do our color sets behave with this?
  • add default dark mode
  • add option to automatically switch to dark mode
  • consider colorblind / a11y mode

implement color modes

theme ui supports color modes out of the box, change the default theme to use all (useful) features of this

https://theme-ui.com/color-modes/

  • add color mode switch to docs
  • how do our color sets behave with this?
  • add default dark mode
  • add option to automatically switch to dark mode
  • consider colorblind / a11y mode

Docs: Make editor optional

When scrolling the kitchen sync, the editor takes up a lot of space.

  • make the editor optional by added a toggle to show/hide it

extend docz to support multiple root/src dirs

Allow components from node_modules, yarn workspace projects and src directory

That way we can have:

  • project specific components
  • community repo components
  • it will work within this mono repo and other lerna/yarn workspace repos

Check windows support

Goal is to support windows out of the box, there are several smaller and bigger issues yet, here is a incomplete list:

  • using env vars POSIX still does not work on default windows termin
  • ...? more!?

Get rid of work arounds

The goal is to just nicely glue other projects together, workarounds should be removed on mid-term, preferably by contribution to other projects.

For now:

Add user friendly prop-type validations

Additionally to the common prop-types package, we could support and implement airbnb's version. It adds a lot of useful propTypes that allow us give users more context about what is possible. Even validation while editing should be possible.

https://github.com/airbnb/prop-types

These could be especially useful:

  • and: ensure that all provided propType validators pass
    • foo: and([number, nonNegativeInteger])
  • between: provide an object with an gt or gte number, and an lt or lte number (only one item allowed from each pairs; one or both pairs may be provided), and the resulting propType validator will ensure the prop value is a number within the given range. Alternatively, you can provide a function that takes the props object and returns a number for each of the gt/gte/lt/lte values.
    • foo: between({ gte: 0, lte: 5 })
    • foo: between({ gt: 0, lt: 5 })
  • elementType: require that the prop be a specific type of React element - takes a Component, an HTML tag name, or "*" to match everything.
    • foo: elementType('span')
    • foo: elementType(Component)
  • numericString: require the prop be a string that is conceptually numeric.
    • foo: numericString()
  • or: recursively allows only the provided propTypes, or arrays of those propTypes.
    • foo: or([bool.isRequired, explicitNull()])
  • range: provide a min, and a max, and the prop must be an integer in the range [min, max)
    • foo: range(-1, 2)
  • stringEndsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that ends with it.
    • foo: stringEndsWith('.png')
  • stringStartsWith: takes a non-empty string, and returns a validator that ensures the prop value is a string that starts with it.
    • foo: stringStartsWith('prefix-')
  • valuesOf: a non-object requiring PropTypes.objectOf. Takes a propType validator, and applies it to every own value on the propValue.
    • foo: valuesOf(number)

merge location & mdx data context

Probably name it pageContext as it will contain all relevant data to render the current page.

As the current page already has the active locale in its context, we can drop LocationContext completely.

Structure:

const {
...pageContext, // contains gatsbys pageContext values
data // contains data required to render MDX components
} = useContext(PageContext)

Simplify env variable structure

currently we always have contentful access && preview token in all environments available.

its enough to just have an access token that changes and switch the api url in the contentful source plugin

  • get ride of the preview token env variable
  • refactor so we support gatsby cloud setup without requiring to alter proposed env var config

Docs: Add MD(X) editing basics

Many people are familar with Markdown, a few with HTML/XML, very little with MDX.

Give some basic instructions in the docs how to use the MDX data format as an author.

Provide information about:

  • headlines && paragraphs
  • text formatting
  • lists
  • images
  • linking
  • structure / MDX
  • Explain why the empy line is needed to switch context

Do not rely on optional source plugins

Currently, the code will break when the user will remove the video, youtube or instagram integration.

This is because the docs gather dummy information for all possible data formats to allow assets being used within the live editor.

  • Use gatsby schema customization to add dummy types when source plugins are not enabled

Refactor <MediaGallery />

  • make sure all core media components are properly supported, especially new video
  • check if we can properly detect and render smaller thumbnails for component

add option to skip rendering docs on production

The theme should have an option to skip rendering the docs on production environments.

Why?

This can speed up bundeling massively since the @mdx-js/runtime takes a while to be packed into the docs sub bundle.

Note: User should be able to control the rendering condition as everybody has their own prod/live/staging/whatever setup

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.