mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-05-18 07:15:43 +02:00
Get webview URI for Windows
This commit is contained in:
@@ -247,15 +247,13 @@ export class PagesParser {
|
||||
}
|
||||
|
||||
if (previewUri) {
|
||||
const previewPath = Dashboard.getWebview()?.asWebviewUri(previewUri);
|
||||
let preview = previewPath?.toString();
|
||||
let previewPath = Dashboard.getWebview()?.asWebviewUri(previewUri);
|
||||
|
||||
if (!preview) {
|
||||
const fileUrl = parseWinPath(previewUri.fsPath);
|
||||
preview = `https://file%2B.vscode-resource.vscode-cdn.net/${fileUrl.startsWith(`/`) ? fileUrl.substr(1) : fileUrl}`;
|
||||
if (!previewPath) {
|
||||
previewPath = PagesParser.getWebviewUri(previewUri);
|
||||
}
|
||||
|
||||
page["fmPreviewImage"] = preview?.toString() || "";
|
||||
page["fmPreviewImage"] = previewPath?.toString() || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,4 +264,24 @@ export class PagesParser {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the webview URI
|
||||
* @param resource
|
||||
* @returns
|
||||
*/
|
||||
private static getWebviewUri(resource: Uri) {
|
||||
// Logic from: https://github.com/microsoft/vscode/blob/main/src/vs/workbench/common/webview.ts
|
||||
const webviewResourceBaseHost = 'vscode-cdn.net';
|
||||
const webviewRootResourceAuthority = `vscode-resource.${webviewResourceBaseHost}`;
|
||||
|
||||
const authority = `${resource.scheme}+${encodeURI(resource.authority)}.${webviewRootResourceAuthority}`;
|
||||
return Uri.from({
|
||||
scheme: "https",
|
||||
authority,
|
||||
path: resource.path,
|
||||
query: resource.query,
|
||||
fragment: resource.fragment
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user