페이지 레이아웃 컴파일러는 해당 페이지 레이아웃을 컴파일하는 NodeJS (CommonJS) JavaScript 모듈입니다.
특정 페이지 레이아웃에 대한 페이지 레이아웃 컴파일러는 -compile.js 확장과 이름을 연관시켜 정의됩니다.
src
themes
<yourTheme>
layouts
<yourPageLayout>.html<yourPageLayout>-compile.js페이지 레이아웃에 대한 -compile.js가 없으면 사용자정의 컴파일이 적용되지 않습니다.
페이지 레이아웃 컴파일러는 Promise를 반환하는 compile() 인터페이스(예: about-compile.js)를 구현해야 합니다.
var mustache = require('mustache');
var PageCompiler = function () {};
PageCompiler.prototype.compile = function (args) {
var self = this,
layoutMarkup = args.layoutMarkup;
self.SCSCompileAPI = args.SCSCompileAPI;
return new Promise function (resolve, reject) {
var compiledPage = layoutMarkup,
id = self.SCSCompileAPI.navigationRoot;
// page is compiled so there is no FOUC, can remove the opacity
workaround
compiledPage = compiledPage.replace('opacity: 0;', 'opacity: 1;');
// remove the dynamic menu creation, we'll be compiling it here
compiledPage = compiledPage.replace('<script
src="_scs_theme_root_/assets/js/topnav.js"></script>', '');
// add link to Home page. . .
var homePageURL = (self.SCSCompileAPI.getPageLinkData(id) ||
{}).href;
if (homePageURL) {
compiledPage = compiledPage.replace('class="navbar-brand"
href="#"', 'class="navbar-brand" href="' + homePageURL + '"');
}
// build the menu and add it to the page
var navMenu = self.createNavMenu();
compiledPage = compiledPage.replace('<!-- navigation menu goes in
here -->', navMenu);
// return the compiled page
resolve(compiledPage);
});
};
// Create the navigation menu that was previously dynamically generated on
each page
PageCompiler.prototype.createNavMenu = function () {
. . .
}
module.exports = new PageCompiler();