@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
105 lines • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Root = void 0;
exports.newRoot = newRoot;
const root_1 = require("../../../domain/config/vo/root");
/**
* Root entity holds the root configuration
*/
class Root {
constructor(rootConfig, rootParams = {}) {
this.rootConfig = rootConfig;
this.rootParams = rootParams;
}
/**
* Get the default theme
*/
defaultTheme() {
return this.rootConfig.theme.length > 0 ? this.rootConfig.theme[0] : '';
}
/**
* Get the compiled timeout duration
*/
compiledTimeout() {
const timeout = this.rootConfig.timeout;
if (/^\d+$/.test(timeout)) {
// A number, assume seconds
return parseInt(timeout, 10) * 1000;
}
// Parse duration strings like "30s", "1m", "2h"
const match = timeout.match(/^(\d+)([smh])$/);
if (match) {
const value = parseInt(match[1], 10);
const unit = match[2];
switch (unit) {
case 's': return value * 1000;
case 'm': return value * 60 * 1000;
case 'h': return value * 60 * 60 * 1000;
}
}
return 30000; // Default 30 seconds
}
/**
* Get the base URL
*/
baseUrl() {
return this.rootConfig.baseURL;
}
/**
* Get configuration parameters
*/
configParams() {
return this.rootParams;
}
/**
* Get site title
*/
siteTitle() {
return this.rootConfig.title;
}
/**
* Get the root configuration
*/
getRootConfig() {
return this.rootConfig;
}
/**
* Get theme list
*/
getThemes() {
return this.rootConfig.theme;
}
/**
* Get default content language
*/
getDefaultContentLanguage() {
return this.rootConfig.defaultContentLanguage;
}
/**
* Check if drafts should be built
*/
shouldBuildDrafts() {
return this.rootConfig.buildDrafts;
}
/**
* Check if future content should be built
*/
shouldBuildFuture() {
return this.rootConfig.buildFuture;
}
/**
* Check if expired content should be built
*/
shouldBuildExpired() {
return this.rootConfig.buildExpired;
}
}
exports.Root = Root;
/**
* Create a new Root instance from provider data
*/
function newRoot(data, params = {}) {
const rootConfig = (0, root_1.decodeRootConfig)(data);
return new Root(rootConfig, params);
}
//# sourceMappingURL=root.js.map