Compare commits

...

2 Commits

Author SHA1 Message Date
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
5 changed files with 6154 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
# 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

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.

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

View File

@@ -175,16 +175,19 @@ 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;
const article = ArticleHelper.getFrontMatter(editor);
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}"`, (error, stdout) => {
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;