Skip to content

Commit 7e48ee0

Browse files
committed
Update docs for 9.4.0
1 parent ebbaeda commit 7e48ee0

File tree

6 files changed

+238
-16
lines changed

6 files changed

+238
-16
lines changed

.frontmatter/database/mediaDb.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

content/changelog/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [#709](https://github.com/estruyf/vscode-front-matter/issues/709): Take "where clause" into account on content creation
1818
- [#710](https://github.com/estruyf/vscode-front-matter/issues/710): Hide child field when parent field its "when clause" is not met, also remove the fields from the content
1919
- [#713](https://github.com/estruyf/vscode-front-matter/issues/713): Add the ability to always use quotes around string values in front matter
20+
- [#722](https://github.com/estruyf/vscode-front-matter/issues/722): Allow to create sub-content which shows a dialog to select the parent folder
2021

2122
### ⚡️ Optimizations
2223

content/changelog/v9.4.0.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Version 9.4.0 release notes
3+
description: ""
4+
date: 2023-12-07T15:05:16.280Z
5+
lastmod: 2023-12-07T16:40:53.318Z
6+
slug: ""
7+
type: changelog
8+
---
9+
10+
## Localization of Front Matter CMS
11+
12+
Now both the webviews and the extension dialogs, messages, and notifications are localized. Currently we support the following languages:
13+
14+
- German
15+
- Spanish
16+
- French
17+
- Italian
18+
- Japanese
19+
- Korean
20+
- Portuguese (Brazil)
21+
- English
22+
23+
> **Important**: If a human translation is not available for the language, it will be translated using Azure Translation Services. This means that the translation might not be 100% accurate. In case you want to help us translate Front Matter CMS to your language, please check out the [localization documentation](/docs/contributing#translating-the-extension).
24+
25+
## Custom script enhancements
26+
27+
With the [@frontmatter/extensibility](https://www.npmjs.com/package/@frontmatter/extensibility) package, it is easier to create custom scripts for Front Matter CMS and it allows you to do more like asking questions to the user.
28+
29+
### Getting the arguments
30+
31+
Previously, you had to manually parse the arguments from the `process.argv` array. Now you can use the `getArguments` function from the `@frontmatter/extensibility` package.
32+
33+
```ts
34+
import { ContentScript, MediaScript } from '@frontmatter/extensibility';
35+
36+
// In content scripts
37+
const contentScriptArgs = ContentScript.getArguments();
38+
39+
// In media scripts
40+
const mediaScriptArgs = MediaScript.getArguments();
41+
```
42+
43+
> **Info**: More information can be found in the [creating a content script](/docs/custom-actions#creating-a-content-script) and [creating a media script](/docs/custom-actions#creating-a-media-script) documentation.
44+
45+
### Asking questions
46+
47+
You can now ask questions to the user when running a script. This can be done by using the `askQuestion` function from the `@frontmatter/extensibility` package.
48+
49+
```ts
50+
import { MediaScript } from '@frontmatter/extensibility';
51+
52+
const mediaScriptArgs = MediaScript.getArguments();
53+
54+
const answers = mediaScriptArgs.answers;
55+
if (!answers) {
56+
MediaScript.askQuestions([{
57+
name: "width",
58+
message: "What is the width of the image?",
59+
default: image.width
60+
}]);
61+
return;
62+
}
63+
64+
const width = answers.width;
65+
66+
// Do something with the width
67+
```
68+
69+
> **Info**: More information can be found in the [asking questions to users](/docs/custom-actions#asking-questions-to-users) documentation.
70+
71+
### Scheduled content
72+
73+
You can now filter and group the content dashboard by scheduled content. This allows you to see which content is scheduled to be published in the future.
74+
75+
![Scheduled content](/releases/v9.4.0/scheduled-content.png)
76+
77+
## Related issues/enhancements
78+
79+
### ✨ New features
80+
81+
- Localization implemented for the whole extension
82+
83+
### 🎨 Enhancements
84+
85+
- [#273](https://github.com/estruyf/vscode-front-matter/issues/273): Allow single value arrays to be set as a string with the `singleValueAsString` field property
86+
- [#686](https://github.com/estruyf/vscode-front-matter/issues/686): Allow script authors to ask questions during script execution
87+
- [#688](https://github.com/estruyf/vscode-front-matter/issues/688): Allow to show the scheduled articles in the content dashboard (filter and group)
88+
- [#690](https://github.com/estruyf/vscode-front-matter/issues/690): Added the ability to filter values in the `contentRelationship` field
89+
- [#700](https://github.com/estruyf/vscode-front-matter/issues/700): Added the `{{pathToken.relPath}}` placeholder for the `previewPath` property
90+
- [#706](https://github.com/estruyf/vscode-front-matter/issues/706): Show the error of scripts failing in the Front Matter output panel
91+
- [#709](https://github.com/estruyf/vscode-front-matter/issues/709): Take "where clause" into account on content creation
92+
- [#710](https://github.com/estruyf/vscode-front-matter/issues/710): Hide child field when parent field its "when clause" is not met, also remove the fields from the content
93+
- [#713](https://github.com/estruyf/vscode-front-matter/issues/713): Add the ability to always use quotes around string values in front matter
94+
- [#722](https://github.com/estruyf/vscode-front-matter/issues/722): Allow to create sub-content which shows a dialog to select the parent folder
95+
96+
### ⚡️ Optimizations
97+
98+
- Dashboard layout grid optimizations
99+
- Added the content-type name to the metadata section in the panel
100+
- New implementation of the combobox for the `contentRelationship` field
101+
102+
### 🐞 Fixes
103+
104+
- [#685](https://github.com/estruyf/vscode-front-matter/issues/685): Fix when using non-string values in the tag picker
105+
- [#691](https://github.com/estruyf/vscode-front-matter/issues/691): Silent authentication retrieval for GitHub sponsors
106+
- [#694](https://github.com/estruyf/vscode-front-matter/issues/694): Start terminal session from the folder where the `frontmatter.json` file is located
107+
- [#696](https://github.com/estruyf/vscode-front-matter/issues/696): Close the local server terminal on restart
108+
- [#699](https://github.com/estruyf/vscode-front-matter/issues/699): Changing border theme variable for the dashboard header
109+
- [#703](https://github.com/estruyf/vscode-front-matter/issues/703): Fix retrieval of Astro Collections for `pnpm` projects
110+
- [#704](https://github.com/estruyf/vscode-front-matter/issues/704): Fix `zod` schema script for optional fields
111+
- [#707](https://github.com/estruyf/vscode-front-matter/issues/707): Fix `clearEmpty` issue with `draft` and `boolean` fields which are by default set to `true`
112+
- [#711](https://github.com/estruyf/vscode-front-matter/issues/711): Fix in character mapping in the slug field
113+
- [#712](https://github.com/estruyf/vscode-front-matter/issues/712): Keep the search context when deleting media files
114+
- [#714](https://github.com/estruyf/vscode-front-matter/issues/714): Fix for taxonomy filtering from taxonomy view to content view
115+
- [#718](https://github.com/estruyf/vscode-front-matter/issues/718): Fix JSON schema for the `frontMatter.panel.actions.disabled` setting

content/docs/custom-actions.md

Lines changed: 121 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Custom actions
33
slug: custom-actions
44
description: null
55
date: 2021-08-30T16:13:00.546Z
6-
lastmod: 2023-11-02T15:02:24.382Z
6+
lastmod: 2023-12-07T16:37:05.124Z
77
weight: 500
88
---
99

@@ -93,7 +93,27 @@ The environment option contains the following properties:
9393
## Creating a content script
9494

9595
Create a folder in your project where you want to store all your custom scripts, and create a new
96-
JavaScript file. The sample content of this file looks like this:
96+
JavaScript file.
97+
98+
> **Info**: You can also use another language like Python, Bash, ... for your script. Examples are
99+
> provided at the end of this page.
100+
101+
### Installing the extensibility package (optional)
102+
103+
When using JavaScript, you can make use of the
104+
[@frontmatter/extensibility](https://www.npmjs.com/package/@frontmatter/extensibility) package.
105+
106+
```bash
107+
npm i @frontmatter/extensibility
108+
```
109+
110+
With this `@frontmatter/extensibility` dependency,
111+
you can easily get the arguments and ask questions to the user.
112+
113+
### Creating a script without the extensibility package
114+
115+
When you do not want to use the `@frontmatter/extensibility` package, you can create a script as
116+
follows:
97117

98118
```javascript
99119
const arguments = process.argv;
@@ -107,25 +127,37 @@ if (arguments && arguments.length > 0) {
107127
}
108128
```
109129

110-
> **Info**: The sample script can be found here [sample-script.js][03]
111-
112130
The current workspace-, file-path, and front matter data will be passed as a arguments. Like you can
113131
see in the above sample script, you can fetch these argument values as follows:
114132

115133
- `arguments[2]`: The workspace path
116134
- `arguments[3]`: The file path (Markdown file)
117135
- `arguments[4]`: The front matter data as object
118136

119-
In order to use this functionality, you will need to configure the `frontMatter.custom.scripts`
137+
### Creating a script with the extensibility package
138+
139+
When you want to use the `@frontmatter/extensibility` package, you can create a script as follows:
140+
141+
```javascript
142+
import { ContentScript } from "@frontmatter/extensibility";
143+
144+
const { workspacePath, filePath, frontMatter, answers } = ContentScript.getArguments();
145+
146+
ContentScript.done("The content returned for your notification.");
147+
```
148+
149+
### Configure the script
150+
151+
To use this functionality, you will need to configure the `frontMatter.custom.scripts`
120152
setting for your project as follows:
121153

122154
```json
123155
{
124156
"frontMatter.custom.scripts": [
125157
{
126158
"title": "Generate social image",
127-
"script": "./scripts/social-img.js",
128-
"command": "~/.nvm/versions/node/v14.15.5/bin/node"
159+
"script": "./scripts/social-img.mjs",
160+
"command": "~/.nvm/versions/node/v18.17.1/bin/node"
129161
}
130162
]
131163
}
@@ -142,7 +174,7 @@ useful when you generate additional content.
142174

143175
![Custom action output][04]
144176

145-
### Updating the front matter
177+
### Updating the front matter of your content
146178

147179
By default, once a custom action executed, it will show the output in a notification. In case you
148180
want to update the front matter of your content, you need to provide the data in the following JSON
@@ -152,17 +184,17 @@ format.
152184
{ "frontmatter": { "<field name>": "field value" } }
153185
```
154186

155-
Example:
187+
Example when you want to update the title without the `@frontmatter/extensibility` dependency:
156188

157-
```javascript
189+
```javascript {{ "title": "Update without the extensibility dependency" }}
158190
(async () => {
159191
// Your script logic
160192

161193
// Finally, update the front matter of your content by passing the data
162194
// in the following format
163195
const output = JSON.stringify({
164-
"frontmatter": {
165-
"title": "My new title"
196+
frontmatter: {
197+
title: "My new title"
166198
}
167199
});
168200

@@ -171,6 +203,14 @@ Example:
171203
})();
172204
```
173205

206+
Example when you want to update the title with the `@frontmatter/extensibility` dependency:
207+
208+
```javascript {{ "title": "Update with the extensibility dependency" }}
209+
import { ContentScript } from "@frontmatter/extensibility";
210+
211+
ContentScript.updateFrontMatter({ title: "My new title" })
212+
```
213+
174214
When data is passed in the above format, it will automatically get parse the JSON data and the file
175215
its front matter gets updated accordingly.
176216

@@ -230,11 +270,19 @@ Here is a sample on how you can define a media script:
230270
}
231271
```
232272

233-
The current workspace-, file/folder-path will be passed as a arguments.
273+
The script will provide you the following arguments:
234274

235275
- `arguments[2]`: The workspace path
236276
- `arguments[3]`: The file or folder path. This depends on the type of script.
237277

278+
When using the `@frontmatter/extensibility` package, you can get the arguments as follows:
279+
280+
```javascript
281+
import { MediaScript } from "@frontmatter/extensibility";
282+
283+
const { workspacePath, mediaPath, answers } = MediaScript.getArguments();
284+
```
285+
238286
### Media file script
239287

240288
When you defined a media file script, you will be able to execute it for a single media file from
@@ -249,6 +297,65 @@ menu next to the **create new folder** button.
249297

250298
![Custom action for a media folder][06]
251299

300+
## Asking questions to users
301+
302+
When you want to ask questions to the user, you can use the `askQuestions` function from the
303+
`@frontmatter/extensibility` package. This functionality can be used in both content and media
304+
scripts.
305+
306+
To get started, you need to know that you have to check if the `answers` property is available in
307+
the arguments. If it is not available, you can ask the questions to the user. Once the user has
308+
answered the questions, the answers will be passed to the script.
309+
310+
Here is a sample on how you can ask questions to the user:
311+
312+
```javascript {{ "title": "Sample script with questions to the user" }}
313+
import { MediaScript } from '@frontmatter/extensibility';
314+
import { Image } from 'image-js';
315+
316+
(async () => {
317+
const mediaScriptArgs = MediaScript.getArguments();
318+
319+
if (!mediaScriptArgs) {
320+
MediaScript.done(`No arguments found`);
321+
return;
322+
}
323+
324+
const imagePath = mediaScriptArgs.mediaPath;
325+
const answers = mediaScriptArgs.answers;
326+
327+
let image = await Image.load(imagePath);
328+
329+
if (!answers) {
330+
MediaScript.askQuestions([{
331+
name: "width",
332+
message: "What is the width of the image?",
333+
default: image.width
334+
}]);
335+
return;
336+
}
337+
338+
const width = answers.width;
339+
340+
if (!width) {
341+
MediaScript.done(`No width provided`);
342+
return;
343+
}
344+
345+
await image.resize({ width: parseInt(width) }).save(imagePath);
346+
347+
MediaScript.done(`Image resized to ${width}px`);
348+
})();
349+
```
350+
351+
How the above script works:
352+
353+
1. It will check if the `answers` property is available in the arguments. If it is not available,
354+
we create a new question for the user and return the script without any output.
355+
1. Once the user has answered the question, the script will be executed again, but this time the
356+
`answers` property will be available in the arguments.
357+
1. We will fetch the width from the answers and resize the image accordingly.
358+
252359
## Sample scripts
253360

254361
### Bash starter
@@ -336,7 +443,6 @@ const arguments = process.argv;
336443

337444
[01]: /assets/custom-action.png
338445
[02]: https://www.eliostruyf.com/generate-open-graph-preview-image-code-front-matter/
339-
[03]: https://github.com/estruyf/vscode-front-matter/blob/HEAD/sample/script-sample.js
340446
[04]: /assets/custom-action-output.png
341447
[05]: /releases/v5.6.0/media-file-custom-script.png
342-
[06]: /releases/v5.6.0/media-folder-custom-script.png
448+
[06]: /releases/v9.4.0/media-folder-script.png
56.2 KB
Loading
152 KB
Loading

0 commit comments

Comments
 (0)