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-menu

v0.1.1

Published

Generate hierarchical menus.

Downloads

4

Readme

Gridsome menu source plugin

This Gridsome plugin will source infinitely nested 'menu' data.

Install

yarn add gridsome-source-menu

Or

npm install --save gridsome-source-menu

Usage

The plugin is currently limited to working with JSON sources with the following schema:

{
  "name": "Main menu",
  "id": "main",
  "links": [
    {
      "link": {
        "title": "Horses",
        "url": "/horses"
      },
      "children": [
        {
          "link": {
            "title": "Mustang",
            "url": "/horses/mustang"
          }
        },
        {
          "link": {
            "title": "Pony",
            "url": "/horses/pony"
          }
        }
      ]
    },
    {
      "link": {
        "title": "Dinosaurs",
        "url": "/dinosaurs"
      }
    }
  ]
}

If the above JSON was placed in a file at src/content/menu/main.json then the plugin could be configured as follows in your girdsome.config.js:

module.exports = {
  plugins: [
    {
      use: 'gridsome-source-menu',
      options: {
        path: 'src/content/menus/**/*.json'
      }
    }
  ]
}

You could then query the menu data from your components using:

{
  menu(id: "main") {
    name
    links {
      url
      title
      order
      children {
        url
        title
      }
    }
  }
}

Which would produce the following result:

{
  "data": {
    "menu": {
      "name": "Main menu",
      "links": [
        {
          "url": "/horses",
          "title": "Horses",
          "order": 0,
          "children": [
            {
              "url": "/horses/mustang",
              "title": "Mustang"
            },
            {
              "url": "/horses/pony",
              "title": "Pony"
            }
          ]
        },
        {
          "url": "/dinosaurs",
          "title": "Dinosaurs",
          "order": 1,
          "children": []
        }
      ]
    }
  }
}

Netlify CMS

Netlify CMS can be easily configured to produce the menu data in the format expected by this plugin:

backend:
  name: git-gateway
media_folder: "static/images/uploads"
public_folder: "/images/uploads"
collections:
  - label: "Menus"
    name: "menus"
    folder: "src/content/menus"
    format: json
    create: true
    link_field: &link_field
      label: Link
      name: link
      widget: object
      fields:
        - {label: "Title", name: "title", widget: "string", hint: "The text that will become a link"}
        - {label: "URL", name: "url", widget: "string", hint: "e.g. /about or https://www.example.com"}
    fields:
      - {label: "ID", name: "id", widget: "string", required: true}
      - {label: "Name", name: "name", widget: "string", required: true}
      -
        label: "Links"
        name: "links"
        widget: "list"
        collapsed: false
        fields:
          - *link_field
          - label: "Child links"
            name: "children"
            widget: "list"
            field: *link_field