mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-21 09:03:06 +02:00
Fixes in preview paths
This commit is contained in:
@@ -80,7 +80,7 @@ export class Preview {
|
||||
} else if (crntFolders && crntFolders.length > 1) {
|
||||
selectedFolder = await Preview.askUserToPickFolder(crntFolders);
|
||||
} else {
|
||||
selectedFolder = await Preview.askUserToPickFolder(folders);
|
||||
selectedFolder = await Preview.askUserToPickFolder(folders.filter((f) => f.previewPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export class Preview {
|
||||
// Get relative file path
|
||||
const folderPath = wsFolder ? parseWinPath(wsFolder.fsPath) : '';
|
||||
const relativePath = filePath.replace(folderPath, '');
|
||||
pathname = processPathPlaceholders(pathname, relativePath);
|
||||
pathname = processPathPlaceholders(pathname, relativePath, filePath, selectedFolder);
|
||||
}
|
||||
|
||||
// Support front matter placeholders - {{fm.<field>}}
|
||||
@@ -265,6 +265,10 @@ export class Preview {
|
||||
): Promise<ContentFolder | undefined> {
|
||||
let selectedFolder: ContentFolder | undefined = undefined;
|
||||
|
||||
if (crntFolders.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Ask the user to select the folder
|
||||
const folderNames = crntFolders.map((folder) => folder.title);
|
||||
const selectedFolderName = await window.showQuickPick(folderNames, {
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
export const processPathPlaceholders = (value: string, path: string) => {
|
||||
if (value && value.includes('{{pathToken.')) {
|
||||
const regex = new RegExp('{{pathToken.(\\d+)}}', 'g');
|
||||
const matches = value.match(regex);
|
||||
import { ContentFolder } from '../models';
|
||||
|
||||
export const processPathPlaceholders = (
|
||||
value: string,
|
||||
path: string,
|
||||
filePath: string,
|
||||
contentFolder: ContentFolder | null | undefined
|
||||
) => {
|
||||
if (value && value.includes('{{pathToken.')) {
|
||||
const regex = /{{pathToken.(\d+|relPath)}}/g;
|
||||
const matches = value.match(regex);
|
||||
if (matches) {
|
||||
for (const match of matches) {
|
||||
const index = parseInt(match.replace('{{pathToken.', '').replace('}}', ''), 10);
|
||||
const pathTokens = path.split('/');
|
||||
const tokenIndex = match.replace('{{pathToken.', '').replace('}}', '');
|
||||
|
||||
if (pathTokens.length >= index) {
|
||||
value = value.replace(match, pathTokens[index - 1]);
|
||||
const pathTokens = path.split('/');
|
||||
if (tokenIndex === 'relPath') {
|
||||
// Return path without the file name
|
||||
const relFilePath = filePath.replace(contentFolder?.path || '', '');
|
||||
value = value.replace(match, relFilePath.substring(0, relFilePath.lastIndexOf('/')));
|
||||
} else {
|
||||
// Get the token from the path
|
||||
value = value.replace(match, pathTokens[Number(tokenIndex)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user