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

gatsby-source-apostrophe

v1.0.1

Published

An ApostropheCMS source plugin for Gatsby

Downloads

4

Readme

gatsby-source-apostrophe

Source plugin for accessing ApostropheCMS 3.x content APIs in Gatsby

Install

npm install gatsby-source-apostrophe

How to use

  1. Review Gatsby documentation on using source plugins. 🤓
  2. Add an API key to the Apostrophe app to include as the apiKey option.
  3. Enter the Apos app root domain as the baseUrl option. For local development this will likely be http://localhost:3000.
  4. Add an array of the piece types (custom content types) you want available to Gatsby in the pieceTypes array.
// In your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-apostrophe`,
      options: {
        apiKey: 'my-apos-api-key',
        baseUrl: 'http://localhost:3000',
        pieceTypes: [
          '@apostrophecms/file',
          'my-piece-type'
        ]
      }
    }
  ]
}

Options

apiKey (required)

An ApostropheCMS API key with permissions to make GET requests. Read more about setting up API keys in the Apostrophe documentation.

baseUrl (required)

The base URL for API requests. Usually this will be the root domain of the Apostrophe website or application with no trailing slash. In local development it will be http://localhost:3000 by default.

pieceTypes

An array of Apostrophe piece type names. These will the same as the key name entered in the app.js modules object in the Apostrophe app. You may include core piece types that are not included by default, e.g, @apostrophecms/file, @apostrophecms/image-tag.

renderPages

Defaults to true. Set this to false to avoid an additional request for each Apostrophe page in order to add the page's rendered HTML to the AposCorePage nodes.

Notes

Naming

Apostrophe content node types in Gatsby's GraphQL API are all prefixed with Apos. So if you include your article piece type, it will appear in the GraphQL API as AposArticle nodes and the query collections will be aposArticle and allAposArticle.

Apostrophe core piece types and pages are prefixed AposCore. For example, including the core @apostrophecms/file piece type will create AposCoreFile nodes. Other scoped module names will be converted to pascal-case, removing punctuation, and prefixed with Apos. For example, @skynet/bad-robots and @skynet/badRobots will be converted to AposSkynetBadRobots.

Rendered content

Apostrophe "pieces" are well suited to being delivered as structured, JSON-like data. However, the power of Apostrophe really shines when editors build custom series of content widgets in "areas." Because areas can contain many types of widgets, and thus are not consistent in data structure, it is usually more useful to retrieve those from the APIs as rendered HTML.

Area fields on piece types will be available in the GraphQL queries with a _rendered property containing a string of rendered HTML. All other field types are delivered directly as their normal data types, e.g., strings, number, arrays, etc.

Rendered pages

Apostrophe pages usually consist primarily of these content "areas," populated with any number of different widget types. Unless you add renderPages: false to this source plugin's options, pages will appear with a _rendered property in Gatsby GraphQL queries. This property's value is a string of HTML, rendered using the relevant page template in the Apostrophe app. See the page API documentation for more specifics on what is rendered.

That HTML can be used in your Gatsby site to programmatically create pages using the right layout component and slug structure for your site.

If there are parts of the Apostrophe page templates that you do not want to include in the rendered response, you can wrap those in the following Nunjucks conditional (these requests include a ?headless=true parameter):

<!-- For example, in the Apostrophe site's `views/layout.html` -->
{% if not data.query.headless == 'true' %}
  <!-- Template wrapper you don't want in rendered responses. -->
{% endif %}

Planned features

  • A video player JS to support the Apostrophe core video widget in areas
  • Option for Apostrophe pages to automatically generate Gatsby pages
  • An option to make all piece types available in Gatsby GraphQL queries without naming them

License

gatsby-source-apostrophe is released under the MIT License.