ebullient / ttrpg-convert-cli

Utility to convert JSON data (for content you own) from 5etools or pf2etools into Obsidian-friendly Markdown.
https://www.ebullient.dev/projects/ttrpg-convert-cli/
Apache License 2.0
152 stars 35 forks source link

šŸ› DnD 5e - not able to add item rarity into the frontmatter #419

Closed pwkooij closed 3 months ago

pwkooij commented 3 months ago

I am trying to add item rarity in the frontmatter, but I am not able to seem to pick up the information, and instead it throws an error.

I have tried several codes using resource.rarity or resource.detail.rarity, but I'm not able to extract that information

---
obsidianUIMode: preview
cssclasses: json5e-item
{#if resource.tags }
tags:
{#for tag in resource.tags}
- {tag}
{/for}
{/if}
aliases: 
- "{resource.name}"
{#if resource.variantAliases }
{resource.variantAliases}
{/if}
NoteIcon: ring
SourceType: Items
BookSource: ["{resource.source}"]
{#if resource.rarity }
Rarity: ["{resource.rarity}"]
{/if}
---

I would like the frontmatter output of the item to look like this:

---
obsidianUIMode: preview
cssclasses: json5e-item
tags:
- compendium/src/5e/dmg
- ttrpg-cli/item/rarity/uncommon
- ttrpg-cli/item/tier/minor
- ttrpg-cli/item/wondrous/wondrous-item
aliases: 
- "+1 Ammunition"
- "+1 Sling Bullet"
- "+1 Arrow"
- "+1 Modern Bullet"
- "+1 Blowgun Needle"
- "+1 Crossbow Bolt"
- "+1 Energy Cell"
- "+1 Renaissance Bullet"
NoteIcon: ring
SourceType: Items
BookSource: ["Dungeon Master's Guide p. 150. Available in the SRD."]
Rarity: ["uncommon"]
---

When I add the text as described above in the template file it results in the following errors for {resource.rarity}: [ šŸ›‘ ERR] io.quarkus.qute.TemplateException: Rendering error: Property "rarity" not found on the base object "dev.ebullient.convert.tools.dnd5e.qute.QuteItem" in expression {resource.rarity}

and for `{resource.detail.rarity} [ šŸ›‘ ERR] io.quarkus.qute.TemplateException: Rendering error: Property "rarity" not found on the base object "java.lang.String" in expression {resource.detail.rarity}

Configuration

Sources:

log file with run that included {resource.rarity} ttrpg-convert.txt

ebullient commented 3 months ago

detail is (currently) just a string, and item rarity/tier is only separately available as tags.

When an attribute has sub-attributes, I try to be clear about it in the docs, e.g.

sourceAndPage

Book sources as list of SourceAndPage

The latter SourceAndPage link shows the sub-attributes. I realize I was not clear in the detail description that it was a pre-formatted string containing those attributes.

Will think about how to capture those as sub-resources, they are not always present.

pwkooij commented 3 months ago

Thanks for the clarification! I would love to be able to add the rarity separately in the frontmatter to make it easier to parse with dataview

ebullient commented 3 months ago

You can already parse with dataview, as tags are supported natively and you have those.

pwkooij commented 3 months ago

I guess I have to go back study on how to use that hehe! Thanks again! And wow you respond fast! Not used to that on github, much appreciated!