Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit 9c92844

Browse files
feat: init commit
0 parents  commit 9c92844

28 files changed

+1340
-0
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = false
6+
indent_style = tab
7+
indent_size = 2

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
$schema: 'https://json.schemastore.org/eslintrc',
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
10+
rules: {
11+
indent: ['error', 'tab'],
12+
'linebreak-style': ['error', 'unix'],
13+
quotes: ['error', 'single'],
14+
semi: ['error', 'always'],
15+
},
16+
globals: {
17+
strapi: 'readonly',
18+
},
19+
extends: ['eslint:recommended', 'plugin:node/recommended', 'prettier'],
20+
};

.gitattributes

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes
2+
3+
# Handle line endings automatically for files detected as text
4+
# and leave all files detected as binary untouched.
5+
* text=auto
6+
7+
#
8+
# The above will handle all files NOT found below
9+
#
10+
11+
#
12+
## These files are text and should be normalized (Convert crlf => lf)
13+
#
14+
15+
# source code
16+
*.php text
17+
*.css text
18+
*.sass text
19+
*.scss text
20+
*.less text
21+
*.styl text
22+
*.js text eol=lf
23+
*.coffee text
24+
*.json text
25+
*.htm text
26+
*.html text
27+
*.xml text
28+
*.svg text
29+
*.txt text
30+
*.ini text
31+
*.inc text
32+
*.pl text
33+
*.rb text
34+
*.py text
35+
*.scm text
36+
*.sql text
37+
*.sh text
38+
*.bat text
39+
40+
# templates
41+
*.ejs text
42+
*.hbt text
43+
*.jade text
44+
*.haml text
45+
*.hbs text
46+
*.dot text
47+
*.tmpl text
48+
*.phtml text
49+
50+
# git config
51+
.gitattributes text
52+
.gitignore text
53+
.gitconfig text
54+
55+
# code analysis config
56+
.jshintrc text
57+
.jscsrc text
58+
.jshintignore text
59+
.csslintrc text
60+
61+
# misc config
62+
*.yaml text
63+
*.yml text
64+
.editorconfig text
65+
66+
# build config
67+
*.npmignore text
68+
*.bowerrc text
69+
70+
# Documentation
71+
*.md text
72+
LICENSE text
73+
AUTHORS text
74+
75+
76+
#
77+
## These files are binary and should be left untouched
78+
#
79+
80+
# (binary is a macro for -text -diff)
81+
*.png binary
82+
*.jpg binary
83+
*.jpeg binary
84+
*.gif binary
85+
*.ico binary
86+
*.mov binary
87+
*.mp4 binary
88+
*.mp3 binary
89+
*.flv binary
90+
*.fla binary
91+
*.swf binary
92+
*.gz binary
93+
*.zip binary
94+
*.7z binary
95+
*.ttf binary
96+
*.eot binary
97+
*.woff binary
98+
*.pyc binary
99+
*.pdf binary

.github/workflows/npm-publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will publish a package to NPM when a release is created
2+
3+
name: Publish to NPM
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
publish-npm:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout branch
14+
uses: actions/checkout@v2
15+
16+
- name: Install Node v14
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '14.x'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- name: Install Yarn
23+
run: npm install -g yarn
24+
25+
- name: Clean install deps
26+
run: yarn install --frozen-lockfile
27+
28+
- name: Publish to NPM
29+
run: npm publish
30+
env:
31+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Don't check auto-generated stuff into git
2+
coverage
3+
node_modules
4+
stats.json
5+
6+
# Cruft
7+
.DS_Store
8+
npm-debug.log
9+
.idea

.npmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# npm
2+
npm-debug.log
3+
4+
# git
5+
.git
6+
.gitattributes
7+
8+
# vscode
9+
.vscode
10+
11+
# RC files
12+
.eslintrc.js
13+
.prettierrc.json
14+
15+
# ignore files
16+
.prettierignore
17+
.gitignore
18+
19+
# config files
20+
.editorconfig
21+
22+
# github
23+
.github

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock.json

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "http://json.schemastore.org/prettierrc",
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"semi": true,
6+
"singleQuote": true,
7+
"useTabs": true,
8+
"arrowParens": "always",
9+
"endOfLine": "lf",
10+
"printWidth": 100
11+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 @ComfortablyCoding
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# strapi-plugin-slugify
2+
3+
A plugin for [Strapi](https://github.com/strapi/strapi) that provides the ability to auto slugify a field for any content type. It also provides a findOne by slug endpoint as a utility.
4+
5+
## Requirements
6+
7+
The installation requirements are the same as Strapi itself and can be found in the documentation on the [Quick Start](https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html) page in the Prerequisites info card.
8+
9+
### Supported Strapi versions
10+
11+
- v4.x.x
12+
13+
**NOTE**: While this plugin may work with the older Strapi versions, they are not supported, it is always recommended to use the latest version of Strapi.
14+
15+
## Installation
16+
17+
```sh
18+
npm install strapi-plugin-slugify
19+
```
20+
21+
**or**
22+
23+
```sh
24+
yarn add strapi-plugin-slugify
25+
```
26+
27+
## Configuration
28+
29+
The plugin configuration is stored in a config file located at `./config/plugins.js`.
30+
31+
A sample configuration
32+
33+
```javascript
34+
module.exports = ({ env }) => ({
35+
slugify: {
36+
enabled: true,
37+
config: {
38+
contentTypes: {
39+
article: {
40+
field: 'slug',
41+
references: 'title',
42+
},
43+
},
44+
},
45+
},
46+
});
47+
```
48+
49+
This will listen for any record created or updated in the article content type and set a slugified value for the slug field automatically based on the title field.
50+
51+
**IMPORTANT NOTE**: Make sure any sensitive data is stored in env files.
52+
53+
### The Complete Plugin Configuration Object
54+
55+
| Property | Description | Type | Default | Required |
56+
| -------- | ----------- | ---- | ------- | -------- |
57+
| contentTypes | The Content Types to add auto slugification and search findOne by slug search utility to | Object | {} | No |
58+
| contentTypes[modelName] | The model name of the content type (it is the `singularName` in the [model schema](https://docs.strapi.io/developer-docs/latest/development/backend-customization/models.html#model-schema)) | String | N/A | Yes |
59+
| contentTypes[modelName]field | The name of the field to add the slug | String | N/A | Yes |
60+
| contentTypes[modelName]references | The name of the field that is used to build the slug | String | N/A | Yes |
61+
| slugifyOptions | The options to pass the the slugify function. All options can be found in the [slugify docs](https://github.com/sindresorhus/slugify#api) | Object | {} | No |
62+
63+
## Usage
64+
65+
Once the plugin has been installed, configured and enabled the configured content types will have the following additional functionality
66+
67+
### Slugification
68+
69+
Any time the respective content types have an entity created or updated the slug field defined in the settings will be auto generated based on the provided reference field.
70+
71+
### Find One by Slug
72+
73+
Hitting the `/api/slugify/slugs/:modelName/:slug` endpoint for any configured content types will return the entity type that matches the slug in the url.
74+
75+
#### Additional Requirements
76+
77+
Like all other created API endpoints the `findSlug` route must be allowed under `User & Permissions -> Roles -> Public/Authenticated` for the user to be able to access the route.
78+
79+
#### Example Request
80+
81+
Making the following request with the sample configuration will look as follows
82+
83+
```js
84+
await fetch(`${API_URL}/api/slugify/slugs/article/lorem-ipsum-dolor`);
85+
// GET /api/slugify/slugs/article/lorem-ipsum-dolor
86+
```
87+
88+
#### Example Response
89+
90+
If an article with the slug of `lorem-ipsum-dolor` exists the reponse will look the same as a single entity response
91+
92+
```json
93+
{
94+
"data": {
95+
"id": 1,
96+
"title": "lorem ipsum dolor",
97+
"slug": "lorem-ipsum-dolor",
98+
"createdAt": "2022-02-17T01:49:31.961Z",
99+
"updatedAt": "2022-02-17T03:47:09.950Z",
100+
"publishedAt": null
101+
}
102+
}
103+
```
104+
105+
**IMPORTANT NOTE** To be inline with Strapi's default behaviour for single types if an article with the slug of `lorem-ipsum-dolor` does not exist a 404 error will be returned.
106+
107+
```json
108+
{
109+
"data": null,
110+
"error": { "status": 404, "name": "NotFoundError", "message": "Not Found", "details": {} }
111+
}
112+
```
113+
114+
## Bugs
115+
116+
If any bugs are found please report them as a [Github Issue](https://github.com/ComfortablyCoding/strapi-plugin-slugify/issues)

0 commit comments

Comments
 (0)