forked from iarv/vscode-front-matter
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50e62b2925 | |||
| c41e7cf5fc | |||
| 232c3ff111 | |||
| a0a21a093f |
@@ -1,5 +1,13 @@
|
||||
# Change Log
|
||||
|
||||
## [1.16.0] - 2020-05-04
|
||||
|
||||
- Add all front matter properties as an argument for custom scripts
|
||||
|
||||
## [1.15.1] - 2020-05-04
|
||||
|
||||
- Add the ability to specify a custom Node path
|
||||
|
||||
## [1.15.0] - 2020-05-04
|
||||
|
||||
- Added the ability to add your own custom scripts as panel actions.
|
||||
|
||||
@@ -28,12 +28,14 @@ Once a custom action has been configured, it will appear on the Front Matter pan
|
||||
|
||||

|
||||
|
||||
The current workspace- and file-path will be passed as an argument. In your script fetch these arguments as follows:
|
||||
The current workspace-, file-path, and front matter data will be passed as an argument. In your script fetch these arguments as follows:
|
||||
|
||||
```javascript
|
||||
const arguments = process.argv;
|
||||
const workspaceArg = arguments[2];
|
||||
const fileArg = arguments[3];
|
||||
const dataArg = arguments[4];
|
||||
const data = dataArg && typeof dataArg === "string" ? JSON.parse(dataArg) : null;
|
||||
```
|
||||
|
||||
The output of the script will be passed as a notification, and it allows you to copy the output.
|
||||
@@ -196,11 +198,14 @@ Allows you to specify a title and script path (starting relative from the root o
|
||||
{
|
||||
"frontMatter.custom.scripts": [{
|
||||
"title": "Generate social image",
|
||||
"script": "./scripts/social-img.js"
|
||||
"script": "./scripts/social-img.js",
|
||||
"nodeBin": "~/.nvm/versions/node/v14.15.5/bin/node"
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
> **Important**: When the command execution would fail when it cannot find the `node` command. You are able to specify your path to the node app. This is for instance required when using `nvm`.
|
||||
|
||||
## Usage
|
||||
|
||||
- Start by opening the command prompt:
|
||||
|
||||
Generated
+6139
-2
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -3,7 +3,7 @@
|
||||
"displayName": "Front Matter",
|
||||
"description": "Simplifies working with front matter of your articles. Useful extension when you are using a static site generator like: Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...",
|
||||
"icon": "assets/front-matter.png",
|
||||
"version": "1.15.0",
|
||||
"version": "1.16.0",
|
||||
"preview": false,
|
||||
"publisher": "eliostruyf",
|
||||
"galleryBanner": {
|
||||
@@ -240,6 +240,7 @@
|
||||
"@types/react-dom": "17.0.0",
|
||||
"@types/vscode": "1.51.0",
|
||||
"date-fns": "2.0.1",
|
||||
"downshift": "6.0.6",
|
||||
"glob": "7.1.6",
|
||||
"gray-matter": "4.0.2",
|
||||
"html-loader": "1.3.2",
|
||||
@@ -250,7 +251,6 @@
|
||||
"tslint": "6.1.3",
|
||||
"typescript": "4.0.2",
|
||||
"webpack": "4.44.2",
|
||||
"webpack-cli": "3.3.12",
|
||||
"downshift": "6.0.6"
|
||||
"webpack-cli": "3.3.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ export interface Slug {
|
||||
export interface CustomScript {
|
||||
title: string;
|
||||
script: string;
|
||||
nodeBin?: string;
|
||||
}
|
||||
+21
-14
@@ -175,24 +175,31 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
|
||||
const config = workspace.getConfiguration(CONFIG_KEY);
|
||||
const scripts: CustomScript[] | undefined = config.get(SETTING_CUSTOM_SCRIPTS);
|
||||
|
||||
if (msg?.data?.title && msg?.data?.script && scripts) {
|
||||
const customScript = scripts.find((s: CustomScript) => s.title === msg.data.title);
|
||||
if (customScript?.script && customScript?.title) {
|
||||
const editor = window.activeTextEditor;
|
||||
if (!editor) return;
|
||||
|
||||
if (msg?.data?.title && msg?.data?.script && scripts && scripts.find((s: CustomScript) => s.title === msg?.data?.title)?.title) {
|
||||
const editor = window.activeTextEditor;
|
||||
const wsFolders = workspace.workspaceFolders;
|
||||
if (wsFolders && wsFolders.length > 0) {
|
||||
const wsPath = wsFolders[0].uri.fsPath;
|
||||
exec(`node ${path.join(wsPath, msg.data.script)} "${wsPath}" "${editor?.document.uri.fsPath}"`, (error, stdout) => {
|
||||
if (error) {
|
||||
window.showErrorMessage(`${msg?.data?.title}: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
const article = ArticleHelper.getFrontMatter(editor);
|
||||
|
||||
window.showInformationMessage(`${msg?.data?.title}: ${stdout || "Executed your custom script."}`, 'Copy output').then(value => {
|
||||
if (value === 'Copy output') {
|
||||
vscodeEnv.clipboard.writeText(stdout);
|
||||
const wsFolders = workspace.workspaceFolders;
|
||||
if (wsFolders && wsFolders.length > 0) {
|
||||
const wsPath = wsFolders[0].uri.fsPath;
|
||||
|
||||
exec(`${customScript.nodeBin || "node"} ${path.join(wsPath, msg.data.script)} "${wsPath}" "${editor?.document.uri.fsPath}" "${JSON.stringify(article?.data)}"`, (error, stdout) => {
|
||||
if (error) {
|
||||
window.showErrorMessage(`${msg?.data?.title}: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
window.showInformationMessage(`${msg?.data?.title}: ${stdout || "Executed your custom script."}`, 'Copy output').then(value => {
|
||||
if (value === 'Copy output') {
|
||||
vscodeEnv.clipboard.writeText(stdout);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user