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

prismic-receiver

v1.0.1

Published

library supporting communication with PRISMIC in pure NodeJS

Downloads

4

Readme

prismicReceiver

1 your prismic access:

Using v2 of prismic please add to your .env:

PRISMIC_APIURL=entry point for your API access
PRISMIC_TOKEN=permanent access tokens

Example:

PRISMIC_APIURL=https://REPOSITORY_NAME.cdn.prismic.io/api/v2
PRISMIC_TOKEN=WEDaerg3232tfWfawf32f4g2.SAd22d-44f-fef-_sadr23-433-454-4wq_we43c23-9Wd-_vUU454Cvv73vv73vv73vv70XGe-_ve-_ve-_ve-_ve-_vQ

2 Add prismic-receiver in your routers.js

const prismicReceiver = require('prismic-receiver');

3 How to use it?

In your routers.js:

// get all articles
router.all('/', async (req, res) => { 
  res.render('Index', await prismicReceiver.getAllArticle([API ID], [language], [pageSize], req) ); 
});

// get a specific article
router.all('/blog/:recordUid', async (req, res) => { 
  res.render('Article', await prismicReceiver.getArticle([API ID], req) ); 
});

// get specific page, next or prev page for articles (pagination for articles)
router.all('/page/:pageNumber', async (req, res) => { 
  res.render('Index', await prismicReceiver.getAllArticle([API ID], [language], [pageSize], req) ); 
});

// get all articles for a specific category
router.all('/category/:categoryName', async (req, res) => { 
  res.render('Category', await prismicReceiver.getByArticleCategory([API ID], [language], [pageSize], [API ID for category], [API ID Key Text field for category], req) ); 
});

// get all articles for a specific category using pagination to display specific page, next or prev page (pagination for category)
router.all('/category/:categoryName/page/:pageNumber', async (req, res) => { 
  res.render('Category', await prismicReceiver.getByArticleCategory([API ID], [language], [pageSize], [API ID for category], [API ID Key Text field for category], req) ); 
});
  • Routes Variable
    • pageNumber - variable specifying the number of displayed articles on the page
    • categoryName - variable specifying the name of the category
    • recordUid - variable specifying the unique ID name for the article (you definitely need to use UID in your articles in prismic)
  • Methods:
    • getAllArticle - access to all your articles from the given API ID
    • getArticle - selected specific article based on UID
    • getByArticleCategory - articles from the given API ID for specific category
  • Arguments:
    • API ID - your custom types name for API ID
    • language - the language you want to get data from
    • pageSize - how many artice you prefer for page
    • API ID for category - if you want to display categories, you must enter the custom types name for the category
    • API ID Key Text field for category - it's a filed name for Key Text of your category

Example:

// get all articles
router.all('/', async (req, res) => { 
  res.render('Index', await prismicReceiver.getAllArticle('article', 'en', 10, req) ); 
});

// get a specific article
router.all('/blog/:recordUid', async (req, res) => { 
  res.render('Article', await prismicReceiver.getArticle('article', req) ); 
});

// get specific page, next or prev page for articles (pagination for articles)
router.all('/page/:pageNumber', async (req, res) => { 
  res.render('Index', await prismicReceiver.getAllArticle('article', 'en', 10, req) ); 
});

// get all articles for a specific category
router.all('/category/:categoryName', async (req, res) => { 
  res.render('Category', await prismicReceiver.getByArticleCategory('article', 'en', 10, "article_category", "name", req) ); 
});

// get all articles for a specific category using pagination to display specific page, next or prev page (pagination for category)
router.all('/category/:categoryName/page/:pageNumber', async (req, res) => { 
  res.render('Category', await prismicReceiver.getByArticleCategory('article', 'en', 10, "article_category", "name", req) ); 
});

4 Now in your views you have access to data from prismic:

for example in ReactJS:

console.log(props.data);

5 Additional information: :grey_exclamation:

  1. axios and dotenv are demanding dependencies for the package to work properly,
  2. The articles are served according to the time of creation - DESC