npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@walltowall/gatsby-source-prismic-docs

v0.1.1

Published

Gatsby source plugin for building documentation for sites using Prismic as a data source

Downloads

6

Readme

@walltowall/gatsby-source-prismic-docs

Gatsby source plugin for Prismic slice documentation.

Gatsby source plugin for building documentation for sites using Prismic as a data source.

Table of Contents

Features

TODO

Install

npm install --save @walltowall/gatsby-source-prismic-docs

How to use

// In your gatsby-config.js
plugins: [
  /**
   * Gatsby's data processing layer begins with "source" plugins. Here the site
   * sources its data from your documentation files.
   */
  {
    resolve: '@walltowall/gatsby-source-prismic-docs',
    options: {
      /**
       * Provide an array of SliceDocumentation objects.
       */
      sliceDocumentations: [SliceDocumentation(/* ... */)],

      /**
       * Provide an array of CustomTypeDocumentation objects.
       */
      customTypeDocumentations: [CustomTypeDocumentation(/* ... */)],

      /**
       * Provide an array of LayoutDocumentation objects.
       */
      layoutDocumentations: [LayoutDocumentation(/* ... */)],

      /**
       * Provide an array of GuideGroup objects.
       */
      guideGroups: [GuideGroup(/* ... */)],
    },
  },
]

Documenting Slices

Slices are documented using the SliceDocumentation struct.

The markdown helper can be used when lengthier content is needed, such as the about field.

const {
  SliceDocumentation,
  SliceExample,
  textField,
  lorem,
  markdown,
} = require('@walltowall/gatsby-source-prismic-docs')

module.exports = SliceDocumentation({
  qualifiedName: 'PageBodyText',
  about: markdown`
About the slice
  `,
  relatedSlices: ['PageBodyImages'],
  examples: [
    SliceExample({
      name: 'Example name',
      data: ({
        heading = lorem('2w'),
        paragraphs = [lorem('40w'), lorem('30w'), lorem('50w')],
      }) => ({
        primary: {
          heading: textField(heading),
          text: textField(paragraphs.map(x => `<p>${x}</p>`).join('')),
        },
      }),
    }),
  ],
})

Providing examples

Slice examples are created using the SliceExample struct. These structs create mock data from Prismic in the shape the Slice expects.

The data field should be a function that returns mock Prismic data for the slice. The content of the examples can be configured using the function's first argument like the example above. These overrides may be useful when creating layout documentation.

The meta field should be a function that returns mock data for the meta object used in mapDataToProps and mapDataToContext in MapSlicesToComponents. Like the data field, the content of the example meta object can be configured using the function's first argument. These overrides may be useful when creating layout documentation.

Helpers are available to mock Prismic fields quickly.

  • textField: Creates a Structured Text field (i.e. Rich Text, Title).
  • linkField: Creates a link field. Usually used with no arguments to create a stub link.
  • imageFieldFluid: Creates an Image field with gatsby-source-prismic's Gatsby Image fluid builder.
  • lorem: Returns placeholder "Lorem ipsum" text.

Documenting Layouts

Layouts are documented using the LayoutDocumentation struct.

The markdown helper can be used when lengthier content is needed, such as the about field.

const {
  LayoutDocumentation,
  SliceExampleRef,
  SliceExampleGroup,
  markdown,
} = require('@walltowall/gatsby-source-prismic-docs')

module.exports = LayoutDocumentation({
  customType: 'page',
  name: 'Home',
  description: 'Short description',
  about: markdown`
About the layout.
  `,
  slicesMiddleware: (list = []) => [
    { __typename: 'PageBodyHeader' },
    ...list,
    { __typename: 'PageBodyFooter' },
  ],
  exampleGroups: [
    SliceExampleGroup({
      name: 'First section of the layout',
      description: markdown`
Description of the section.
      `,
      recommendedSlices: ['PageBodyText'],
      examples: [
        SliceExampleRef({
          qualifiedName: 'PageBodyText',
          exampleName: 'With heading',
          args: {
            heading: 'My cool page',
          },
        }),
      ],
    }),
    SliceExampleGroup({
      name: 'Second section of the layout',
      description: markdown`
Description of the section.
      `,
      recommendedSlices: ['PageBodyCallToAction'],
      examples: [
        SliceExampleRef({
          qualifiedName: 'PageBodyCallToAction',
          exampleName: 'With external link',
        }),
      ],
    }),
  ],
})

Providing example groups

Slice examples are combined to create an example layout using the SliceExampleGroup and SliceExampleRef structs.

The SliceExampleGroup struct groups one or more Slice examples and provides a description of their purpose.

The SliceExampleRef struct references an example from a given Slice using the Slice's qualified name and the example's full name. Arguments can be passed via the args and metaArgs fields to customize the mock data for the example.

If the layout requires MapSlicesToComponents list middleware, such as adding site-wide header and footer Slices, a middleware function can be provided to the slicesMiddleware field.

Documenting Custom Types

Custom types are documented using the CustomTypeDocumentation struct.

The markdown helper can be used when lengthier content is needed, such as the about field.

const {
  CustomTypeDocumentation,
  markdown,
} = require('@walltowall/gatsby-source-prismic-docs')

module.exports = CustomTypeDocumentation({
  apiId: 'page',
  description: 'Short description',
  about: markdown`
About the custom type.
  `,
  tabDescriptions: {
    main: 'Information about the page.',
    body: 'Content for the page.',
  },
  sliceZoneDescriptions: {
    main: 'Set metadata for the page.',
    body: "Build the page's content using Slices.",
  },
})

Documenting Guide Groups

Custom types are documented using the CustomTypeDocumentation struct.

const { GuidesGroup } = require('@walltowall/gatsby-source-prismic-docs')

module.exports = GuidesGroup({
  name: 'General',
  files: [
    path.join(__dirname, 'editing-content.md'),
    path.join(__dirname, 'publishing.md'),
  ],
})

How to query

You can query nodes created from your documentation files using GraphQL like the following:

Note: Learn to use the GraphQL tool and Ctrl+Spacebar at http://localhost:8000/___graphql to discover the types and properties of your GraphQL model.

{
  allPrismicDocsSlice {
    nodes {
      id
      qualifiedName
    }
  }
}

All documentation schemas are pulled from your plugin options and created as prismicDocs${nodeType} and allPrismicDocs${nodeType}, where ${nodeType} is one of the following:

  • Slice
  • SliceExample
  • SliceExampleGroup
  • ExampleData
  • Layout
  • CustomType
  • GuidesGroup

For example, if you want to get documentation for all custom types, you will be able to query for them like the following:

{
  allPrismicDocsCustomType {
    nodes {
      id
      displayName
    }
  }
}

Query Slice documentation

Query Layout documentation

Query Examples

Query Custom Type documentation

Query Guide Groups

Site's gatsby-node.js example

const path = require('path')

exports.createPages = async ({ graphql, actions }) => {
  const { createPage } = actions

  const sliceDocs = await graphql(`
    {
      allPrismicDocsSlice {
        nodes {
          id
          schema {
            name
          }
        }
      }
    }
  `)

  sliceDocs.data.allPrismicDocsSlice.nodes.forEach(node => {
    createPage({
      path: `/slices/${node.schema.name}`,
      component: path.resolve(__dirname, 'src/templates/slice.js'),
      context: {
        id: node.id,
      },
    })
  })
}