diff --git a/CHANGELOG.md b/CHANGELOG.md index 95849fe0..3e0074e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#686](https://github.com/estruyf/vscode-front-matter/issues/686): Allow script authors to ask questions during script execution - [#688](https://github.com/estruyf/vscode-front-matter/issues/688): Allow to show the scheduled articles in the content dashboard (filter and group) - [#690](https://github.com/estruyf/vscode-front-matter/issues/690): Added the ability to filter values in the `contentRelationship` field +- [#700](https://github.com/estruyf/vscode-front-matter/issues/700): Added the `{{pathToken.relPath}}` placeholder for the `previewPath` property ### ⚡️ Optimizations diff --git a/src/helpers/processPathPlaceholders.ts b/src/helpers/processPathPlaceholders.ts index 32e9a980..2c5afffb 100644 --- a/src/helpers/processPathPlaceholders.ts +++ b/src/helpers/processPathPlaceholders.ts @@ -1,3 +1,4 @@ +import { dirname, relative } from 'path'; import { ContentFolder } from '../models'; export const processPathPlaceholders = ( @@ -7,6 +8,13 @@ export const processPathPlaceholders = ( contentFolder: ContentFolder | null | undefined ) => { if (value && value.includes('{{pathToken.')) { + const relPathToken = '{{pathToken.relPath}}'; + if (value.includes(relPathToken) && contentFolder?.path) { + const dirName = dirname(filePath); + let relPath = relative(contentFolder.path, dirName); + value = value.replace(relPathToken, relPath); + } + const regex = /{{pathToken.(\d+|relPath)}}/g; const matches = value.match(regex); if (matches) {