Burdy Web Utils
Powerful utilities to simplify usage of the Burdy on the web.
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'
}
}
]
});
const { page, footer, header } = rewrites.rewrite('/fr/home');
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);
}
});
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);
});