Based on feedback from Discord, it would be useful to have the ability to use placeholders in the filePrefix template. That way, users can generate unique IDs for their files.
Documentation
Add information on the file prefix that placeholders can be used
Add information to the placeholder page
Update the default value from the frontMatter.templates.prefix setting
Based on feedback from Discord, it would be useful to have the ability to use placeholders in the `filePrefix` template. That way, users can generate unique IDs for their files.
## Documentation
- [x] Add information on the file prefix that placeholders can be used
- [x] Add information to the placeholder page
- [x] Update the default value from the `frontMatter.templates.prefix` setting
<!-- github-sync-id:2470099938 -->
@wottpal it is now possible in the beta to use placeholders for defining your file prefixes. You are also able to use a custom placeholders with which you would be able to generate an index number during the file creation.
import{PlaceholderScript}from"@frontmatter/extensibility";import{readdir}from"fs/promises";(async()=>{// Filepath is the directory path where the file will be created
const{filePath}=PlaceholderScript.getArguments();if(!filePath){PlaceholderScript.done(`000`);return;}constfiles=awaitreaddir(filePath);if(!files){PlaceholderScript.done(`000`);return;}// Return the number of files + 1 with leading zeros
PlaceholderScript.done((files.length+1).toString().padStart(3,`0`));})();
@wottpal it is now possible in the beta to use placeholders for defining your file prefixes. You are also able to use a custom placeholders with which you would be able to generate an index number during the file creation.
Example configuration:
```json
{
"frontMatter.content.pageFolders": [{
"title": "articles",
"path": "[[workspace]]/content/prefixes/",
"filePrefix": "{{indexNr}}"
}],
"frontMatter.content.placeholders": [{
"id": "indexNr",
"script": "./scripts/indexNr.mjs",
"command": "~/.nvm/versions/node/v18.17.1/bin/node"
}]
}
```
The script:
```js
import { PlaceholderScript } from "@frontmatter/extensibility";
import { readdir } from "fs/promises";
(async () => {
// Filepath is the directory path where the file will be created
const { filePath } = PlaceholderScript.getArguments();
if (!filePath) {
PlaceholderScript.done(`000`);
return;
}
const files = await readdir(filePath);
if (!files) {
PlaceholderScript.done(`000`);
return;
}
// Return the number of files + 1 with leading zeros
PlaceholderScript.done((files.length + 1).toString().padStart(3, `0`));
})();
```
Notice that the `@frontmatter/extensibility` library is used. More information on how to install it can be found here: https://frontmatter.codes/docs/custom-actions#extensibility-library
<!-- github-comment-id:2338034144 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Based on feedback from Discord, it would be useful to have the ability to use placeholders in the
filePrefixtemplate. That way, users can generate unique IDs for their files.Documentation
frontMatter.templates.prefixsetting@wottpal it is now possible in the beta to use placeholders for defining your file prefixes. You are also able to use a custom placeholders with which you would be able to generate an index number during the file creation.
Example configuration:
The script:
Notice that the
@frontmatter/extensibilitylibrary is used. More information on how to install it can be found here: https://frontmatter.codes/docs/custom-actions#extensibility-libraryThis functionality is now part of the
v10.4.0main release.