-
Notifications
You must be signed in to change notification settings - Fork 668
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
[Templates v2] Add a metadata syntax to templates #563
Comments
Hey @movermeyer! @riccardoferretti just gave me a walkthrough of the spec, thank you so much for working on this! The spec all makes sense to me. I was wondering, what is the purpose of the ---
filepath: "..."
---
---
tags: []
---
# Heading Great work on the specification, I like the direction and the way it unifies the handling of different features! |
Further, a suggestion: Since we're already adding template metadata, I wonder if we could also add fields such as |
@jevakallio We can do whatever makes sense. The syntax shown there is purely hypothetical to illustrate the point.
Neat. I think I like that. |
Here are some initial ideas for the syntax. IdealsIn descending order of importance:
A note on Markdown frontmatterThere is no formal specification of frontmatter and it seems that CommonMark isn't interested in specifying it either. Idea 1: Use a second frontmatter blockPut the foam-specific metadata into its own frontmatter block at the start of the file. ---
foam_template:
filepath: 'journal/${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}-${FOAM_TITLE}.md'
---
---
tags:
- movies
- top 10
- guy_ritchie
--- Q: If the file only has one frontmatter block, how do you tell if it is Foam related or not? A: That is why the attributes are namespaced under a Benefits
Detriments
Idea 2: Use attributes in a single frontmatter blockPlace any Foam-specific metadata in the same frontmatter block as everything else. If there is not frontmatter in the template, but there are Foam-specific metadata, then a frontmatter block is added specifically to hold the Foam-specific metadata. The metadata are namespaced under a ---
tags:
- movies
- top 10
- guy_ritchie
foam_template:
filepath: 'journal/${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}-${FOAM_TITLE}.md'
--- In cases where the frontmatter only contains Benefits
Detriments
Programmatic modification of YAMLYAML is notoriously difficult to programmatically manipulate. Removing The naive algorithm for doing this: parsed = YAML.parse(frontmatter)
parsed.delete("foam_template")
new_frontmatter = YAML.dump(parsed) Will produce dramatically different frontmatter than what was parsed. For example: ---
tags: # Add tags to increase SEO.
- movies
- top 10
- guy_ritchie
metadata: &info
title: The Gentlemen
year: 2019
more_metadata: *info # Required by our IMDB parser
foam_template:
filepath: 'journal/${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}-${FOAM_TITLE}.md'
--- Might become: ---
metadata: &1
title: The Gentlemen
year: 2019
tags: [movies, top 10, guy_ritchie]
more_metadata: *1
--- Note that they comments, list style, key order, and anchor/alias names were all lost in this roundtrip. This is because, by the YAML spec, parsers are required not to give any consideration to these stylistic elements when serializing. Trust me; I've spent far too much of my career wrangling with YAML parsers. 😢 Idea 3: Something else?INI, JSON, or some other format??? |
I like approach n. 2 for all the reasons you mentioned.
That should:
thoughts? |
@riccardoferretti I've implemented a first draft of this in #655. It allows the metadata to be added to an existing YAML frontmatter block, but only using a very limited syntax. There's still more to do in that PR, but it shows the direction I'm headed so far. |
Closing this now, since we have the ability to add metadata. |
As described in #534, we want to be able to template the default filepath of a template. Further, this templated filepath metadata should live within the template files themselves.
This requires specifying a syntax for use in template files where this metadata can be written, without being included in the files that are created from the template.
Create this syntax, and use it to allow for the specification of a default filepath for a template.
You should be able to template the filepath using variables just like any other content in the template.
Therefore, the process for creating a template file is:
Example
Using a "second front-matter" mock syntax (Note: this may not be the syntax we want, but is used for demonstration):
The text was updated successfully, but these errors were encountered: