Fix: improve media folder parsing on Windows and update path handling in various modules

This commit is contained in:
Elio Struyf
2025-02-12 14:53:56 +01:00
parent d3b7f73c66
commit 710ef136b4
5 changed files with 10 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
### 🐞 Fixes
- Fix for media folder parsing on Windows
- [#909](https://github.com/estruyf/vscode-front-matter/issues/909): Schema fix for the view modes
- [#913](https://github.com/estruyf/vscode-front-matter/issues/913): Fix for relative media paths in page bundles
- [#914](https://github.com/estruyf/vscode-front-matter/issues/914): Fix sanitizing of default filenames with an `_` in it

View File

@@ -219,7 +219,9 @@ export class Folders {
: Folders.getAbsFilePath(assetFolder);
const wsFolder = Folders.getWorkspaceFolder();
if (wsFolder) {
const relativePath = relative(parseWinPath(wsFolder.fsPath), parseWinPath(assetFolder));
const relativePath = parseWinPath(
relative(parseWinPath(wsFolder.fsPath), parseWinPath(assetFolder))
);
return relativePath === '' ? '/' : relativePath;
}
}
@@ -648,7 +650,7 @@ export class Folders {
const uniqueFolders = [...new Set(folders)];
const relativeFolderPaths = uniqueFolders.map((folder) =>
relative(parseWinPath(wsFolder.fsPath), folder)
parseWinPath(relative(parseWinPath(wsFolder.fsPath), folder))
);
Logger.verbose('Folders:getContentFolders:end');

View File

@@ -137,7 +137,7 @@ export class FrameworkDetector {
const assetDir = dirname(absAssetPath);
const fileName = parse(absAssetPath);
relAssetPath = relative(fileDir, assetDir);
relAssetPath = parseWinPath(relative(fileDir, assetDir));
relAssetPath = join(relAssetPath, `${fileName.name}${fileName.ext}`);
}
// Support for HEXO image folder
@@ -197,7 +197,7 @@ export class FrameworkDetector {
const assetDir = dirname(absAssetPath);
const fileName = parse(absAssetPath);
let relAssetPath = relative(fileDir, assetDir);
let relAssetPath = parseWinPath(relative(fileDir, assetDir));
relAssetPath = join(relAssetPath, `${fileName.name}${fileName.ext}`);
return parseWinPath(relAssetPath);
}

View File

@@ -422,7 +422,7 @@ export class MediaHelpers {
// If the image exists in a content folder, the relative path needs to be used
if (existsInContent) {
const relImgPath = relative(fileDir, imgDir);
const relImgPath = parseWinPath(relative(fileDir, imgDir));
relPath = join(relImgPath, basename(relPath));

View File

@@ -1,5 +1,6 @@
import { dirname, relative } from 'path';
import { ContentFolder } from '../models';
import { parseWinPath } from './parseWinPath';
export const processPathPlaceholders = (
value: string,
@@ -11,7 +12,7 @@ export const processPathPlaceholders = (
const relPathToken = '{{pathToken.relPath}}';
if (value.includes(relPathToken) && contentFolder?.path) {
const dirName = dirname(filePath);
const relPath = relative(contentFolder.path, dirName);
const relPath = parseWinPath(relative(contentFolder.path, dirName));
value = value.replace(relPathToken, relPath);
}