@burdy-cms/web-utils
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

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'
      }
    }
  ]
});

/**
  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);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @burdy-cms/web-utils

Homepage

burdy.io

Weekly Downloads

1

Version

1.3.0

License

MIT

Unpacked Size

45.3 kB

Total Files

33

Last publish

Collaborators

  • team-burdy