Skip to content

Commit 7fb52c6

Browse files
committed
Update README and MIGRATION
1 parent 27c1a68 commit 7fb52c6

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

Diff for: MIGRATION.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ Now that the field is a `string` field, the slash character is saved with the va
6262
'use strict';
6363

6464
module.exports = {
65-
async up( knex ) {
66-
const rows = await knex( 'pages' );
67-
68-
await Promise.all( rows.map( row => {
69-
return knex( uid )
70-
.where( { id: row.id } )
71-
.update( {
72-
slug: row.slug.replace( /~/g, '/' ),
73-
} );
74-
} ) );
65+
async up(knex) {
66+
const rows = await knex('pages');
67+
68+
const promisedUpdates = rows.map(row => {
69+
return knex(uid)
70+
.where({ id: row.id })
71+
.update({ slug: row.slug.replace(/~/g, '/') });
72+
});
73+
74+
await Promise.all(promisedUpdates);
7575
},
7676

7777
down() {},

Diff for: README.md

+40-33
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ yarn add strapi-plugin-permalinks@latest
3333
## <a id="custom-field"></a>✏️ Custom Field
3434
To get started, let's create a simple `Page` collection that uses a permalink field.
3535

36-
<img style="width: 960px; height: auto;" src="public/screenshot-page-schema.png" alt="Screenshot for Strapi permalinks plugin" />
36+
<div align="center">
37+
<img style="width: 960px; height: auto;" src="public/screenshot-page-schema.png" alt="Screenshot for Strapi permalinks plugin" />
38+
</div>
3739

3840
Use the "Custom" tab in the content type builder to add the permalink field to the model.
3941

40-
<img style="width: 960px; height: auto;" src="public/screenshot-content-type-builder.png" alt="Screenshot for Strapi permalinks plugin" />
42+
<div align="center">
43+
<img style="width: 960px; height: auto;" src="public/screenshot-content-type-builder.png" alt="Screenshot for Strapi permalinks plugin" />
44+
</div>
4145

4246
After adding a permalink field through the content type builder, there are additional `targetField` and `targetRelation` props that will need to be manually added to the permalink schema attribute.
4347

@@ -46,7 +50,6 @@ After adding a permalink field through the content type builder, there are addit
4650
#### Schema for `Page`
4751
```js
4852
// src/api/page/content-types/page/schema.json
49-
5053
{
5154
"kind": "collectionType",
5255
"collectionName": "pages",
@@ -119,7 +122,7 @@ module.exports = {
119122
config: {
120123
contentTypes: [
121124
{
122-
uids: [ 'api::page.page' ],
125+
uids: ['api::page.page'],
123126
},
124127
],
125128
},
@@ -147,7 +150,7 @@ module.exports = {
147150
],
148151
},
149152
{
150-
uids: [ 'api::help-page.help-page' ],
153+
uids: ['api::help-page.help-page'],
151154
},
152155
],
153156
},
@@ -172,7 +175,7 @@ In order to use the full permalink URL for the "Copy permalink" feature or to us
172175
// config/plugins.js
173176
'use strict';
174177

175-
module.exports = ( { env } ) => ( {
178+
module.exports = ({ env }) => ({
176179
permalinks: {
177180
config: {
178181
contentTypes: [
@@ -181,16 +184,16 @@ module.exports = ( { env } ) => ( {
181184
'api::page.page',
182185
'api::product-page.product-page',
183186
],
184-
url: `${env( 'STRAPI_PERMALINKS_BASE_URL' )}/{slug}`,
187+
url: `${env('STRAPI_PERMALINKS_BASE_URL')}/{slug}`,
185188
},
186189
{
187-
uids: [ 'api::help-page.help-page' ],
188-
url: `${env( 'STRAPI_PERMALINKS_BASE_URL' )}/help/{slug}`,
190+
uids: ['api::help-page.help-page'],
191+
url: `${env('STRAPI_PERMALINKS_BASE_URL')}/help/{slug}`,
189192
},
190193
],
191194
},
192195
},
193-
} );
196+
});
194197
```
195198

196199
#### Example with localization
@@ -203,7 +206,7 @@ With `i18n` enabled for the `slug` field, you can insert the `locale` into the p
203206
// config/plugins.js
204207
'use strict';
205208

206-
module.exports = ( { env } ) => ( {
209+
module.exports = ({ env }) => ({
207210
permalinks: {
208211
config: {
209212
contentTypes: [
@@ -218,19 +221,19 @@ module.exports = ( { env } ) => ( {
218221

219222
// Example with localized absolute URL and env vars.
220223
{
221-
uids: [ 'api::help-page.help-page' ],
222-
url: `${env( 'STRAPI_PERMALINKS_BASE_URL' )}/{locale}/help/{slug}`,
224+
uids: ['api::help-page.help-page'],
225+
url: `${env('STRAPI_PERMALINKS_BASE_URL')}/{locale}/help/{slug}`,
223226
},
224227

225228
// Another example with a different locale position.
226229
{
227-
uids: [ 'api::example.example' ],
230+
uids: ['api::example.example'],
228231
url: 'https://{locale}.example.com/{slug}',
229232
},
230233
],
231234
},
232235
},
233-
} );
236+
});
234237
```
235238

236239
> Notice how the `HelpPage` example has `/help/` prepending it's slug value, which already makes it unique against `Page` and `ProductPage`.
@@ -242,8 +245,8 @@ By using `{curly_braces}`, you can map values from the entry data into your perm
242245
243246
```js
244247
{
245-
uids: [ 'api::product-page.product-page' ],
246-
url: `${env( 'STRAPI_PERMALINKS_BASE_URL' )}/{locale}/{slug}`,
248+
uids: ['api::product-page.product-page'],
249+
url: `${env('STRAPI_PERMALINKS_BASE_URL')}/{locale}/{slug}`,
247250
}
248251
```
249252

@@ -252,8 +255,8 @@ The "Copy permalink" button located in the edit view sidebar can be disabled wit
252255

253256
```js
254257
{
255-
uids: [ 'api::page.page' ],
256-
url: `${env( 'STRAPI_PERMALINKS_BASE_URL' )}/{slug}`,
258+
uids: ['api::page.page'],
259+
url: `${env('STRAPI_PERMALINKS_BASE_URL')}/{slug}`,
257260
copy: false,
258261
}
259262
```
@@ -267,7 +270,7 @@ Defaults to `true`. It will ensure the permalink value is always lowercased.
267270
// config/plugins.js
268271
'use strict';
269272

270-
module.exports = ( { env } ) => ( {
273+
module.exports = ({ env }) => ({
271274
permalinks: {
272275
config: {
273276
lowercase: false,
@@ -276,7 +279,7 @@ module.exports = ( { env } ) => ( {
276279
],
277280
},
278281
},
279-
} );
282+
});
280283
```
281284

282285
#### Example migration script to lowercase existing permalinks
@@ -286,16 +289,16 @@ module.exports = ( { env } ) => ( {
286289
'use strict';
287290

288291
module.exports = {
289-
async up( knex ) {
290-
const rows = await knex( 'pages' );
291-
292-
await Promise.all( rows.map( row => {
293-
return knex( uid )
294-
.where( { id: row.id } )
295-
.update( {
296-
slug: row.slug.toLowerCase(),
297-
} );
298-
} ) );
292+
async up(knex) {
293+
const rows = await knex('pages');
294+
295+
const promisedUpdates = rows.map(row => {
296+
return knex(uid)
297+
.where({ id: row.id })
298+
.update({ slug: row.slug.toLowerCase() });
299+
});
300+
301+
await Promise.all(promisedUpdates);
299302
},
300303

301304
down() {},
@@ -313,11 +316,15 @@ Deleting an entity that has children will **orphan** those children. Strapi will
313316

314317
**If orphaned pages exist**, you will see their slug value in the content manager list view as a red label instead of plain text.
315318

316-
<img style="width: 960px; height: auto;" src="public/screenshot-orphan-index.png" alt="Screenshot for Strapi permalinks plugin" />
319+
<div align="center">
320+
<img style="width: 960px; height: auto;" src="public/screenshot-orphan-index.png" alt="Screenshot for Strapi permalinks plugin" />
321+
</div>
317322

318323
Editing the orphaned page will display a warning and an error message on the permalink field. From here you can assign a new parent or no parent at all. Upon saving, any children of the entity will also update their target fields to reflect to new parent permalinks.
319324

320-
<img style="width: 960px; height: auto;" src="public/screenshot-orphan-edit.png" alt="Screenshot for Strapi permalinks plugin" />
325+
<div align="center">
326+
<img style="width: 960px; height: auto;" src="public/screenshot-orphan-edit.png" alt="Screenshot for Strapi permalinks plugin" />
327+
</div>
321328

322329
## <a id="troubleshooting"></a>💩 Troubleshooting
323330

0 commit comments

Comments
 (0)