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

@ax2/multisite-module

v0.2.5

Published

Multisite features for your Nuxt project

Downloads

72

Readme

multisite-module

npm (scoped with tag) npm Dependencies Code Style

Multisite features for your Nuxt project

📖 Release Notes

Features

This module helps you bring multisite features to your Nuxt project. Here are the main features:

  • Current site detection based on host (or query string in development)
  • Contextual CSS vars declaration for site-specific theming
  • Contextual meta data

Setup

  • Install the module with your favorite package manager.
yarn add @ax2/multisite-module
# Or npm i @ax2/multisite-module
  • Add @ax2/multisite-module to modules section of nuxt.config.js.
// nuxt.config.js

{
  modules: [
    '@ax2/multisite-module',
 ],
}
  • Configure the module as needed by adding a multisite key to nuxt.config.js.
// nuxt.config.js

{
  multisite: {
  	// Module options
  }
}

Options

debug

  • Type: Boolean
  • Default: false

Set this to true to force the module to get the current site from the query string.

sites

  • Type: Array

List of sites.

{
  multisite: {
    sites: [
      {
        id: 'my-site',
        title: 'My awesome site',
        isDefault: true,
        hostPatterns: 'myawesomesite\.com,myincrediblesite\.(com|org)',
        cssVars: {
          '--primary-color': '#41B883',
          '--secondary-color': '#3B8070',
        },
        head: {
          link: [
            { rel: 'icon', type: 'image/x-icon', href: '/my-site/favicon.ico' },
          ],
        },
      },
    ],
  },
}

Each item in sites can have a few options of its own:

id

  • Type: Integer|String

The site's unique identifier.

isDefault

  • Type: Boolean

Wether this site should be considered as the default one. Any request that cannot be resolved to one of the sites will fallback to the default one.

hostPatterns

  • Type: String

A list of comma-separated patterns to test against requests host in order to enable this site in production.

cssVars

  • Type: Object

CSS vars that should be set when visiting this site.

head

  • Type: Object

This is the same as Nuxt's head property, options defined here are merged with the main head property definition.

NOTE: Functions are not supported here

Usage

Development

In development, switch from one site to another by adding a site query parameter to the URL. The value should be the site's ID as defined in the module's configuration. ie: http://127.0.0.1:8080/?site=my-site

Active site is stored in a cookie, so next time you visit http://127.0.0.1:8080, active site will be last used one.

Production

In production, active site is detected by matching request host against the patterns you defined in hostPatterns options. ie if you visit http://myawesomesite.com, my-site will be set as active site.

A $multisite property is added to the app's context, it contains a few helpers that you can use in any component.

Properties

site

  • Type: Object

The site property contains current site's configuration. You could use it to display the current site's title:

<template>
  <h1 class="site-title">
    {{ $multisite.site.title }}
  </h1>
</template>

Methods

asset

  • Arguments
    • {String} path: required
    • {Integer|String} site: optional, defaults to current site ID
  • Return: String

Get an asset's path for given site. If no site is specified, defaults to active site.

<template>
  <header>
    <img class="logo" :src="$multisite.asset('logo.png')">
    <!-- Renders to <img class="logo" src="/my-site/logo.png"> -->
  </header>
</template>

NOTE: It's recommended that you place site-specific assets in a directory named after the site's ID as defined in the module's options. Sites assets directories should be in the static/ directory.

License

MIT License

Copyright (c) Ax2 Inc.