Skip to content

Commit

Permalink
fix: nester path generation & docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp3rius committed Oct 7, 2020
1 parent 386a7e4 commit 52d7f5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ To setup the plugin properly we recommend to put following snippet as part of `c

### Render

`GET <host>/navigation/<id>?type=<type>`
`GET <host>/navigation/render/<idOrSlug>?type=<type>`

Return a rendered navigation structure depends on passed type (`tree`, `rfr` or nothing to render as `flat/raw`).

*Note: The ID of navigation by default is `1`, that's for future extensions and multi-navigation feature.*

**Example URL**: `https://localhost:1337/navigation/1`
**Example URL**: `https://localhost:1337/navigation/render/1`

**Example response body**

Expand Down Expand Up @@ -201,7 +201,7 @@ Return a rendered navigation structure depends on passed type (`tree`, `rfr` or
]
```

**Example URL**: `https://localhost:1337/navigation/1?type=tree`
**Example URL**: `https://localhost:1337/navigation/render/1?type=tree`

**Example response body**

Expand Down Expand Up @@ -237,7 +237,7 @@ Return a rendered navigation structure depends on passed type (`tree`, `rfr` or
]
```

**Example URL**: `https://localhost:1337/navigation/1?type=rfr`
**Example URL**: `https://localhost:1337/navigation/render/1?type=rfr`

**Example response body**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-navigation",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Strapi - Navigation plugin",
"strapi": {
"name": "Navigation",
Expand Down
4 changes: 4 additions & 0 deletions services/__tests__/navigation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

describe('Dummy test', () => {
test('Dummy', () => { });
});
7 changes: 4 additions & 3 deletions services/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,17 @@ module.exports = {
switch (type) {
case renderType.TREE:
case renderType.RFR:
const itemParser = (item, path, field) => {
const itemParser = (item, path = '', field) => {
const isExternal = item.type === itemType.EXTERNAL;
const parentPath = isExternal ? undefined : `${path}/${item.path}`;
const parentPath = isExternal ? undefined : `${path === '/' ? '' : path}/${item.path === '/' ? '' : item.path}`;
const slug = isString(parentPath) ? slugify((first(parentPath) === '/' ? parentPath.substring(1) : parentPath).replace(/\//g, '-')) : undefined;
return {
title: item.title,
menuAttached: item.menuAttached,
path: isExternal ? item.externalPath : parentPath,
type: item.type,
uiRouterKey: item.uiRouterKey,
slug: isString(parentPath) ? slugify(parentPath.replace('/', '-')) : undefined,
slug: !slug && item.uiRouterKey ? slugify(item.uiRouterKey) : slug,
external: isExternal,
related: isExternal ? undefined : first(item.related),
audience: !isEmpty(item.audience) ? item.audience.map(aItem => aItem.key) : undefined,
Expand Down

0 comments on commit 52d7f5e

Please sign in to comment.