mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-10 19:03:17 +02:00
#806 - Prefix and suffix update
This commit is contained in:
@@ -313,12 +313,15 @@ export class Article {
|
||||
}
|
||||
}
|
||||
|
||||
const suffix = Settings.get(SETTING_SLUG_SUFFIX) as string;
|
||||
const prefix = Settings.get(SETTING_SLUG_PREFIX) as string;
|
||||
|
||||
if (parsedFile.name.toLowerCase() !== 'index') {
|
||||
return parsedFile.name;
|
||||
return `${prefix}${parsedFile.name}${suffix}`;
|
||||
}
|
||||
|
||||
const folderName = basename(dirname(file));
|
||||
return folderName;
|
||||
return `${prefix}${folderName}${suffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,13 +19,13 @@ import { ContentFolder, ContentType, PreviewSettings } from '../models';
|
||||
import { format } from 'date-fns';
|
||||
import { DateHelper } from '../helpers/DateHelper';
|
||||
import { Article } from '.';
|
||||
import { urlJoin } from 'url-join-ts';
|
||||
import { WebviewHelper } from '@estruyf/vscode';
|
||||
import { Folders } from './Folders';
|
||||
import { ParsedFrontMatter } from '../parsers';
|
||||
import { getLocalizationFile } from '../utils/getLocalizationFile';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
import { LocalizationKey } from '../localization';
|
||||
import { joinUrl } from '../utils';
|
||||
|
||||
export class Preview {
|
||||
public static filePath: string | undefined = undefined;
|
||||
@@ -65,7 +65,7 @@ export class Preview {
|
||||
const localhostUrl = await this.getLocalServerUrl();
|
||||
|
||||
if (browserLiteCommand) {
|
||||
const pageUrl = urlJoin(localhostUrl.toString(), slug || '');
|
||||
const pageUrl = joinUrl(localhostUrl.toString(), slug || '');
|
||||
commands.executeCommand(browserLiteCommand, pageUrl);
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ export class Preview {
|
||||
<title>Front Matter Preview</title>
|
||||
</head>
|
||||
<body style="width:100%;height:100%;margin:0;padding:0;overflow:hidden">
|
||||
<div id="app" data-type="preview" data-url="${urlJoin(
|
||||
<div id="app" data-type="preview" data-url="${joinUrl(
|
||||
localhostUrl.toString(),
|
||||
slug || ''
|
||||
)}" data-isProd="${isProd}" data-environment="${
|
||||
@@ -208,7 +208,7 @@ export class Preview {
|
||||
|
||||
webView.webview.postMessage({
|
||||
command: PreviewCommands.toWebview.updateUrl,
|
||||
payload: urlJoin(localhost.toString(), slug || '')
|
||||
payload: joinUrl(localhost.toString(), slug || '')
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -312,7 +312,10 @@ export class Preview {
|
||||
pathname = processPathPlaceholders(pathname, relativePath, filePath, selectedFolder);
|
||||
|
||||
const file = parse(filePath);
|
||||
if (file.name.toLowerCase() === 'index' && (pathname.endsWith(slug) || !pathname)) {
|
||||
if (
|
||||
file.name.toLowerCase() === 'index' &&
|
||||
(pathname.endsWith(slug) || !pathname || pathname === '/')
|
||||
) {
|
||||
slug = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ import { Dashboard } from '../../commands/Dashboard';
|
||||
import { PanelProvider } from '../../panelWebView/PanelProvider';
|
||||
import { ArticleHelper, Extension } from '../../helpers';
|
||||
import { Logger } from '../../helpers/Logger';
|
||||
import { commands, Uri, window, workspace } from 'vscode';
|
||||
import { commands, Uri, window } from 'vscode';
|
||||
import { PostMessageData } from '../../models';
|
||||
import { Preview } from '../../commands';
|
||||
import { urlJoin } from 'url-join-ts';
|
||||
import { joinUrl } from '../../utils';
|
||||
|
||||
export abstract class BaseListener {
|
||||
public static process(msg: PostMessageData) {
|
||||
@@ -84,7 +84,7 @@ export abstract class BaseListener {
|
||||
|
||||
const slug = await Preview.getContentSlug(article, filePath);
|
||||
|
||||
const fullUrl = urlJoin(websiteUrl, slug);
|
||||
const fullUrl = joinUrl(websiteUrl, slug);
|
||||
commands.executeCommand('vscode.open', fullUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export * from './flattenObjectKeys';
|
||||
export * from './getLocalizationFile';
|
||||
export * from './ignoreMsgCommand';
|
||||
export * from './isWindows';
|
||||
export * from './joinUrl';
|
||||
export * from './mkdirAsync';
|
||||
export * from './readFileAsync';
|
||||
export * from './readdirAsync';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { urlJoin } from 'url-join-ts';
|
||||
|
||||
export const joinUrl = (baseUrl: string | undefined, ...paths: any[]): string => {
|
||||
const url = urlJoin(baseUrl, ...paths);
|
||||
|
||||
// Get last path
|
||||
const lastPath = paths[paths.length - 1];
|
||||
if (lastPath && lastPath.endsWith('/') && !url.endsWith('/')) {
|
||||
return url + '/';
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
Reference in New Issue
Block a user