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

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

Open
9diov opened this issue Oct 7, 2024 · 2 comments
Open

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

9diov opened this issue Oct 7, 2024 · 2 comments

Comments

@9diov
Copy link

9diov commented Oct 7, 2024

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:

  • Allowing map to convert a string to an object then use template e.g. map:item => {str: item}|template:"genres/${str}"
  • A keyword such as _item to refer to the original item e.g. template:"genres/${_item}
@9diov 9diov changed the title Allowing map filter to work with string literal Allowing map or template filter to work with string literal Oct 7, 2024
@kepano
Copy link
Collaborator

kepano commented Oct 14, 2024

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

@TunaFFish
Copy link

TunaFFish commented Oct 15, 2024

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?

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

No branches or pull requests

3 participants