question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: Allow frontmatter.json to be split in multiple files

See original GitHub issue

When describing complex content types, frontmatter.json quickly become a long and unreadable file. I just finished creating a content type describing Hugo various front-matter fields, and my frontmatter.json has 211 lines of content, and this is just with one complex content type and some frontmatter settings.

Hugo allows to split is configuration file in multiple files stored in config folder, and named according to the config section they store. An example of Hugo splitted config can be found at https://github.com/razonyang/hugo-theme-bootstrap-skeleton/tree/main/config/_default

Frontmatter could allow a similar setup in .frontmatter/config to allow an atomic configuration.

Another option is to allow the use of an import directive in frontmatter.json where the user explicitly import another file in lieu of a parameter value.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
estruyfcommented, Sep 29, 2022

Pushed the current change for the new beta. The feature is not yet complete, but already available to give it a try to see if we’re on the right path.

Current settings which can be split into folders/files are:

  • Content-types: .frontmatter/config/taxonomy/contentTypes
  • Page folders: .frontmatter/config/taxonomy/pageFolders
  • Placeholders: .frontmatter/config/taxonomy/placeholders
  • Snippets: .frontmatter/config/taxonomy/snippets

I’ve also created a sample project: https://github.com/FrontMatter/project-samples/tree/main/docusaurus

Let me know what you think.

2reactions
michaeltlombardicommented, Sep 24, 2022

My only suggestion to the proposal outlined is that the convention always replace . with folder level, so instead of (not reordered for alphabetic sorting, sorry):

.
β”œβ”€β”€ .frontmatter/
β”‚   └── config/
β”‚       β”œβ”€β”€ taxonomy.contentTypes/
β”‚       β”‚   └── *.json
β”‚       β”œβ”€β”€ taxonomy.contentTypes.json
β”‚       β”œβ”€β”€ content.placeholders/
β”‚       β”‚   └── *.json
β”‚       β”œβ”€β”€ content.placeholders.json
β”‚       β”œβ”€β”€ content.snippets/
β”‚       β”‚   └── *.json
β”‚       └── content.snippets.json
└── .frontmatter.json

It would be:

.
β”œβ”€β”€ .frontmatter/
β”‚   └── config/
β”‚       └── taxonomy/
β”‚       β”‚   β”œβ”€β”€ contentTypes/
β”‚       β”‚   β”‚   └── *.json
β”‚       β”‚   β”œβ”€β”€ contentTypes.json
β”‚       └── content/
β”‚           β”œβ”€β”€ placeholders/
β”‚           β”‚   └── *.json
β”‚           β”œβ”€β”€ placeholders.json
β”‚           β”œβ”€β”€ snippets/
β”‚           β”‚   └── *.json
β”‚           └── snippets.json
└── .frontmatter.json

I think those three sections - taxonomy.contentTypes, content.snippets, and content.placeholders make enormous sense for a first pass. I think in the future it would absolutely be useful to be able to do data.*, taxonomy.fieldGroups, and taxonomy.customTaxonomy.

For me, the ideal end state is to be able to have most or all fields definable via this split definition, with non-arrays defined in their nearest ancestor .json. For example:

// .frontmatter/config/taxonomy.json
{
  "frontMatter.taxonomy.seoContentLength": 1760,
  "frontMatter.taxonomy.seoDescriptionField": "description",
  // etc for the non-arrays
}
// .frontmatter/config/taxonomy/contentTypes/foo.json
{
  "name": "foo",
  "pageBundle": false,
  "fields": [
    {
      "title": "Title",
      "name": "title",
      "type": "string",
      "single": true
    },
    // snipped for brevity
  ]
}
// .frontmatter/config/taxonomy/contentTypes/bar.json
{
  "name": "bar",
  "pageBundle": false,
  "fields": [
    {
      "title": "Title",
      "name": "title",
      "type": "string",
      "single": true
    },
    // snipped for brevity
  ]
}

With the deterministic file/folder name, we could know what schema to apply where.

On possible future DevX

In the example above, I used the full key names in the split config. To be very clear, I believe that’s how this should be implemented initially because I expect it’s the least amount of work. However, I think a possible enhanced UX would be this instead:

// .frontmatter/config/taxonomy.json
{
  "seoContentLength": 1760,
  "seoDescriptionField": "description",
  // etc for the non-arrays
}

But that would require some schema rework (or copying the schema partially and maintaining it separately, which seems rough - def more thought needs to go into the maintainability of something like this). I just wanted to note it here because if I didn’t do it now, I would entirely forget.

I really, really like this proposal. I also think sorting this out is something of a prerequisite for #407, especially since this model would make maintaining β€œpackaged” configurations easier and will already require some work on merging. This is also much more relevant to the majority of the user base.

My own config file is 767 lines long without the hundreds of lines I would need for my data type definitions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enhancement: Extending another config Β· Issue #407 - GitHub
I've been working through configuring Front Matter for my site ... Enhancement: Allow frontmatter.json to be split in multiple files #412.
Read more >
Settings - Front Matter CMS
Some of the Front Matter settings can be split in multiple files to make management of these easier. For example, in case you...
Read more >
Option to Separate Front Matter and Content into Different Files
My proposal is for front matter to optionally be stored in a separate toml/yaml/json file which has the same name as the .md...
Read more >
Is there a YAML front matter standard / validator?
I was too in need of a Frontmatter YAML validator, against JSON Schema, as you would with a pure YAML or JSON file,...
Read more >
Supercharge Your Bridgetown Site with Ruby Front Matter
Enable Ruby Front Matter only if you feel confident in your ability to control and monitor all on-going updates to repository files and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found