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

@tamperan/zerocms

v0.0.3

Published

JS client library for the zeroCMS headless content management platform

Downloads

2

Readme

zerocms

zeroCMS is a headless/decoupled CMS focused on fast and easy editing, and straightforward integration into your development processes. Find out more at https://zerocms.dev

This library wraps the content serving API for easier consumption in Javascript-based apps and web sites. For documentation on what all the configuration options and doc fields mean see the online docs at https://zerocms.dev/integrations

If you use React or Vue, try one of the framework-specific libraries for better integration with your UI framework.

Note: This library is written in Typescript, and Typescript bindings are included.

Getting started

Install

First, install the package with npm or yarn:

npm i @tamperan/zerocms

The zeroCMS object

To retrieve content, you'll need a zeroCMS object. You can have many of these if you need to pull from multiple repos, but in most cases you'll just need one.

Before you start, you'll need a repo in zeroCMS and you'll need to know its 'slug' - which you will have chosen when creating the Repo and is displayed in the Deploy section in the UI.

import {ZeroCMS, create} from "@tamperan/zerocms";

const options = {
    dev: false, // set to true in dev mode for console log output when content is retrieved
    region: 'us',
    repo: 'my_repo_slug',
    //target: '_',  - set this if you approve/publish to a specific Target for your UI
    locale: 'en', // fetch content in this locale
}

const zerocms = create(options);

Retrieving content

Content is retrieved asynchronously, so the get() method returns a Promise.

If your repo has a doc type with slug pages and a doc with slug about-us then the following can be used to retrieve the document:

zerocms.get('pages', 'about-us').then(res => {
    // the result - res - will be a Doc object
})

Of course you should also catch() as well, in case of connectivity errors or accidentally providing non-existent doc slugs.

Displaying content

Once you have retrieved a Doc object, you can interrogate it for renderable content.

The elements property will contain an ordered array of the structured content elements in the doc; e.g. plaintext, richtext, image or video elements. Iterate through these to render them to your UI.

See https://zerocms.dev/integrations for documentation on all the elements.

Internal links

Note that internal links, i.e. links from one doc to another, will have a data-slug property that references the doc being linked to.

If your repo is configured to allow internal/doc links, then you will need to interpret and handle these references to implement appropriate navigation from doc to doc in your UI.