obsidianmd / obsidian-clipper

Official web clipper extension for Obsidian.
https://obsidian.md
MIT License
545 stars 16 forks source link

Allowing `map` or `template` filter to work with string literal #81

Open 9diov opened 1 week ago

9diov commented 1 week ago

My use case is to add a prefix to a list of values, for example I want to extract Genres from a Goodreads page, and turn that into a list of Wikilink like this: ["genres/Nonfiction", "genres/Fitness"]. I thought that it is possible to do this with map and template filters but it turned out they only work with object-based items, not strings.

Describe the solution you'd like There are 2 ways transforming list of strings like above can be done:

kepano commented 3 days ago

Should be improved in 0.9.3 but some more work is needed. See readme.

TunaFFish commented 2 days ago

Hi, I am trying to do something similar. On a Medium.com Article page I find the tags which I than |map and want to prepend "Medium/" to the tags. Expected output:

tags:
   - Medium
   - Medium/Cooking
   - Medium/Healthy-Lifestyle

I tried a few things and believe this should be close: Medium, {{selector:a[href*='/tag/']|map:item => item|template:'Medium/${item}'|replace:' ':'-'|join:', '}} but that gives me Medium, Medium/Medium/Medium/Medium/Medium/

Please help. btw the Clipper is a Godsend, I was trying to get my Medium articles in Obsidian with the unofficial Medium API on RapidAPI but Clipper is gonna be so much cooler!

EDIT: looking better at the OP example I came up with: Medium, {{selector:a[href*='/tag/']|map:item => {str: item}|template:"Medium/${str}, "|replace:' ':'-'|join}} It gives me the desired output. Is this correct? Instead of delimiting the comma with |join do it in the |template?