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: Enumerate indices as filePrefix #844

Closed
wottpal opened this issue Aug 26, 2024 · 8 comments
Closed

Enhancement: Enumerate indices as filePrefix #844

wottpal opened this issue Aug 26, 2024 · 8 comments
Labels
enhancement New feature or request In BETA The current task is available for testing in the BETA version. v10.4.0 Project: v10.4.0

Comments

@wottpal
Copy link
Contributor

wottpal commented Aug 26, 2024

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}-.
@wottpal wottpal added the enhancement New feature or request label Aug 26, 2024
@estruyf
Copy link
Owner

estruyf commented Sep 5, 2024

Thanks, @wottpal, for the suggestion.

The issue is linked to #841

@estruyf
Copy link
Owner

estruyf commented Sep 12, 2024

@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?

@project-labels project-labels bot added v10.4.0 Project: v10.4.0 Ready This is ready to be picked up labels Sep 12, 2024
@wottpal
Copy link
Contributor Author

wottpal commented Sep 12, 2024

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?

@estruyf
Copy link
Owner

estruyf commented Sep 13, 2024

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.

estruyf added a commit that referenced this issue Sep 13, 2024
@estruyf
Copy link
Owner

estruyf commented Sep 13, 2024

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.

@project-labels project-labels bot added To document This item needs to be documented and removed Ready This is ready to be picked up labels Sep 13, 2024
@wottpal
Copy link
Contributor Author

wottpal commented Sep 18, 2024

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

@estruyf
Copy link
Owner

estruyf commented Sep 19, 2024

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.

@estruyf estruyf mentioned this issue Sep 25, 2024
@project-labels project-labels bot added Released The task has been released and removed To document This item needs to be documented labels Sep 25, 2024
@estruyf estruyf closed this as completed Sep 25, 2024
@project-labels project-labels bot added In BETA The current task is available for testing in the BETA version. and removed Released The task has been released labels Sep 25, 2024
@estruyf
Copy link
Owner

estruyf commented Sep 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request In BETA The current task is available for testing in the BETA version. v10.4.0 Project: v10.4.0
Projects
None yet
Development

No branches or pull requests

2 participants