Enhancement: Allow custom scripts for custom placeholders #280

Closed
opened 2026-10-05 02:37:31 +02:00 by adam · 3 comments
Owner

To further enhance the placeholders that can be used in the content types. It would be good to investigate if it would be possible to have a custom script capability.

To further enhance the placeholders that can be used in the content types. It would be good to investigate if it would be possible to have a custom script capability. <!-- github-sync-id:1266513168 -->
adam closed this issue 2026-10-05 02:37:32 +02:00
Author
Owner

Testing out with the following implementation:

{
  "frontMatter.taxonomy.contentTypes": [
    {
      "name": "test",
      "pageBundle": false,
      "fields": [
        {
          "title": "Title",
          "name": "title",
          "type": "string"
        },
        {
          "title": "Unique ID",
          "name": "uniqueId",
          "type": "string",
          "default": "{{uniqueId}}"
        },
      ]
    }
  ],
  "frontMatter.content.placeholders": [
    {
      "id": "uniqueId",
      "script": "./scripts/uniqueId.js",
      "command": "~/.nvm/versions/node/v16.13.1/bin/node"
    }
  ]
}

The script gets two arguments:

  1. File path
  2. Title of the document
const arguments = process.argv;

if (arguments && arguments.length > 0) {
  const workspaceArg = arguments[2];
  const filePath = arguments[3];
  const title = arguments[4];

  console.log(Math.random().toString(36).substring(2, 15));
}

The outcome of the newly generated file its front matter:

Xnapper-2022-07-21-14 01 51
Testing out with the following implementation: ```json { "frontMatter.taxonomy.contentTypes": [ { "name": "test", "pageBundle": false, "fields": [ { "title": "Title", "name": "title", "type": "string" }, { "title": "Unique ID", "name": "uniqueId", "type": "string", "default": "{{uniqueId}}" }, ] } ], "frontMatter.content.placeholders": [ { "id": "uniqueId", "script": "./scripts/uniqueId.js", "command": "~/.nvm/versions/node/v16.13.1/bin/node" } ] } ``` The script gets two arguments: 1. File path 2. Title of the document ```js const arguments = process.argv; if (arguments && arguments.length > 0) { const workspaceArg = arguments[2]; const filePath = arguments[3]; const title = arguments[4]; console.log(Math.random().toString(36).substring(2, 15)); } ``` The outcome of the newly generated file its front matter: <img width="384" alt="Xnapper-2022-07-21-14 01 51" src="https://user-images.githubusercontent.com/2900833/180198707-f290d962-82a7-486e-8621-34f8eb7ed579.png"> <!-- github-comment-id:1191349402 -->
Author
Owner

Another test with a known placeholder from Front Matter:

{
  "frontMatter.taxonomy.contentTypes": [
    {
      "name": "test",
      "pageBundle": false,
      "fields": [
        {
          "title": "Title",
          "name": "title",
          "type": "string"
        },
        {
          "title": "Random",
          "name": "random",
          "type": "string",
          "default": "{{uniqueId}}-{{slug}}"
        },
      ]
    }
  ]
}
Xnapper-2022-07-21-14 05 53
Another test with a known placeholder from Front Matter: ```json { "frontMatter.taxonomy.contentTypes": [ { "name": "test", "pageBundle": false, "fields": [ { "title": "Title", "name": "title", "type": "string" }, { "title": "Random", "name": "random", "type": "string", "default": "{{uniqueId}}-{{slug}}" }, ] } ] } ``` <img width="504" alt="Xnapper-2022-07-21-14 05 53" src="https://user-images.githubusercontent.com/2900833/180199395-d7aaa0c7-02fb-4af4-82fe-22bf890ad2fd.png"> <!-- github-comment-id:1191351044 -->
Author
Owner
  • Added a new notification message when the content is being created. This is useful when some placeholders take up some time to process. Example: creating a social image on the fly.
  • Added the workspace path as the first argument.
  • Added a notification when the custom placeholder failed to process.
- Added a new notification message when the content is being created. This is useful when some placeholders take up some time to process. Example: creating a social image on the fly. - Added the workspace path as the first argument. - Added a notification when the custom placeholder failed to process. <!-- github-comment-id:1196520927 -->
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#280