strapi-plugin-custom-links
v0.3.0
Published
Create Custom-Links for your ContentTypes.
Downloads
168
Readme
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.
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
'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.
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.
⚡️ API
Schema
| 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 |
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.
| 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 |
Response
/api/custom-links/proxy/my-article-uri
{
"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
| 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 | - |
🚧 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 [email protected]
📝 License
MIT License Copyright (c) la chose & Strapi Solutions.