@phtml/schema
Version:
Write shorter schema.org microdata in HTML
29 lines (21 loc) • 805 B
JavaScript
;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var phtml = _interopDefault(require('phtml'));
var index = new phtml.Plugin('phtml-schema', opts => {
const schema = Object(opts).schema || 'https://schema.org/';
return {
Element(node) {
const itemtype = node.attrs.get('itemtype');
if (itemtype) {
if (!node.attrs.itemscope) {
node.attrs.add('itemscope', null);
}
const prefix = typeof schema === 'string' ? schema : String(schema[itemtype] || schema['*'] || '');
const itemtypeURL = itemtype.replace(/^\w+$/, `${prefix}$&`);
node.attrs.add('itemtype', itemtypeURL);
}
}
};
});
module.exports = index;
//# sourceMappingURL=index.js.map