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

Canonical metadata #27

Merged
merged 9 commits into from
Dec 31, 2024
Merged

Canonical metadata #27

merged 9 commits into from
Dec 31, 2024

Conversation

Zheoni
Copy link
Contributor

@Zheoni Zheoni commented Dec 22, 2024

This PR adds support for all the canonical metadata keys. I added a bunch of methods that will help the conversions from a YAML value to a known data structure/type.

The basic usage is something like

use cooklang::metadata::CooklangValueExt; // trait that adds more conversions to a YAML value

let metadata = &recipe.metadata;
let course = metadata.get(StdKey::Course)?.as_str()?;
let tags = metadata.get(StdKey::Tags)?.as_tags()?;

When the expected type is clear I added a more direct method. For example, for tags you can also do:

let tags = metadata.tags()?;

Time can now be always parsed from HhMm like the spec says. No spaces.

Also, when time is used with cook time and prep time, time always takes precedence. I know I asked in the discord but the serde_yaml::Mapping API made it difficult to implement last one gets preference, and this is much simpler. The warning is emitted telling the user prep time/cook time has been overriden so I think it's no big problem.


I dind't merge it myself just to confirm the API is ok and that I didn't missinterpret the spec.

@Zheoni Zheoni merged commit 6e5364b into main Dec 31, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant