@mgks/docmd 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODE_OF_CONDUCT.md +48 -0
- package/.github/CONTRIBUTING.md +129 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +58 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +27 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- package/.github/SECURITY.md +18 -0
- package/.github/workflows/publish.yml +20 -55
- package/README.md +119 -67
- package/config.js +14 -0
- package/docs/comparison.md +51 -0
- package/docs/content/containers/changelogs.md +128 -0
- package/docs/content/containers/collapsible.md +89 -0
- package/docs/recipes/custom-fonts.md +43 -0
- package/docs/recipes/favicon.md +38 -0
- package/docs/recipes/index.md +12 -0
- package/docs/recipes/landing-page.md +46 -0
- package/package.json +1 -2
- package/src/assets/css/docmd-main.css +1262 -4
- package/src/assets/js/docmd-main.js +17 -1
- package/src/core/config-loader.js +9 -3
- package/src/core/config-validator.js +79 -0
- package/src/core/file-processor.js +49 -769
- package/src/core/markdown/containers.js +94 -0
- package/src/core/markdown/renderers.js +90 -0
- package/src/core/markdown/rules.js +355 -0
- package/src/core/markdown/setup.js +108 -0
|
@@ -36,6 +36,22 @@ function initializeCollapsibleNav() {
|
|
|
36
36
|
toggleSubmenu(isExpanded);
|
|
37
37
|
|
|
38
38
|
anchor.addEventListener('click', (e) => {
|
|
39
|
+
const currentExpanded = item.getAttribute('aria-expanded') === 'true';
|
|
40
|
+
const href = anchor.getAttribute('href');
|
|
41
|
+
const isPlaceholder = !href || href === '#' || href === '';
|
|
42
|
+
|
|
43
|
+
if (!currentExpanded) {
|
|
44
|
+
toggleSubmenu(true);
|
|
45
|
+
} else if (isPlaceholder || e.target.closest('.collapse-icon')) {
|
|
46
|
+
toggleSubmenu(false);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isPlaceholder || e.target.closest('.collapse-icon')) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/* anchor.addEventListener('click', (e) => {
|
|
39
55
|
// If the click target is the icon, ALWAYS prevent navigation and toggle.
|
|
40
56
|
if (e.target.closest('.collapse-icon')) {
|
|
41
57
|
e.preventDefault();
|
|
@@ -47,7 +63,7 @@ function initializeCollapsibleNav() {
|
|
|
47
63
|
toggleSubmenu(item.getAttribute('aria-expanded') !== 'true');
|
|
48
64
|
}
|
|
49
65
|
// Otherwise, let the click proceed to navigate to the link.
|
|
50
|
-
})
|
|
66
|
+
});*/
|
|
51
67
|
});
|
|
52
68
|
}
|
|
53
69
|
|
|
@@ -2,19 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
|
+
const { validateConfig } = require('./config-validator');
|
|
5
6
|
|
|
6
7
|
async function loadConfig(configPath) {
|
|
7
8
|
const absoluteConfigPath = path.resolve(process.cwd(), configPath);
|
|
8
9
|
if (!await fs.pathExists(absoluteConfigPath)) {
|
|
9
|
-
throw new Error(`Configuration file not found: ${absoluteConfigPath}
|
|
10
|
+
throw new Error(`Configuration file not found at: ${absoluteConfigPath}\nRun "docmd init" to create one.`);
|
|
10
11
|
}
|
|
11
12
|
try {
|
|
12
13
|
// Clear require cache to always get the freshest config
|
|
13
14
|
delete require.cache[require.resolve(absoluteConfigPath)];
|
|
14
15
|
const config = require(absoluteConfigPath);
|
|
15
16
|
|
|
17
|
+
// Validate configuration call
|
|
18
|
+
validateConfig(config);
|
|
19
|
+
|
|
16
20
|
// Basic validation and defaults
|
|
17
|
-
if (!config.siteTitle) throw new Error('`siteTitle` is missing in config file');
|
|
18
21
|
config.srcDir = config.srcDir || 'docs';
|
|
19
22
|
config.outputDir = config.outputDir || 'site';
|
|
20
23
|
config.theme = config.theme || {};
|
|
@@ -24,7 +27,10 @@ async function loadConfig(configPath) {
|
|
|
24
27
|
|
|
25
28
|
return config;
|
|
26
29
|
} catch (e) {
|
|
27
|
-
|
|
30
|
+
if (e.message === 'Invalid configuration file.') {
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Error parsing config file: ${e.message}`);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Source file from the docmd project — https://github.com/mgks/docmd
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
|
|
5
|
+
// Known configuration keys for typo detection
|
|
6
|
+
const KNOWN_KEYS = [
|
|
7
|
+
'siteTitle', 'siteUrl', 'srcDir', 'outputDir', 'logo',
|
|
8
|
+
'sidebar', 'theme', 'customJs', 'autoTitleFromH1',
|
|
9
|
+
'copyCode', 'plugins', 'navigation', 'footer', 'sponsor', 'favicon'
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
// Common typos mapping
|
|
13
|
+
const TYPO_MAPPING = {
|
|
14
|
+
'site_title': 'siteTitle',
|
|
15
|
+
'sitetitle': 'siteTitle',
|
|
16
|
+
'baseUrl': 'siteUrl',
|
|
17
|
+
'source': 'srcDir',
|
|
18
|
+
'out': 'outputDir',
|
|
19
|
+
'customCSS': 'theme.customCss',
|
|
20
|
+
'customcss': 'theme.customCss',
|
|
21
|
+
'customJS': 'customJs',
|
|
22
|
+
'customjs': 'customJs',
|
|
23
|
+
'nav': 'navigation',
|
|
24
|
+
'menu': 'navigation'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function validateConfig(config) {
|
|
28
|
+
const errors = [];
|
|
29
|
+
const warnings = [];
|
|
30
|
+
|
|
31
|
+
// 1. Required Fields
|
|
32
|
+
if (!config.siteTitle) {
|
|
33
|
+
errors.push('Missing required property: "siteTitle"');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. Type Checking
|
|
37
|
+
if (config.navigation && !Array.isArray(config.navigation)) {
|
|
38
|
+
errors.push('"navigation" must be an Array');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (config.customJs && !Array.isArray(config.customJs)) {
|
|
42
|
+
errors.push('"customJs" must be an Array of strings');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (config.theme) {
|
|
46
|
+
if (config.theme.customCss && !Array.isArray(config.theme.customCss)) {
|
|
47
|
+
errors.push('"theme.customCss" must be an Array of strings');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 3. Typos and Unknown Keys (Top Level)
|
|
52
|
+
Object.keys(config).forEach(key => {
|
|
53
|
+
if (TYPO_MAPPING[key]) {
|
|
54
|
+
warnings.push(`Found unknown property "${key}". Did you mean "${TYPO_MAPPING[key]}"?`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// 4. Theme specific typos
|
|
59
|
+
if (config.theme) {
|
|
60
|
+
if (config.theme.customCSS) {
|
|
61
|
+
warnings.push('Found "theme.customCSS". Did you mean "theme.customCss"?');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Output results
|
|
66
|
+
if (warnings.length > 0) {
|
|
67
|
+
console.log(chalk.yellow('\n⚠️ Configuration Warnings:'));
|
|
68
|
+
warnings.forEach(w => console.log(chalk.yellow(` - ${w}`)));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (errors.length > 0) {
|
|
72
|
+
console.log(chalk.red('\n❌ Configuration Errors:'));
|
|
73
|
+
errors.forEach(e => console.log(chalk.red(` - ${e}`)));
|
|
74
|
+
console.log('');
|
|
75
|
+
throw new Error('Invalid configuration file.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { validateConfig };
|