You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
import {getBlockConfigs, getBlockName, getBlockVariations, handlebarLayoutsPath} from "../helpers.js";
|
|
import path from "path";
|
|
import {buildAssetFiles} from "../inc/changes-watcher.js";
|
|
|
|
export default async function (req, res) {
|
|
const blockName = req.query.block;
|
|
const block = getBlockName(blockName);
|
|
|
|
const blockDir = path.join('blocks', '@' + block.project, block.name);
|
|
const dataFiles = await getBlockVariations(blockDir);
|
|
|
|
const data = await getDataOfFrame(!!req.query.iframe, Object.assign({}, block, {dataFiles}));
|
|
|
|
if (data.error && data.errorMessage) {
|
|
return res.send(data.errorMessage);
|
|
}
|
|
|
|
const baseView = req.params.baseView ?? 'alignfull';
|
|
|
|
await buildAssetFiles(blockDir);
|
|
|
|
res.render(baseView, data)
|
|
}
|
|
|
|
async function getDataOfFrame(isIframe = false, block) {
|
|
const data = {config: await getBlockConfigs(block)};
|
|
if (data.error && data.errorMessage) {
|
|
return data;
|
|
}
|
|
|
|
data.helpers = {
|
|
include_partial: (filesPath) => handlebarLayoutsPath(filesPath),
|
|
}
|
|
|
|
if (isIframe) {
|
|
data.iframeMode = true;
|
|
}
|
|
|
|
data.staticFilesPath = `/block/${block.project}/${block.name}`;
|
|
|
|
return data;
|
|
}
|
|
|
|
|