Feedback: Custom action returning frontmatter #304

Closed
opened 2026-10-05 02:39:07 +02:00 by adam · 1 comment
Owner

https://frontmatter.codes/docs/custom-actions#updating-the-front-matter says something along the lines of returning a json structure to update the frontmatter.

It doesn't work though in my tests. A very simple sample:

(async () => {
    // something is done
    // and then
    return '{ "frontmatter": { "bla": "fasel" }}';
  }
})();

... this is not updating the frontmatter in the markdown file from where I called the action. The main problem is probably just that the one paragraph describing the feature is not enough.

Questions:

  • does bla have to exist to be "updated"?
  • how can I add new frontmatter
  • frontmatter - do you expect it to be JSON, YAML, TOML? can Front Matter handle different frontmatter formats?
  • is return the right way or does Front Matter expect an echo-output?
  • is returning a stringified JSON right or should an object be returned?
  • could you maybe add a sample?

The above script returns 'Front Matter: Retrieve Unsplash image: undefined' as notification (where the retrieve unsplash image part is the title of the action).

https://frontmatter.codes/docs/custom-actions#updating-the-front-matter says something along the lines of returning a json structure to update the frontmatter. It doesn't work though in my tests. A very simple sample: ``` (async () => { // something is done // and then return '{ "frontmatter": { "bla": "fasel" }}'; } })(); ``` ... this is not updating the frontmatter in the markdown file from where I called the action. The main problem is probably just that the one paragraph describing the feature is not enough. Questions: - does `bla` have to exist to be "updated"? - how can I _add_ new frontmatter - frontmatter - do you expect it to be JSON, YAML, TOML? can Front Matter handle different frontmatter formats? - is return the right way or does Front Matter expect an echo-output? - is returning a stringified JSON right or should an object be returned? - could you maybe add a sample? The above script returns 'Front Matter: Retrieve Unsplash image: undefined' as notification (where the retrieve unsplash image part is the title of the action). <!-- github-sync-id:1331025316 -->
adam closed this issue 2026-10-05 02:39:07 +02:00
Author
Owner

You're almost there, but it is the documentation that can be optimized here.

A custom action/script needs to return data via logging it to the output, as that is what the extension will receive and process.

In your case, the script should be as follows:

(async () => {
    // something is done
    // and then
    console.log('{ "frontmatter": { "bla": "fasel" }}');
  }
})();

Answers:

does bla have to exist to be "updated"?

Nope, this can be added by the script

how can I add new frontmatter

Example above

frontmatter - do you expect it to be JSON, YAML, TOML? can Front Matter handle different frontmatter formats?

Should be JSON

is return the right way or does Front Matter expect an echo output?

Think the above sample helps you with this

is returning a stringified JSON right or should an object be returned?

Yep, this is correct

could you maybe add a sample?

Example above

You're almost there, but it is the documentation that can be optimized here. A custom action/script needs to return data via logging it to the output, as that is what the extension will receive and process. In your case, the script should be as follows: ```javascript (async () => { // something is done // and then console.log('{ "frontmatter": { "bla": "fasel" }}'); } })(); ``` Answers: > does bla have to exist to be "updated"? Nope, this can be added by the script > how can I add new frontmatter Example above > frontmatter - do you expect it to be JSON, YAML, TOML? can Front Matter handle different frontmatter formats? Should be JSON > is return the right way or does Front Matter expect an echo output? Think the above sample helps you with this > is returning a stringified JSON right or should an object be returned? Yep, this is correct > could you maybe add a sample? Example above <!-- github-comment-id:1207789405 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#304