soames-gatsby-theme
Version:
A customizable Gatsby theme for personal websites using WordPress as a headless CMS.
106 lines (105 loc) • 5.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Shortcodes = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const html_react_parser_1 = __importDefault(require("html-react-parser"));
const getAttributes_1 = require("./getAttributes");
const getContent_1 = require("./getContent");
const RemoveContentAreaPadding_1 = __importDefault(require("../../components/shortcodes/RemoveContentAreaPadding"));
const SoamesTitle_1 = __importDefault(require("../../components/shortcodes/SoamesTitle"));
const SoamesTitleBar_1 = __importDefault(require("../../components/shortcodes/SoamesTitleBar"));
const SoamesTitleBarLg_1 = __importDefault(require("../../components/shortcodes/SoamesTitleBarLg"));
const SoamesTextBlock_1 = __importDefault(require("../../components/shortcodes/SoamesTextBlock"));
const SoamesIconList_1 = __importDefault(require("../../components/shortcodes/SoamesIconList"));
const SoamesFeature_1 = __importDefault(require("../../components/shortcodes/SoamesFeature"));
const SoamesGalleryMenu_1 = __importDefault(require("../../components/shortcodes/SoamesGalleryMenu"));
const SoamesVideo_1 = __importDefault(require("../../components/shortcodes/SoamesVideo"));
const SoamesTextList_1 = __importDefault(require("../../components/shortcodes/SoamesTextList"));
const SoamesSoundCloud_1 = __importDefault(require("../../components/shortcodes/SoamesSoundCloud"));
const handleShortcodes = (node) => {
if (node.type === "tag" && node.children && node.children.length > 0) {
const child = node.children[0];
if (child.type === "text") {
const shortcode = child.data.trim();
if (shortcode === "[soames-remove-content-area-padding]") {
return (0, jsx_runtime_1.jsx)(RemoveContentAreaPadding_1.default, {});
}
const shortcodeMappings = [
{
regex: /\[soames-title([^\]]*)\]([\s\S]*?)\[\/soames-title\]/,
component: SoamesTitle_1.default,
propsExtractor: (match) => ({ title: (0, getContent_1.getContent)(match) }),
},
{
regex: /\[soames-title-bar([^\]]*)\]([\s\S]*?)\[\/soames-title-bar\]/,
component: SoamesTitleBar_1.default,
propsExtractor: (match) => ({ title: (0, getContent_1.getContent)(match) }),
},
{
regex: /\[soames-title-bar-lg([^\]]*)\]([\s\S]*?)\[\/soames-title-bar-lg\]/,
component: SoamesTitleBarLg_1.default,
propsExtractor: (match) => ({
title: (0, getContent_1.getContent)(match),
attributes: (0, getAttributes_1.getAttributes)(match),
}),
},
{
regex: /\[soames-text-block([^\]]*)\]([\s\S]*?)\[\/soames-text-block\]/,
component: SoamesTextBlock_1.default,
propsExtractor: (match) => ({ content: (0, getContent_1.getContent)(match) }),
},
{
regex: /\[soames-text-list([^\]]*)\]([\s\S]*?)\[\/soames-text-list\]/,
component: SoamesTextList_1.default,
propsExtractor: (match) => ({ content: (0, getContent_1.getContent)(match) }),
},
{
regex: /\[soames-icon-list([^\]]*)\]/,
component: SoamesIconList_1.default,
propsExtractor: (match) => ({ attributes: (0, getAttributes_1.getAttributes)(match) }),
},
{
regex: /\[soames-feature([^\]]*)\]([\s\S]*?)\[\/soames-feature\]/,
component: SoamesFeature_1.default,
propsExtractor: (match) => ({
content: (0, getContent_1.getContent)(match),
attributes: (0, getAttributes_1.getAttributes)(match),
}),
},
{
regex: /\[soames-gallery-menu([^\]]*)\]/,
component: SoamesGalleryMenu_1.default,
propsExtractor: (match) => ({ attributes: (0, getAttributes_1.getAttributes)(match) }),
},
{
regex: /\[soames-video([^\]]*)\]/,
component: SoamesVideo_1.default,
propsExtractor: (match) => ({ attributes: (0, getAttributes_1.getAttributes)(match) }),
},
{
regex: /\[soames-soundcloud([^\]]*)\]/,
component: SoamesSoundCloud_1.default,
propsExtractor: (match) => ({ attributes: (0, getAttributes_1.getAttributes)(match) }),
},
];
for (const { regex, component: Component, propsExtractor } of shortcodeMappings) {
const match = shortcode.match(regex);
if (match) {
const props = propsExtractor(match);
return (0, jsx_runtime_1.jsx)(Component, { ...props });
}
}
}
}
return undefined;
};
const Shortcodes = ({ children }) => {
const reactElements = (0, html_react_parser_1.default)(children || "", {
replace: handleShortcodes,
});
return (0, jsx_runtime_1.jsx)("div", { children: reactElements });
};
exports.Shortcodes = Shortcodes;