Enhancement: Enumerate indices as filePrefix #666

Closed
opened 2026-10-05 02:59:26 +02:00 by adam · 8 comments
Owner

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 -->
adam closed this issue 2026-10-05 02:59:26 +02:00
Author
Owner

Thanks, @wottpal, for the suggestion.

The issue is linked to #841

Thanks, @wottpal, for the suggestion. The issue is linked to #841 <!-- github-comment-id:2330856294 -->
Author
Owner

@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 -->
Author
Owner

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 -->
Author
Owner

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.

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 -->
Author
Owner

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 -->
Author
Owner

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 -->
Author
Owner

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 -->
Author
Owner

This functionality is now part of the v10.4.0 main release.

This functionality is now part of the `v10.4.0` main release. <!-- github-comment-id:2373238993 -->
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#666