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

vsf-lexascms

v0.4.3

Published

Official LexasCMS module for Vue Storefront (Next).

Downloads

10

Readme

Table of Contents

Installation

Please follow the below instructions to install vsf-lexascms in your Vue Storefront Next project.

1. Install the NPM package

Install the vsf-lexascms NPM package by running one of the following commands:

# Yarn
yarn add vsf-lexascms

# NPM
npm install vsf-lexascms

2. Configure the module

Add the vsf-lexascms Nuxt module to the buildModules section of your projects nuxt.config.js file:

export default {
  // ...

  buildModules: [
    // ...

    ['vsf-lexascms/nuxt']
  ]

  // ...
};

3. Configure middleware

Open the middleware.config.js file in the root of your project and add the following configuration:

module.exports = {
  integrations: {
    // ...

    lexascms: {
      location: 'vsf-lexascms/server',
      configuration: {
        spaceId: 'YOUR_SPACE_ID',
        apiKey: 'YOUR_API_KEY' // Optional, unless using content previews
      }
    }
  }
};

How To Use

Once you have installed the vsf-lexascms module, content can be retrieved using the useContent composable.

import { useContent } from 'vsf-lexascms';

const { search, content, loading, error } = useContent();
  • search is a function and is used for retrieving content from LexasCMS.
  • content, loading and error are all computed properties which are populated by the search method
    • content contains the content retrieved by the search method
    • loading is a boolean which communicates whether the search method is currently running or not
    • error is null unless an error is thrown by the search method, in which case this contains the error message

Fetching a collection

The following code snippet shows an example of how you could retrieve a collection of promo banners from LexasCMS.

import { useContent } from 'vsf-lexascms';

export default {
  setup() {
    const { search, content, loading, error } = useContent();

    await search({
      type: 'collection',
      contentType: 'promoBanners'

      // Optionally provide additional params, see supported parameters below
      // params: {
      //   
      // }
      //
      // Override the request context for this request, see the 'Request Context' section for more details
      // context: {
      //
      // }
    });

    return { content, loading, error };
  }
};

Supported parameters

As suggested in the code snippet above, you can also pass some additional parameters for making your queries more specific (e.g. filtering, localisation etc.).

| Name | Type | Required | Example | Comments | |-------------|--------|----------|---------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | fields | Object | N | { promoBanner: 'title,subtitle' } | See sparse fieldsets documentation for more info. | | filter | Object | N | { title: { _startsWith: 'Hello' } } | See filtering documentation for more info. | | include | String | N | backgroundImage | See fetching records documentation for more info. | | localeCode | String | N | en-GB | See localisation documentation for more info. | | page | Object | N | { limit: 2, skip: 4 } | See pagination documentation for more info. | | sort | String | N | title | See ordering documentation for more info. |

Fetching a single item

The following code snippet shows an example of how you could retrieve an individual promo banner from LexasCMS.

import { useContent } from 'vsf-lexascms';

export default {
  setup() {
    const { search, content, loading, error } = useContent();

    await search({
      type: 'item',
      contentType: 'promoBanner',
      itemId: 'example-promo-banner-id'

      // Optionally provide additional params, see supported parameters below
      // params: {
      //   
      // }
      //
      // Override the request context for this request, see the 'Request Context' section for more details
      // context: {
      //
      // }
    });

    return { content, loading, error };
  }
};

Supported parameters

As suggested in the code snippet above, you can also pass some additional parameters for making your queries more specific (e.g. localisation, pagination etc.).

| Name | Type | Required | Example | Comments | |-------------|--------|----------|------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | fields | Object | N | { promoBanner: 'title,subtitle' } | See sparse fieldsets documentation for more info. | | include | String | N | backgroundImage | See fetching records documentation for more info. | | localeCode | String | N | en-GB | See localisation documentation for more info. | | page | Object | N | { relationshipField: { limit: 2, skip: 4 } } | See pagination documentation for more info. |

Request Context

In the event that you would like to provide a request context with your requests to LexasCMS (i.e. for content personalisation), you can pass the context property to the search function.

The following snippet shows an example of setting the request context:

import { useContent } from 'vsf-lexascms';

export default {
  setup() {
    const { search, content, loading, error } = useContent();

    await search({
      type: 'collection',
      contentType: 'promoBanner',
      context: {
        audienceAttributes: {
          age: 25,
          location: 'GB'
        }
      }
    });

    return { content, loading, error };
  }
};

Supporting Content Previews

When making use of LexasCMS's visual content previews feature, LexasCMS will load your website with the lexascmsRequestContent query parameter.

The value of this parameter will be a pre-encoded request context, which should be provided directly to all requests to the Content Delivery API.

The following snippet shows an example of how this could be achieved:

import { useContent } from 'vsf-lexascms';

export default {
  setup(_, context) {
    const { search, content, loading, error } = useContent();

    await search({
      type: 'collection',
      contentType: 'promoBanner',
      context: context.root.$route.query.lexascmsRequestContext ?? null
    });

    return { content, loading, error };
  }
};

Full Example

The below code shows a full example of how you could create a small component which lists the available promo banners:

<template>
  <div id="promo-banners">
    <div v-if="loading">Loading promo banners...</div>
    <div v-if="error">Error loading promo banners!</div>
    <ul>
      <li v-for="promoBanner in promoBanners" :key="promoBanner.id">
        {{ promoBanner.title }}
      </li>
    </ul>
  </div>
</template>

<script>
import { useContent } from 'vsf-lexascms';
import { onSSR } from '@vue-storefront/core';

export default {
  name: 'PromoBanners',
  setup() {
    // useContent
    const { search, content, loading, error } = useContent();

    // Retrieve promo banners on server-side render only
    onSSR(async () => {
      await search({
        type: 'collection',
        contentType: 'promoBanner'
      });
    });

    // Return
    return {
      promoBanners: content,
      loading,
      error
    };
  }
};
</script>

Tutorials

Prefer a more guided tutorial? Check out our 3 part tutorial series using the links below:

License

This project is licensed under the MIT License.