Strapi plugin logo for Custom Links

Custom Links

Allows you to create and edit URI for different ContentTypes.

thumbnail for Custom Links

Strapi logo

Strapi v4 - Custom Links

A plugin for Strapi that allows you to create and edit URI for different ContentTypes.

Tested with Strapi 4.11.5

🔌 Installation

npm install strapi-plugin-custom-links

or

yarn add strapi-plugin-custom-links

⚙️ Configuration

You can configure the plugin directly from the Strapi interface in developer mode.

Go to Settings > Custom-Links Plugin > Configuration

And add content-types you wish to associate Custom-Links and just save it.

plugin settings

NOTE

Alternatively, you can create the config file by your own, by creating a file custom-links.js inside the folder config of your strapi project.

The file looks like this :

./config/custom-links.js

1
2
3
4
5
'use strict';

module.exports = {
  contentTypes: ['api::mycontenttype.mycontenttype', 'api::othercontentype.othercontentype'],
};

✏️ Create and edit Custom-Links

From the Content Manager

When editing a Content-Type, you will find at the right section a Custom-Link block, in wich you can create or update a Custom-Link by editing the URI field.

plugin editing

From the Custom-Links plugin section

You will be able to retrieve the list of Custom-Links from Plugins > Custom-Links section.

In this section you can search, filter, update or delete Custom-Links.

admin-custom-links

⚡️ API

Schema

FieldTypeUniqueminLengthregExpDescription
idbigintegertrue1The id of the Custom-Link
uristringtrue1^/[a-zA-Z0-9-_./]*$The uri of the Custom-Link
kindstringfalse--The uid of the ContentType associated
contentIdbigintegerfalse--The id of the ContentType associated

Basic Usage

Note on proxy pattern

Our own use of this plugin is to only rely on the URI to request every content-type (the same way you would request a node with Drupal 8) then dynamically create a template according to the nature of the data returned. This is a pattern called proxy.

Since this plugin can be enabled only on a few content-types, we reckon that you might need to fetch the custom-link collection itself (see Alternative usage)

Endpoints

As we always try to stay as close as possible of the strapi default behavior and core concept while developing this plugin, we think that per URI request shouldn't be used with a GET parameters because they prevent the request to be cached by the browser and are harder to manage behind a CDN.

MethodURLDescriptionDetails
GET/api/custom-links/proxy/:uriFetch the data of a Content-Type by its Custom-LinkBy default components and relations are populate

Response

/api/custom-links/proxy/my-article-uri

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
  "data": {
    "id": 1,
    "attributes": {
      "title": "My article",
      "slug": "my-article",
      "createdAt": "2022-08-01T16:32:35.878Z",
      "updatedAt": "2022-08-01T16:32:35.878Z",
      "component": [
        {
          "id": 1,
          "text": "A component"
        }
      ],
      "content": [
        {
          "__component": "core.component",
          "id": 2,
          "text": "A dyn component"
        }
      ]
    }
  },
  "meta": {
    "meta": {
      "customLink": {
        "id": "1",
        "uri": "/my-article-uri",
        "kind": "api::article.article",
        "contentId": "1"
      }
    }
  }
}

As you can see on the previous example we inject customLink data inside the meta of the result. This can also be used to retrieve a specific custom-link as seen in the following part.

Alternative Usage

You can also use the custom-link classic CRUD which exposes the same endpoints as the strapi default controller.

By requesting a Custom-Link collection, you can retrieve the kind (the Content-Type uid) and the contentId (the id of the ContentType) and then request the Content-Type associated.

This can be useful if you need to know the target content-type before making the request.

Endpoints

MethodURLDescriptionDetails
GET/api/custom-linksFetch custom linksFor more information see Strapi documentation
POST/api/custom-linksCreate a custom-link-
GET/api/custom-links/:idFetch one custom-link-
GET/api/custom-links/countGet the count of custom-links-
PUT/api/custom-links/:idUpdate a custom-link-

🚧 Roadmap

We aim at providing a fully buffed plugin to leverage URI management and navigation issues in Strapi so it can become the true CMS it deserve. Here are a few ideas we will work on.

  • Initial Release
  • 💡 Keep working on stability
  • 💡 Better documentation with use case and frontend examples
  • 💡 Redirections (for SEO purpose)
  • 💡 Batch import for redirections
  • 💡 Custom field with autocompletion
  • 💡 And much more !

🤝 Feedback and issues

Feel free raise an issue for any bug, feedback or idea you might have

As we have a mono repo for any current and future plugin we are developing, please specify the plugin you are raising an issue for.

🚀 Strapi Services

We are a small french agency with a strong Web Performance ortiented technical team; We work mainly with Strapi, and other NodeJS CMS, and with React and VueJS. If you need any help to develop a Strapi app or website, a Strapi plugin, if you need any services in Web Performance, feel free to contact us at strapi@lachose.fr

📝 License

MIT License Copyright (c) la chose & Strapi Solutions.

Install now

npm install strapi-plugin-custom-links

STATS

5 GitHub stars45 weekly downloads

Last updated

284 days ago

Strapi Version

4.0.0 and above

Author

github profile image for @lachoseparis
@lachoseparis

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.