fix: resolve relative paths in --index flag to prevent malformed config paths

When using --index with relative paths like './index/my-project', the path was
stored directly as the config filename, resulting in paths like:
/home/user/.config/qmd/./index/my-project.yml

This caused 'no such file or directory' errors. Now relative paths are resolved
and normalized by replacing path separators with underscores.
This commit is contained in:
Tobi Lütke 2026-02-17 10:00:12 -05:00
parent 640ac13cd0
commit 00bcfbbd34
No known key found for this signature in database

View File

@ -58,7 +58,16 @@ let currentIndexName: string = "index";
* Config file will be ~/.config/qmd/{indexName}.yml
*/
export function setConfigIndexName(name: string): void {
currentIndexName = name;
// Resolve relative paths to absolute paths and sanitize for use as filename
if (name.includes('/')) {
const { resolve } = require('path');
const { cwd } = require('process');
const absolutePath = resolve(cwd(), name);
// Replace path separators with underscores to create a valid filename
currentIndexName = absolutePath.replace(/\//g, '_').replace(/^_/, '');
} else {
currentIndexName = name;
}
}
function getConfigDir(): string {