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

gridsome-source-directus

v0.1.2

Published

Gridsome Source Plugin to load data from Directus CMS

Downloads

28

Readme

gridsome-source-directus

Gridsome Source Plugin to load data from Directus CMS, download images and files.

Install

  • yarn add gridsome-source-directus
  • Add .cache-directus to the .gitignore file, if you don't want to check in your downloaded files and images to git.

OR

  • npm install gridsome-source-directus
  • Add .cache-directus to the .gitignore file, if you don't want to check in your downloaded files and images to git.

Usage

Add the plugin to your gridsome.config.js file.

Example configuration:

module.exports = {
  plugins: [
    {
      use: 'gridsome-source-directus',
      options: {
        apiUrl: 'YOUR_API_URL',
        project: 'YOUR_PROJECT_NAME OR _ FOR THE DEFAULT PROJECT',
        email: 'EMAIL_OF_DIRECTUS_USER',
        password: 'PASSWORD_OF_DIRECTUS_USER',
        collections: [
          {
            name: 'posts',
            status: 'published',
            fields: '*.*',
            downloadImages: true
          },
          {
            name: 'articel',
            hasRoute: true,
            fields: '*.*.*',
            downloadFiles: true
          },
          {
            name: 'products',
            directusPathName: '`directusproducts',
            route: '/product/:slug',
            fields: '*.*.*'
          }
        ]
      }
    }
  ]
}

Authenticication

You have to create a directus user with the correct access rights (read) for the collections you want to fetch.

Simply add the email and password to the plugin options and the plugin will login via the credentials.

Fetching the collections

To fetch your collections, you have mutiple options. Each collection is an object in the collections array of the plugin options.

It can have the following properties:

  • name - The name of the collection (in Directus)
  • fields - The fields directus should load
  • hasRoute (optional) - If set to true, Gridsome will create a page from the data (with the schema collection-name/:slug). See Templates for mor information
  • directusPathName (optional) - If you want to have a different name in Gridsome, you can specify a directusPathName (collection name). This is handy, if you want to load data twice (e.g. for easy translation).
  • route (optional) - If set, Gridsome will create pages with this route schema.
  • downloadImages (optional) - If set to true, Gridsome will download all images from the collection. It will add the internal path to a new field gridsome_image in the image. You can use the Gridsome image processing.
  • downloadFiles (optional) - If set to true, Gridsome will download all fiels from the collection. It will add the internal path to a new field gridsome_link in the file.

Additionaly you can add aditional query parameters that are getting past along to directus. See the official Directus documentation for mor info