mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 09:23:00 +02:00
#812 - Added {{locale}} placeholder
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
- [#808](https://github.com/estruyf/vscode-front-matter/issues/808): Add support to generate field groups and `block` fields in content type generation
|
||||
- [#810](https://github.com/estruyf/vscode-front-matter/issues/810): Update the tab title based on the view
|
||||
- [#811](https://github.com/estruyf/vscode-front-matter/issues/811): Added `panel.gitActions` view mode option to hide the Git actions in the panel
|
||||
- [#812](https://github.com/estruyf/vscode-front-matter/issues/812): Added the `{{locale}}` placeholder which can be used in the `previewPath` property
|
||||
|
||||
### ⚡️ Optimizations
|
||||
|
||||
|
||||
+13
-6
@@ -1,6 +1,3 @@
|
||||
import { processFmPlaceholders } from './../helpers/processFmPlaceholders';
|
||||
import { processPathPlaceholders } from './../helpers/processPathPlaceholders';
|
||||
import { Telemetry } from './../helpers/Telemetry';
|
||||
import {
|
||||
SETTING_PREVIEW_HOST,
|
||||
SETTING_PREVIEW_PATHNAME,
|
||||
@@ -12,13 +9,22 @@ import {
|
||||
GeneralCommands,
|
||||
SETTING_PREVIEW_TRAILING_SLASH
|
||||
} from './../constants';
|
||||
import { ArticleHelper } from './../helpers/ArticleHelper';
|
||||
import { join, parse } from 'path';
|
||||
import { commands, env, Uri, ViewColumn, window, WebviewPanel, extensions } from 'vscode';
|
||||
import { Extension, parseWinPath, processTimePlaceholders, Settings } from '../helpers';
|
||||
import {
|
||||
ArticleHelper,
|
||||
DateHelper,
|
||||
Extension,
|
||||
parseWinPath,
|
||||
processI18nPlaceholders,
|
||||
processTimePlaceholders,
|
||||
processFmPlaceholders,
|
||||
processPathPlaceholders,
|
||||
Settings,
|
||||
Telemetry
|
||||
} from '../helpers';
|
||||
import { ContentFolder, ContentType, PreviewSettings } from '../models';
|
||||
import { format } from 'date-fns';
|
||||
import { DateHelper } from '../helpers/DateHelper';
|
||||
import { Article } from '.';
|
||||
import { WebviewHelper } from '@estruyf/vscode';
|
||||
import { Folders } from './Folders';
|
||||
@@ -311,6 +317,7 @@ export class Preview {
|
||||
const folderPath = wsFolder ? parseWinPath(wsFolder.fsPath) : '';
|
||||
const relativePath = filePath.replace(folderPath, '');
|
||||
pathname = processPathPlaceholders(pathname, relativePath, filePath, selectedFolder);
|
||||
pathname = processI18nPlaceholders(pathname, selectedFolder);
|
||||
|
||||
const file = parse(filePath);
|
||||
if (file.name.toLowerCase() === 'index') {
|
||||
|
||||
@@ -33,5 +33,6 @@ export * from './openFileInEditor';
|
||||
export * from './parseWinPath';
|
||||
export * from './processArticlePlaceholders';
|
||||
export * from './processFmPlaceholders';
|
||||
export * from './processI18nPlaceholders';
|
||||
export * from './processPathPlaceholders';
|
||||
export * from './processTimePlaceholders';
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { ContentFolder } from '../models';
|
||||
|
||||
export const processI18nPlaceholders = (
|
||||
value: string,
|
||||
contentFolder: ContentFolder | null | undefined
|
||||
) => {
|
||||
// Example: {{locale}}
|
||||
if (value && contentFolder?.locale) {
|
||||
if (value.includes('{{locale}}')) {
|
||||
const regex = new RegExp('{{locale}}', 'g');
|
||||
value = value.replace(regex, contentFolder.locale);
|
||||
}
|
||||
// Example: {{locale | ignore:en}}
|
||||
else if (value.includes('{{locale')) {
|
||||
const regex = /{{locale[^}]*}}/g;
|
||||
const matches = value.match(regex);
|
||||
if (matches) {
|
||||
for (const match of matches) {
|
||||
const placeholderParts = match.split('|');
|
||||
if (placeholderParts.length > 1) {
|
||||
let ignore = placeholderParts[1].trim().replace('}}', '');
|
||||
|
||||
if (ignore.startsWith('ignore:')) {
|
||||
ignore = ignore.replace('ignore:', '');
|
||||
|
||||
if (ignore.includes(contentFolder.locale)) {
|
||||
value = value.replace(match, '');
|
||||
} else {
|
||||
value = value.replace(match, contentFolder.locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user