Compare commits

...

7 Commits

Author SHA1 Message Date
Elio Struyf
2d82b815fc Update CHANGELOG.md 2021-05-31 15:51:39 +02:00
Elio Struyf
99701e88a0 1.16.1 2021-05-27 22:39:28 +02:00
Elio Struyf
6901ae30f5 Fix for node 2021-05-27 22:39:22 +02:00
Elio Struyf
50e62b2925 1.16.0 2021-05-04 14:33:45 +02:00
Elio Struyf
c41e7cf5fc Added front matter to custom script arguments 2021-05-04 14:33:37 +02:00
Elio Struyf
232c3ff111 1.15.1 2021-05-04 13:16:59 +02:00
Elio Struyf
a0a21a093f Fix for nvm 2021-05-04 13:16:51 +02:00
7 changed files with 6188 additions and 21 deletions

View File

@@ -1,5 +1,17 @@
# Change Log
## [1.16.1] - 2020-05-27
- Fix for Node.js v14.16.0
## [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.

View File

@@ -28,12 +28,14 @@ Once a custom action has been configured, it will appear on the Front Matter pan
![](./assets/custom-actions.png)
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:

6141
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -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.1",
"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"
}
}

View File

@@ -21,4 +21,5 @@ export interface Slug {
export interface CustomScript {
title: string;
script: string;
nodeBin?: string;
}

View File

@@ -9,4 +9,4 @@ declare const acquireVsCodeApi: <T = unknown>() => {
};
const elm = document.querySelector("#app");
render(<ViewPanel />, elm);
render(<ViewPanel />, elm);

View File

@@ -175,24 +175,36 @@ 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);
const wsFolders = workspace.workspaceFolders;
if (wsFolders && wsFolders.length > 0) {
const wsPath = wsFolders[0].uri.fsPath;
let articleData = `'${JSON.stringify(article?.data)}'`;
if (os.type() === "Windows_NT") {
articleData = `"${JSON.stringify(article?.data).replace(/"/g, `""`)}"`;
}
window.showInformationMessage(`${msg?.data?.title}: ${stdout || "Executed your custom script."}`, 'Copy output').then(value => {
if (value === 'Copy output') {
vscodeEnv.clipboard.writeText(stdout);
exec(`${customScript.nodeBin || "node"} ${path.join(wsPath, msg.data.script)} "${wsPath}" "${editor?.document.uri.fsPath}" ${articleData}`, (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);
}
});
});
});
}
}
}
}