Allows you to create and edit URI for different ContentTypes.
A plugin for Strapi that allows you to create and edit URI for different ContentTypes.
Tested with Strapi 4.11.5
npm install strapi-plugin-custom-links
or
yarn add strapi-plugin-custom-links
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.
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'],
};
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.
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.
Field | Type | Unique | minLength | regExp | Description |
---|---|---|---|---|---|
id | biginteger | true | 1 | The id of the Custom-Link | |
uri | string | true | 1 | ^/[a-zA-Z0-9-_./]*$ | The uri of the Custom-Link |
kind | string | false | - | - | The uid of the ContentType associated |
contentId | biginteger | false | - | - | The id of the ContentType associated |
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)
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.
Method | URL | Description | Details |
---|---|---|---|
GET | /api/custom-links/proxy/:uri | Fetch the data of a Content-Type by its Custom-Link | By default components and relations are populate |
/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.
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.
Method | URL | Description | Details |
---|---|---|---|
GET | /api/custom-links | Fetch custom links | For more information see Strapi documentation |
POST | /api/custom-links | Create a custom-link | - |
GET | /api/custom-links/:id | Fetch one custom-link | - |
GET | /api/custom-links/count | Get the count of custom-links | - |
PUT | /api/custom-links/:id | Update a custom-link | - |
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.
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.
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
MIT License Copyright (c) la chose & Strapi Solutions.
npm install strapi-plugin-custom-links
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.