When creating new content, it's currently possible to prepend the current date & year via the filePrefix attribute.
As we enumerate our files in subdirectories with indices (instead of dates) I would highly appreciate seeing this being automated via Frontmatter CMS.
Idea:
New filePrefix format: 0000- where the amount of 0s determines the index string-length (left-padded with 0s).
When a new file is being created it checks what's the currently highest index in the subdirectory and prefixes the filename with 000${i+1}-.
When creating new content, it's currently possible to prepend the current date & year via the [`filePrefix`](https://frontmatter.codes/docs/content-creation/additional-config#file-prefixes) attribute.
As we enumerate our files in subdirectories with indices (instead of dates) I would highly appreciate seeing this being automated via Frontmatter CMS.
**Idea:**
* New `filePrefix` format: `0000-` where the amount of `0`s determines the index string-length (left-padded with `0`s).
* When a new file is being created it checks what's the currently highest index in the subdirectory and prefixes the filename with `000${i+1}-`.
<!-- github-sync-id:2487316584 -->
@wottpal In issue #841, there is an example of including the above prefix by a custom placeholder.
Now, I'm thinking of making it part of the CMS, but I am not sure about the format.
For the index prefix, I see the following settings:
Nr of characters: 3 by default
Leading zeros: true by default
Exclude file extensions: undefined by default
The placeholder structure could look as follows:
# Using the defaults
{{idxNr}}
# Using other settings
{{idxNr|chars:4,zeros:true,exclude:mdx}}
What do you think?
@wottpal In issue #841, there is an example of including the above prefix by a custom placeholder.
Now, I'm thinking of making it part of the CMS, but I am not sure about the format.
For the `index` prefix, I see the following settings:
- Nr of characters: `3` by default
- Leading zeros: `true` by default
- Exclude file extensions: `undefined` by default
The placeholder structure could look as follows:
```
# Using the defaults
{{idxNr}}
# Using other settings
{{idxNr|chars:4,zeros:true,exclude:mdx}}
```
What do you think?
<!-- github-comment-id:2346547106 -->
Hey @estruyf, thanks for the addition & script in #841 - Just back to work today and I'll give it a try soon :)
What do you think?
I think this looks fantastic and could be really useful for everyone. One question though, what does the exclude property do? Is it about counting files in the directory to determine the current/next index and what files to (not) count?
Hey @estruyf, thanks for the addition & script in #841 - Just back to work today and I'll give it a try soon :)
> What do you think?
I think this looks fantastic and could be really useful for everyone. One question though, what does the `exclude` property do? Is it about counting files in the directory to determine the current/next index and what files to (not) count?
<!-- github-comment-id:2346985966 -->
One question though, what does the exclude property do?
It might not be required, but in some cases, other files are in the folder where you want to create your content. Just thinking about those cases where you want to make sure the index is based on the content files, and not the unrelated ones. Another way is to make the assumption there are only content files.
Welcome back!
> One question though, what does the exclude property do?
It might not be required, but in some cases, other files are in the folder where you want to create your content. Just thinking about those cases where you want to make sure the index is based on the content files, and not the unrelated ones. Another way is to make the assumption there are only content files.
<!-- github-comment-id:2348160039 -->
In the latest beta, the new placeholder is available and you can use it as follows:
# Default usage
{{filePrefix.index}}
# Leading zeros - 4 characters
{{filePrefix.index|zeros:4}}
# Turn off leading zeros
{{filePrefix.index|zeros:0}}
I have updated the name and its settings to make it clearer and easier to use.
In the latest beta, the new placeholder is available and you can use it as follows:
```
# Default usage
{{filePrefix.index}}
# Leading zeros - 4 characters
{{filePrefix.index|zeros:4}}
# Turn off leading zeros
{{filePrefix.index|zeros:0}}
```
I have updated the name and its settings to make it clearer and easier to use.
<!-- github-comment-id:2348805015 -->
Hey @estruyf, just tested the Beta and it works amazing so far. Just with one quirk: All counts are one off (+1) and I was able to figure out that this is related to invisible .DS_Store files created by macOS which are in every content directory. If I delete those, it works, but unfortunately they are re-created each time I visit the directory in the file explorer.
I would suggest either:
Ignoring .DS_Store files manually as they are quite common
Going with a whitelist-approach (instead of the suggested exclude parameter) which defaults to [frontMatter.content.defaultFileType].
Hey @estruyf, just tested the Beta and it works amazing so far. Just with one quirk: All counts are one off (+1) and I was able to figure out that this is related to invisible `.DS_Store` files created by macOS which are in every content directory. If I delete those, it works, but unfortunately they are re-created each time I visit the directory in the file explorer.
I would suggest either:
* Ignoring `.DS_Store` files manually as they are quite common
* Going with a whitelist-approach (instead of the suggested `exclude` parameter) which defaults to `[frontMatter.content.defaultFileType]`.
<!-- github-comment-id:2358964743 -->
Thanks, @wottpal, for verifying. I changed the logic slightly to exclude the hidden files and verify files against the frontMatter.content.supportedFileTypes setting. This should give better results.
Thanks, @wottpal, for verifying. I changed the logic slightly to exclude the hidden files and verify files against the `frontMatter.content.supportedFileTypes` setting. This should give better results.
<!-- github-comment-id:2360131534 -->
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.
When creating new content, it's currently possible to prepend the current date & year via the
filePrefixattribute.As we enumerate our files in subdirectories with indices (instead of dates) I would highly appreciate seeing this being automated via Frontmatter CMS.
Idea:
filePrefixformat:0000-where the amount of0s determines the index string-length (left-padded with0s).000${i+1}-.Thanks, @wottpal, for the suggestion.
The issue is linked to #841
@wottpal In issue #841, there is an example of including the above prefix by a custom placeholder.
Now, I'm thinking of making it part of the CMS, but I am not sure about the format.
For the
indexprefix, I see the following settings:3by defaulttrueby defaultundefinedby defaultThe placeholder structure could look as follows:
What do you think?
Hey @estruyf, thanks for the addition & script in #841 - Just back to work today and I'll give it a try soon :)
I think this looks fantastic and could be really useful for everyone. One question though, what does the
excludeproperty do? Is it about counting files in the directory to determine the current/next index and what files to (not) count?Welcome back!
It might not be required, but in some cases, other files are in the folder where you want to create your content. Just thinking about those cases where you want to make sure the index is based on the content files, and not the unrelated ones. Another way is to make the assumption there are only content files.
In the latest beta, the new placeholder is available and you can use it as follows:
I have updated the name and its settings to make it clearer and easier to use.
Hey @estruyf, just tested the Beta and it works amazing so far. Just with one quirk: All counts are one off (+1) and I was able to figure out that this is related to invisible
.DS_Storefiles created by macOS which are in every content directory. If I delete those, it works, but unfortunately they are re-created each time I visit the directory in the file explorer.I would suggest either:
.DS_Storefiles manually as they are quite commonexcludeparameter) which defaults to[frontMatter.content.defaultFileType].Thanks, @wottpal, for verifying. I changed the logic slightly to exclude the hidden files and verify files against the
frontMatter.content.supportedFileTypessetting. This should give better results.This functionality is now part of the
v10.4.0main release.