@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
68 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultTaxonomies = void 0;
exports.cleanTreeKey = cleanTreeKey;
exports.setupTaxonomyViews = setupTaxonomyViews;
exports.decodeTaxonomyConfig = decodeTaxonomyConfig;
/**
* Default taxonomies
*/
exports.DefaultTaxonomies = {
tag: 'tags',
category: 'categories'
};
/**
* Creates a clean tree key for taxonomy
*/
function cleanTreeKey(...elems) {
let s = '';
if (elems.length > 0) {
s = elems[0];
if (elems.length > 1) {
s = elems.join('/');
}
}
// Trim dots, slashes, and spaces
s = s.replace(/^[.\s/]+|[.\s/]+$/g, '');
s = s.toLowerCase();
s = s.replace(/\\/g, '/');
if (s === '' || s === '/') {
return '';
}
if (!s.startsWith('/')) {
s = '/' + s;
}
return s;
}
/**
* Creates taxonomy views from taxonomies configuration
*/
function setupTaxonomyViews(taxonomies) {
const views = [];
for (const [singular, plural] of Object.entries(taxonomies)) {
views.push({
singular,
plural,
pluralTreeKey: cleanTreeKey(plural)
});
}
// Sort by plural name
views.sort((a, b) => a.plural.localeCompare(b.plural));
return views;
}
/**
* Creates taxonomy configuration from provider data
*/
function decodeTaxonomyConfig(data) {
if (data.taxonomies && typeof data.taxonomies === 'object') {
const taxonomies = {};
for (const [key, value] of Object.entries(data.taxonomies)) {
if (typeof value === 'string') {
taxonomies[key] = value;
}
}
return taxonomies;
}
return { ...exports.DefaultTaxonomies };
}
//# sourceMappingURL=taxonomy.js.map