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

strapi-plugin-paths

v0.0.12

Published

A way to fetch Strapi content, and create breadcrumbs based on front end urls.

Downloads

4

Readme

Paths

My initial thoughts

My thought was to create a plugin that has two content types, a category and a path. Since I originally wanted to use it to expose a rest endpoint to get content by url on the front-end, the focus was on the paths table. The idea here was to let plugin users select what content types the plugin should be used on, and then subscribe to create and update events for these types.

In the paths table the plugin stores the path (I will come back to this later), the model uid, the entity id and the publish state. (It also stores the entity title, but I forgot why, so will probably remove it). This enables me to query the endpoint for a path for a specific frontend url.

In the paths service, the plugin returns the entity that corresponds to the path (fetched by the model uid and entity id).

To create the paths for each entity, I just made it simple by creating a category that allows to create categories with a parent and children, along with a title and a slug. So when adding a category to an entity, the path should be generated from the category structure.

This was the original idea. But then I needed breadcrumbs, and that is why I have started adding a function to generate a json structure that holds the breadcrumb along side the path, model uid and entity id.

So an example of a path entity is:

{ 
  "model_uid": "api::article.article", 
  "entity_id": "38", 
  "json_category": [ 
    { 
      "name": "Vårt ansvar", 
      "slug": "berekraft" 
    }, 
    { 
      "name": "Dyrevern", 
      "slug": "berekraft/dyrevern" 
    } 
  ]
}

So, this was the original idea.

Path category

paths-paths-category

This is where the categories are created, and from which where the path and breadcrumbs are created

A Path category has a name, a slug, a parent and children.

Path category schema

{
  "kind": "collectionType",
  "collectionName": "pathscategories",
  "info": {
    "singularName": "pathscategory",
    "pluralName": "pathscategories",
    "displayName": "Paths category",
    "description": ""
  },
  "options": {
    "draftAndPublish": false
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string",
      "required": true
    },
    "slug": {
      "type": "string",
      "required": true
    },
    "parent": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "plugin::paths.pathscategory",
      "inversedBy": "children"
    },
    "children": {
      "type": "relation",
      "relation": "oneToMany",
      "target": "plugin::paths.pathscategory",
      "mappedBy": "parent"
    },
    "path": {
      "type": "customField",
      "customField": "plugin::paths.path"
    }
  }
}

Path

When creating or updating an entity like article or page, the path and breadcrumbs are created from the selected Path category and title and slug of the page or article. In the table, the path, entity ID together with the model uid and breadcrumbs json (json_category) is stored.

paths-create-entry Editing or creating an entity that has Paths activated on it

paths-paths List of paths created

Path schema

{
  "kind": "collectionType",
  "collectionName": "paths",
  "info": {
    "singularName": "path",
    "pluralName": "paths",
    "displayName": "Paths"
  },
  "pluginOptions": {
    "content-manager": {
      "visible": true
    },
    "content-type-builder": {
      "visible": true
    }
  },
  "options": {
    "draftAndPublish": false,
    "comment": ""
  },
  "attributes": {
    "path": {
      "type": "string"
    },
    "model_uid": {
      "type": "string"
    },
    "entity_id": {
      "type": "biginteger"
    },
    "entity_title": {
      "type": "string"
    },
    "json_category": {
      "type": "json"
    },
    "is_published": {
      "type": "boolean"
    },
    "category": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "plugin::paths.pathscategory"
    }
  }
}