mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 00:09:04 +00:00
update
This commit is contained in:
70
docs/src/config/loadConfig.js
Normal file
70
docs/src/config/loadConfig.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
function deepMerge(target, source) {
|
||||
for (const key of Object.keys(source)) {
|
||||
if (
|
||||
source[key] &&
|
||||
typeof source[key] === 'object' &&
|
||||
!Array.isArray(source[key])
|
||||
) {
|
||||
target[key] = deepMerge(target[key] || {}, source[key]);
|
||||
} else if (source[key] !== undefined) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function loadConfig(configPath = path.join(process.cwd(), 'config.yaml')) {
|
||||
let raw = {};
|
||||
if (fs.existsSync(configPath)) {
|
||||
try {
|
||||
raw = yaml.load(fs.readFileSync(configPath, 'utf8')) || {};
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse ${configPath}: ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const defaults = {
|
||||
site: {
|
||||
title: 'Archivox',
|
||||
description: '',
|
||||
logo: '',
|
||||
favicon: ''
|
||||
},
|
||||
navigation: {
|
||||
search: true
|
||||
},
|
||||
footer: {},
|
||||
theme: {
|
||||
name: 'minimal',
|
||||
darkMode: false
|
||||
},
|
||||
features: {},
|
||||
pluginsDir: 'plugins',
|
||||
plugins: []
|
||||
};
|
||||
|
||||
const config = deepMerge(defaults, raw);
|
||||
|
||||
const errors = [];
|
||||
if (
|
||||
!config.site ||
|
||||
typeof config.site.title !== 'string' ||
|
||||
!config.site.title.trim()
|
||||
) {
|
||||
errors.push('site.title is required in config.yaml');
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
errors.forEach(err => console.error(`Config error: ${err}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
module.exports = loadConfig;
|
24
docs/src/config/loadPlugins.js
Normal file
24
docs/src/config/loadPlugins.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function loadPlugins(config) {
|
||||
const dir = path.resolve(process.cwd(), config.pluginsDir || 'plugins');
|
||||
const names = Array.isArray(config.plugins) ? config.plugins : [];
|
||||
const plugins = [];
|
||||
for (const name of names) {
|
||||
const file = path.join(dir, name.endsWith('.js') ? name : `${name}.js`);
|
||||
if (fs.existsSync(file)) {
|
||||
try {
|
||||
const mod = require(file);
|
||||
plugins.push(mod);
|
||||
} catch (e) {
|
||||
console.error(`Failed to load plugin ${name}:`, e);
|
||||
}
|
||||
} else {
|
||||
console.warn(`Plugin not found: ${file}`);
|
||||
}
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
module.exports = loadPlugins;
|
Reference in New Issue
Block a user