dotmd-cli 0.14.7 → 0.14.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/package.json +1 -1
- package/src/new.mjs +15 -4
package/package.json
CHANGED
package/src/new.mjs
CHANGED
|
@@ -77,12 +77,22 @@ export async function runNew(argv, config, opts = {}) {
|
|
|
77
77
|
// Resolve template
|
|
78
78
|
const template = resolveTemplate(templateName ?? 'default', config);
|
|
79
79
|
|
|
80
|
+
// If name contains path separators, split into directory prefix and basename
|
|
81
|
+
let nameDir = null;
|
|
82
|
+
let namePart = name;
|
|
83
|
+
if (name.includes('/') || name.includes(path.sep)) {
|
|
84
|
+
nameDir = path.dirname(name);
|
|
85
|
+
namePart = path.basename(name, '.md');
|
|
86
|
+
} else if (name.endsWith('.md')) {
|
|
87
|
+
namePart = name.slice(0, -3);
|
|
88
|
+
}
|
|
89
|
+
|
|
80
90
|
// Slugify
|
|
81
|
-
const slug =
|
|
91
|
+
const slug = namePart.toLowerCase().replace(/[\s_]+/g, '-').replace(/[^a-z0-9-]/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '');
|
|
82
92
|
if (!slug) { die('Name resolves to empty slug: ' + name); }
|
|
83
93
|
|
|
84
94
|
// Title
|
|
85
|
-
const docTitle = title ??
|
|
95
|
+
const docTitle = title ?? namePart.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
86
96
|
|
|
87
97
|
// Resolve target root
|
|
88
98
|
let targetRoot = config.docsRoot;
|
|
@@ -96,8 +106,9 @@ export async function runNew(argv, config, opts = {}) {
|
|
|
96
106
|
targetRoot = match;
|
|
97
107
|
}
|
|
98
108
|
|
|
99
|
-
// Path
|
|
100
|
-
const
|
|
109
|
+
// Path — if user provided a directory prefix, resolve relative to repoRoot
|
|
110
|
+
const baseDir = nameDir ? path.resolve(config.repoRoot, nameDir) : targetRoot;
|
|
111
|
+
const filePath = path.join(baseDir, slug + '.md');
|
|
101
112
|
const repoPath = toRepoPath(filePath, config.repoRoot);
|
|
102
113
|
|
|
103
114
|
if (existsSync(filePath)) {
|