readwiseio / obsidian-readwise

Official Readwise plugin for Obsidian
GNU General Public License v3.0
239 stars 23 forks source link

Feature Request: Add {{ domain }} metadata attribute to documents #32

Open mbaltrusitis opened 1 year ago

mbaltrusitis commented 1 year ago

user story.

As an Obsidian user I want to enter the domain of a URL as part of my document metadata so that I may explore the relationships between my notes and which sites I am most often using as reference or source material.

example.

Given the following Jinja template:

### metadata.
{% if url -%}
- Site: [[ {{domain}} ]]
- URL: {{url}}
{% endif -%}

And the following document input:

{
  "title": "How a worm gave the south a bad name",
  "url": "https://www.pbs.org/wgbh/nova/article/how-a-worm-gave-the-south-a-bad-name/"
}

I want the following output:

### metadata.
- URL: https://www.pbs.org/wgbh/nova/article/how-a-worm-gave-the-south-a-bad-name/
- domain: [[pbs.org]]

supplemental information.

polygami commented 1 year ago

I'm not sure if this applies to Reader only or Readwise in general. In my case, it's an issue with notes created in Reader. Because I can't seem to use an if block with a someString.contains() method or use RegEx to manually extract a domain name, I am stuck with having "reader" as the source, when I actually want the original source domain.

There are also other metadata attributes which are visible in Reader, but not accessible in templates. The other notable one is type.

writtenfool commented 1 year ago

Thanks for this thread, I've wondered as well. Jinja examples for this Readwise - Obsidian interface are few and far between. Also check the Readwise API docs - https://readwise.io/api_deets

it seems we need to split the source_url into pieces and then parse out the domain. For me, I only want URL's for web addresses (not Kindle books, for example), so you may want to filter with an if. Try something like this - note this is off the cuff... I'm days away from my desktop.

{% if source == "web_clipper" -%} {% set weburl = source_url.split('.') %} {% endif %}

-- split by each period in the url -- concatenate items 1 and 2 (0 is the http stuff) -- tilde is the concatenate function

{% mydomain = weburl[1] ~ weburl[2] %}

Hope this helps.