Enhancement: Better setup options for custom scripts (and actions) #407

Closed
opened 2026-10-05 02:45:36 +02:00 by adam · 6 comments
Owner

Currently (it seems) all custom scripts are added to the Actions box and available in all content types. Shutting it off is only possible by removing that meta box from the view (with a custom view mode for instance).

The following is a current sample in my system:

20230227-18:15:41-Selection-001

  • I would love to remove the "Optimize slug" button. It is an internal action, so I can't just delete the config option
  • Starting and stopping the server might be done outside of the CMS. Even if not, it would use up less space by being a "switch" button. "Start server" if it's off, "Stop server" if it's on.
  • "Open Preview" should be only available when the server is running
  • Custom action youtube - I would love to show these buttons only where they are needed, based on content type. The youtube preview button for instance would show up only in type: video posts.
  • Or: based on frontmatter. The unsplash button only if a field/group unsplash is defined in the frontmatter of the current post.

In general the sidebar tends to be very long and cluttered on post pages. Showing things conditionally or collapse all boxes might help.

In short:

  • custom actions based on content type
  • disable/enable internal actions (like server start/stop) and optimize how they show up
  • conditional rules where to show custom actions based on frontmatter variables
  • a config option to collapse all boxes by default (or all boxes after a selected one) would be nice.
Currently (it seems) all [custom scripts](https://frontmatter.codes/docs/custom-actions) are added to the Actions box and available in all content types. Shutting it off is only possible by removing that meta box from the view (with a custom view mode for instance). The following is a current sample in my system: ![20230227-18:15:41-Selection-001](https://user-images.githubusercontent.com/83281/221549893-61d24ad7-1543-4261-98a5-124dd0cea1f6.png) - I would love to remove the "Optimize slug" button. It is an internal action, so I can't just delete the config option - Starting and stopping the server might be done outside of the CMS. Even if not, it would use up less space by being a "switch" button. "Start server" if it's off, "Stop server" if it's on. - "Open Preview" should be only available when the server is running - Custom action youtube - I would love to show these buttons only where they are needed, based on content type. The youtube preview button for instance would show up only in `type: video` posts. - Or: based on frontmatter. The unsplash button only if a field/group `unsplash` is defined in the frontmatter of the current post. In general the sidebar tends to be very long and cluttered on post pages. Showing things conditionally or collapse all boxes might help. In short: - custom actions based on content type - disable/enable internal actions (like server start/stop) and optimize how they show up - conditional rules where to show custom actions based on frontmatter variables - a config option to collapse all boxes by default (or all boxes after a selected one) would be nice. <!-- github-sync-id:1600995970 -->
adam closed this issue 2026-10-05 02:45:36 +02:00
Author
Owner

Thanks, @davidsneighbour; some enhancements can be made to the custom actions.

  • Custom actions based on the content-type is a good idea!
  • Disable/enable internal actions is a good idea, I will check what I can do for this
  • Wouldn't you already have the field defined in the content-type? It might be easier to specify multiple content types for a script.
  • Not sure if I understand this, can you clarify this a bit?

Something else: knowing when the server is running is a bit trickier (for the stop and preview actions), as some only sometimes use the start action. You could run it separately.

Thanks, @davidsneighbour; some enhancements can be made to the custom actions. - Custom actions based on the content-type is a good idea! - Disable/enable internal actions is a good idea, I will check what I can do for this - Wouldn't you already have the field defined in the content-type? It might be easier to specify multiple content types for a script. - Not sure if I understand this, can you clarify this a bit? Something else: knowing when the server is running is a bit trickier (for the stop and preview actions), as some only sometimes use the start action. You could run it separately. <!-- github-comment-id:1458313610 -->
Author
Owner

Something else: knowing when the server is running is a bit trickier (for the stop and preview actions), as some only sometimes use the start action. You could run it separately.

This has been implemented #652

> Something else: knowing when the server is running is a bit trickier (for the stop and preview actions), as some only sometimes use the start action. You could run it separately. This has been implemented #652 <!-- github-comment-id:1744850527 -->
Author
Owner

The ability to hide custom actions per content type has been added:

{
  "frontMatter.custom.scripts": [{
      "title": "Generate social image",
      "script": "./scripts/social-img.js",
      "command": "~/.nvm/versions/node/v16.19.0/bin/node",
      "contentTypes": ["post"]
    }]
}

All you need to do is add the contentTypes property to the custom script and specify the content type names for which you want to enable the custom script. Once you do this, the custom action will only appear for the list of specified content types in the panel.

The ability to hide custom actions per content type has been added: ```json { "frontMatter.custom.scripts": [{ "title": "Generate social image", "script": "./scripts/social-img.js", "command": "~/.nvm/versions/node/v16.19.0/bin/node", "contentTypes": ["post"] }] } ``` All you need to do is add the `contentTypes` property to the custom script and specify the content type names for which you want to enable the custom script. Once you do this, the custom action will only appear for the list of specified content types in the panel. <!-- github-comment-id:1746546753 -->
Author
Owner

A new setting frontMatter.panel.actions.disabled is available for defining which actions you want to hide:

{
  "frontMatter.panel.actions.disabled": [
    "openDashboard",
    "createContent",
    "optimizeSlug",
    "preview",
    "openOnWebsite",
    "startStopServer",
    "customActions"
  ]
}
A new setting `frontMatter.panel.actions.disabled` is available for defining which actions you want to hide: ```json { "frontMatter.panel.actions.disabled": [ "openDashboard", "createContent", "optimizeSlug", "preview", "openOnWebsite", "startStopServer", "customActions" ] } ``` <!-- github-comment-id:1746698841 -->
Author
Owner

To collapse all zones, you can use the following action:

image

To collapse all zones, you can use the following action: ![image](https://github.com/estruyf/vscode-front-matter/assets/2900833/8c5cd176-0134-4c89-ad9b-d6feee5b3f7e) <!-- github-comment-id:1746764430 -->
Author
Owner

I am sorry, I never saw your answers to my report. Those all are good options, thanks for the hard work :)

I am sorry, I never saw your answers to my report. Those all are good options, thanks for the hard work :) <!-- github-comment-id:1751903097 -->
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#407