0.2.1 • Published 6 years ago
prismic-reciver-test v0.2.1
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 pagecategoryName
- variable specifying the name of the categoryrecordUid
- 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 IDgetArticle
- selected specific article based on UIDgetByArticleCategory
- articles from the given API ID for specific category
- Arguments:
API ID
- your custom types name for API IDlanguage
- the language you want to get data frompageSize
- how many artice you prefer for pageAPI ID for category
- if you want to display categories, you must enter the custom types name for the categoryAPI 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:
axios
anddotenv
are demanding dependencies for the package to work properly,- The articles are served according to the time of creation -
DESC
0.1.60
6 years ago
0.2.1
6 years ago
0.1.55
6 years ago
0.1.56
6 years ago
0.1.57
6 years ago
0.1.58
6 years ago
0.1.52
6 years ago
0.1.53
6 years ago
0.1.51
6 years ago
0.1.50
6 years ago
0.1.12
6 years ago
0.1.13
6 years ago
0.1.14
6 years ago
0.1.49
6 years ago
0.1.41
6 years ago
0.1.42
6 years ago
0.1.43
6 years ago
0.1.44
6 years ago
0.1.45
6 years ago
0.1.46
6 years ago
0.1.47
6 years ago
0.1.48
6 years ago
0.1.40
6 years ago
0.1.38
6 years ago
0.1.39
6 years ago
0.1.30
6 years ago
0.1.31
6 years ago
0.1.32
6 years ago
0.1.33
6 years ago
0.1.34
6 years ago
0.1.35
6 years ago
0.1.36
6 years ago
0.1.37
6 years ago
0.1.27
6 years ago
0.1.28
6 years ago
0.1.29
6 years ago
0.1.20
6 years ago
0.1.21
6 years ago
0.1.22
6 years ago
0.1.23
6 years ago
0.1.24
6 years ago
0.1.25
6 years ago
0.1.26
6 years ago
0.1.16
6 years ago
0.1.18
6 years ago
0.1.19
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.8
6 years ago
0.1.9
6 years ago
0.1.7
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago