estruyf / vscode-front-matter

Front Matter is a CMS running straight in Visual Studio Code. Can be used with static site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...
https://frontmatter.codes
MIT License
1.85k stars 69 forks source link

Enhancement: Automation for creating a document and placing it in a configurable subfolder based on the title or date #825

Open Laincito opened 1 week ago

Laincito commented 1 week ago

Problem:

A website with thousands of documents in a collection becomes unmanageable if all documents are stored in the same folder, potentially exceeding the maximum number of files per folder allowed by the operating system.

To avoid this issue, subfolders are created within the main collection folder. The idea is to have a system that automatically creates the folder structure where the newly created document will be placed, based on the file name, similar to the "filePrefix" property but for automatically and configurable directory creation.

Proposed Solution:

Create a configuration parameter "subdir" where a template using placeholders can be configured.

For example, with this configuration:

{
  "frontMatter.content.pageFolders": [
    {
      "title": "Blog",
      "subdir": "{{year}}/{{month}}",
      "path": "[[workspace]]/src/content/blog"
    }
  ]
}

When creating a document titled "post," it would be generated in the folder "/src/content/blog/2024/06/post.md".

Additionally, it should be possible to use custom placeholders. For example, creating a placeholder that returns the first few characters of the title as a directory.

"subdir": "{{customPlaceholder}}"

We would create a script associated with the "customPlaceholder" that generates directories from the first few numbers: customPlaceholder(15678) => "1/5/6/7/".

So, if we created a document titled "345," it would be generated in the folder "/src/content/blog/3/4/345.md".