npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kentico-kontent-nuxt-module

v8.0.1

Published

Add Kentico Kontent super power to your nuxt app

Downloads

3,852

Readme

CircleCI semantic-release NPM

kentico-kontent-nuxt-module

Add Kentico Kontent super power to your nuxt app :fire:

Features

The module makes it easy to do delivery client api calls via the Kentico kontent Delivery JS SDK.

Quick start

  • Install via npm
npm i kentico-kontent-nuxt-module --save
  • Add kentico-kontent-nuxt-module to modules section of nuxt.config.js
  /*
  ** Nuxt.js modules
  */
  modules: [
    'kentico-kontent-nuxt-module'
  ],
  kenticokontent: {
    projectId: 'xxxx-xxx-xxxx-xxxx-xxxxx',
    enableAdvancedLogging: false,
    previewApiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    globalQueryConfig: {
			usePreviewMode: true, // Queries the Delivery Preview API.
      useSecureMode: false,
		},
    baseUrl: 'https://custom.uri/api/KenticoKontentProxy',
    secureApiKey: 'xxx',
    enableSecuredMode: true
  },

Note: See the client configuration section of the Kentico Kontent Delivery SDK for all available configuration options.

  • $nuxtDeliveryClient is now globally available.

 this.$nuxtDeliveryClient.items()
    .type('page')
    .toPromise()
    .then(response => console.log('DeliveryClient Response', response));

Note:

By default Nuxt can only work with promises. Therefor you always use the "toPromise" method provided by the Kentico Kontent Delivery SDK! RxJs operator's are not supported at the moment.

Typescript

Since version 7 the kentico-kontent-nuxt-module has typescript support!

Add the types to your "types" array in tsconfig.json after the @nuxt/types (Nuxt 2.9.0+) or @nuxt/vue-app entry


 {
  "compilerOptions": {
    "types": [
      "@nuxt/types",
      "kentico-kontent-nuxt-module"
    ]
  }
}

Generating

When using a static generated deployment you may need to use the items-feed endpoint when generating your site (because the items endpoint has a rate limitation).


 this.$nuxtDeliveryClient.itemsFeedAll()
    .toPromise()
    .then(response => console.log('DeliveryClient Response', response));

Caching

API calls can be "cached" (they will be stored in memory) client side via the "viaCache" method.


 const query =  this.$nuxtDeliveryClient.items().type('page');
 const cacheSeconds = 30;
 this.$nuxtDeliveryClient.viaCache(query, cacheSeconds)
        .then(response => console.log('DeliveryClient Response', response));

Extending

If you need to customize the Kentico Kontent Delivery SDK by registering interceptors and changing global config, you have to create a nuxt plugin.

nuxt.config.js

{
  modules: [
    'kentico-kontent-nuxt-module',
  ],

  plugins: [
    '~/plugins/kenticokontentNuxtModule'
  ]
}

plugins/kenticokontentNuxtModule.js

export default function ({ store, $nuxtDeliveryClient }) {
    $nuxtDeliveryClient.config.globalHeaders = (queryConfig) => {
        let headers = [];
        headers.push({header: 'Authorization', value: 'bearer ' + store.state.token });
        return headers;
      }
  }

Type Resolvers

Type resolvers can also be registered by using a nuxt plugin:

plugins/kenticokontentNuxtModule.js

import { TypeResolver, ContentItem } from '@kentico/kontent-delivery';

class Page extends ContentItem {
    constructor() {
        super({
            richTextResolver: (item, context) => {
                // todo: implement
            },
            urlSlugResolver: (link, context) => {
                // todo: implement
            }
        });
    }
}

export default function ({ store, app, $nuxtDeliveryClient }) {
    $nuxtDeliveryClient.config.typeResolvers = [
        new TypeResolver('page', () => new Page())
    ]
}