@burdy-cms/web-utils
v1.3.0
Published
Burdy web utilities
Downloads
22
Readme
Burdy Web Utils
Powerful utilities to simplify usage of the Burdy on the web.
- See Burdy Docs for more details
Instalation
npm i @burdy-cms/web-utils
Functionalities
createRewrites
Creates a RewritesObject
instance that can be used to rewrite paths based on the configuration.
Accepts rewriteMap
and origin
(optional) as object parameters.
import { createRewrites } from '@burdy-cms/web-utils';
import axios from 'axios';
const rewrites = createRewrites({
origin: 'https://cms.website.com/api/content',
rewriteMap: [
{
source: '/:lang(fr|de)/:path*',
rewrites: {
page: '/sites/{lang}/{path}',
header: '/sites/{lang}/fragments/header',
footer: '/sites/{lang}/fragments/footer'
}
},
{
source: '/:path*',
rewrites: {
page: '/sites/en/{path}',
header: '/sites/en/fragments/header',
footer: '/sites/en/fragments/footer'
}
}
]
});
/**
Page = https://cms.website.com/api/content/sites/fr/fragments/home
Header = https://cms.website.com/api/content/sites/fr/fragments/header
Footer = https://cms.website.com/api/content/sites/fr/fragments/footer
**/
const { page, footer, header } = rewrites.rewrite('/fr/home');
// Fetch data from Burdy
const [pageRequest, footerRequest, headerRequest] = await Promise.all([
page,
footer,
header
]);
richtextToHtml
A function for converting Richtext (DraftJS) Editor content to plain HTML.
This is a forked version of draftjs-to-html
draftjs-to-html created by Jyoti Puri.
import { richtextToHtml } from '@burdy-cms/web-utils';
const rawContentState = BURDY_RICHTEXT_RESPONSE;
const markup = richtextToHtml(
rawContentState
);
subscribeToPreview
Subscribes to Burdy preview (iframe parent). Returns a Subscription
that has unsubscribe()
method.
import { subscribeToPreview } from '@burdy-cms/web-utils';
const subscription = subscribeToPreview({
onEdit: post => {
updateView(post); // Updates view using new content
}
});
// Unsubscribe at some point if needed
subscription.unsubscribe();
updatePreview
Sends the updates to Burdy preview (iframe parent). This allows Burdy to know when you have switched the page on the frontend.
import { updatePreview } from '@burdy-cms/web-utils';
onRouterChange((pageData) => {
updatePreview(pageData);
});