Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Added custom routes option
Browse files Browse the repository at this point in the history
  • Loading branch information
yashha committed Mar 20, 2020
1 parent ad4c54a commit 28415af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -103,6 +103,24 @@ module.exports = {

See more options in the extension [nuxtjs/sitemap](https://github.com/nuxt-community/sitemap-module) or in the following [file](https://github.com/yashha/wp-nuxt/blob/master/lib/module/sitemap.js)

## Custom Routes
You can register your own routes e.g. for custom extentions.

```js
module.exports = {
wp: {
endpoint: 'https://wp.kmr.io/wp-json',
customRoutes: [
{
extension: 'wp/v2',
route: 'custom-taxonomy',
name: 'customTaxonomy'
}
]
}
}
```
This will call `wp.customTaxonomy = wp.registerRoute('wp/v2','custom-taxonomy'` and make it available as `app.$wp.customTaxonomy()`

## Auto-Discovery

Expand Down
7 changes: 6 additions & 1 deletion lib/plugin.js
Expand Up @@ -4,7 +4,8 @@ import WPApi from 'wpapi'
import { registerWuxt } from 'wpapi-extensions'
<% } %>

let wp = new WPApi(<%= serialize(options) %>)
const options = <%= serialize(options) %>
let wp = new WPApi(options)


export default async (ctx, inject) => {
Expand All @@ -16,5 +17,9 @@ export default async (ctx, inject) => {
wp = await WPApi.discover('https://wp.kmr.io/wp-json');
<% } %>

options.customRoutes.forEach(element => {
wp[element.name] = wp.registerRoute(element.extension, element.route);
});

inject('wp', wp)
}
9 changes: 8 additions & 1 deletion test/fixture/nuxt.config.js
Expand Up @@ -12,7 +12,14 @@ module.exports = {
modules: [require('../../')],
wp: {
endpoint: 'https://wp.kmr.io/wp-json',
extensions: true
extensions: true,
customRoutes: [
{
extension: 'wp/v2',
route: 'custom-taxonomy',
name: 'customTaxonomy'
}
]
},
feed: [wpNuxtFeed()]
}

0 comments on commit 28415af

Please sign in to comment.