Publican.lib feed functions

195 words, 1-minute read

The feed functions help create machine-readable files in JSON and XML format. The libInit() function adds all functions:

publican.config.js excerpt

// Publican configuration
import { Publican, tacs } from 'publican';
import { libInit } from 'publican.lib';

// ...set Publican defaults...

// initialize publican.lib
libInit(publican, tacs);

// build
await publican.build();

Or you can add functions individually:

publican.config.js excerpt

// Publican configuration
import { Publican, tacs } from 'publican';
import { rss } from 'publican.lib/feed';

// ...set Publican defaults...

// add global feed functions
tacs.lib = tacs.lib || {};
tacs.lib.feed = { rss };

// build
await publican.build();

All examples in this section assume the global tacs.config.domain is the domain, such as https://mysite.com.

rss(str, domain, root) #

Removes invalid HTML attributes and ensures all URIs use absolute references.

RSS example

<content:encoded><![CDATA[
${ tacs.lib.feed.rss( data.contentRendered, tacs.config.domain, tacs.root ) }
]]></content:encoded>

json(str, domain, root) #

Does the same as rss() but also applies special encodings for JSON feeds that are replaced.

JSON example

"content_html": "${ tacs.lib.feed.json( data.contentRendered, tacs.config.domain, tacs.root ) }"

escape(str) #

Escapes single-line HTML and XML strings.

example

<title>${ tacs.lib.feed.escape( data.title ) }</title>