Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Allow custom scripts for custom placeholders #352

Closed
estruyf opened this issue Jun 9, 2022 · 3 comments
Closed

Enhancement: Allow custom scripts for custom placeholders #352

estruyf opened this issue Jun 9, 2022 · 3 comments
Labels
enhancement New feature or request Project: v8.1.0

Comments

@estruyf
Copy link
Owner

estruyf commented Jun 9, 2022

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.

@estruyf estruyf added the enhancement New feature or request label Jun 9, 2022
@estruyf
Copy link
Owner Author

estruyf commented Jul 21, 2022

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

@estruyf
Copy link
Owner Author

estruyf commented Jul 21, 2022

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

@estruyf
Copy link
Owner Author

estruyf commented Jul 27, 2022

  • 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.

estruyf added a commit that referenced this issue Sep 5, 2022
@estruyf estruyf closed this as completed Sep 22, 2022
@estruyf estruyf mentioned this issue Sep 22, 2022
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Project: v8.1.0
Projects
None yet
Development

No branches or pull requests

1 participant