Skip to content

Commit

Permalink
[create-pull-request] automated change (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: akosbalasko <[email protected]>
  • Loading branch information
github-actions[bot] and akosbalasko committed Sep 3, 2021
1 parent 33799c4 commit 2575232
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dataview-plugin-snippet-showcase.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<meta property="og:description" content="A place to find and post code snippets used in the Dataview plugin created by Discord user blacksmithgu#1946. Edit: In a recent update, various functions have been introduced! Checkout the docs to learn more about their usage. Edit: I gave a live Obsidian Talk on the basics of Dataview, as well as some more advanced stuff. You can find the recordings of the live session here: Part 1: Metadata and Basic-to-Intermediate Dataview Part 2: More advanced Dataview stuff" />
<meta name="twitter:description" content="A place to find and post code snippets used in the Dataview plugin created by Discord user blacksmithgu#1946. Edit: In a recent update, various functions have been introduced! Checkout the docs to learn more about their usage. Edit: I gave a live Obsidian Talk on the basics of Dataview, as well as some more advanced stuff. You can find the recordings of the live session here: Part 1: Metadata and Basic-to-Intermediate Dataview Part 2: More advanced Dataview stuff" />
<meta name="twitter:label1" value="Reading time" />
<meta name="twitter:data1" value="54 mins 🕑" />
<meta name="twitter:data1" value="55 mins 🕑" />
<meta name="twitter:label2" value="Likes" />
<meta name="twitter:data2" value="746 ❤" />
<meta property="article:published_time" content="2021-02-26T06:12:05+00:00" />
Expand Down
2 changes: 1 addition & 1 deletion lastPostId.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
400
439
15 changes: 15 additions & 0 deletions scripts/M_bot_1627659031000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title:
author: M_bot (https://forum.obsidian.md/u/M_bot)
Publication Date: Fri Jul 30 2021
Last modification Date: Fri Jul 30 2021
---


<p>Since 0.4.0, <code>econtains</code> or &#x201C;exact contains&#x201D; allows you to look for exact matches only rather than substrings. There isn&#x2019;t documentation on it quite yet but the following should hopefully work</p>
<pre><code class="lang-auto">```dataview
TABLE Season
WHERE econtains(School, &quot;FHS&quot;)
```
</code></pre>
16 changes: 16 additions & 0 deletions scripts/M_bot_1628347515000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title:
author: M_bot (https://forum.obsidian.md/u/M_bot)
Publication Date: Sat Aug 07 2021
Last modification Date: Sat Aug 07 2021
---


<p>I&#x2019;ve only taken a quick glance but you should be able to do the same in regular dataview. Just in case anyone wants add on without having to use JS</p>
<pre><code class="lang-auto">```dataview
list
where contains(this.file.inlinks, file.link)
and !contains(this.file.outlinks, file.link)
```
</code></pre>
55 changes: 55 additions & 0 deletions scripts/Moonbase59_1628345823000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title:
author: Moonbase59 (https://forum.obsidian.md/u/Moonbase59)
Publication Date: Sat Aug 07 2021
Last modification Date: Sat Aug 07 2021
---


<h2>List of backlinks not including outgoing links from this note</h2>
<p>I made a short description, so that everyone can follow how to do things like that. It requires <code>```dataviewjs</code> though.</p>
<h3>Here&#x2019;s what it looks like</h3>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.obsidian.md/uploads/default/original/3X/f/0/f09e077225825f21ded236a385e6321293097863.png" data-download-href="https://forum.obsidian.md/uploads/default/f09e077225825f21ded236a385e6321293097863" title="Test Dataview - List of backlinks not including outgoing links from this note.md () - Knowledgebase - Obsidian_001"><img src="https://forum.obsidian.md/uploads/default/optimized/3X/f/0/f09e077225825f21ded236a385e6321293097863_2_430x500.png" alt="Test Dataview - List of backlinks not including outgoing links from this note.md () - Knowledgebase - Obsidian_001" data-base62-sha1="ykBaskRqxRjEBOIcNJ8o5SMnq95" width="430" height="500" srcset="https://forum.obsidian.md/uploads/default/optimized/3X/f/0/f09e077225825f21ded236a385e6321293097863_2_430x500.png, https://forum.obsidian.md/uploads/default/optimized/3X/f/0/f09e077225825f21ded236a385e6321293097863_2_645x750.png 1.5x, https://forum.obsidian.md/uploads/default/optimized/3X/f/0/f09e077225825f21ded236a385e6321293097863_2_860x1000.png 2x" data-small-upload="https://forum.obsidian.md/uploads/default/optimized/3X/f/0/f09e077225825f21ded236a385e6321293097863_2_10x10.png"><div class="meta">
<svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"/></svg><span class="filename">Test Dataview - List of backlinks not including outgoing links from this note.md () - Knowledgebase - Obsidian_001</span><span class="informations">892&#xD7;1035 85.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"/></svg>
</div></a></div><p></p>
<h3>Here&#x2019;s the code</h3>
<pre><code class="lang-auto"># List of backlinks not including outgoing links from this note

An outlink: [[Test Dataview Links]]

### outlinks

```dataview
list from outgoing([[#]])
```

### inlinks

```dataview
list from [[#]]
```

### Backlinks w/o the outgoing links

You can simply filter one array&apos;s elements by setting the condition based on other array&apos;s elements.

The `some()` method tests whether at least one element in the array passes the test implemented by the provided function. And I&#x2019;ve added a function which just checks if the inlink path exists in the outlinks array with the same value to be able to filter from the first array using a `not` (`!`).

#### Long form for better understanding

```dataviewjs
var outlinks = dv.current().file.outlinks;
var inlinks = dv.current().file.inlinks;

dv.list(inlinks.filter(i =&gt; !outlinks.some(o =&gt; o.path === i.path)));
```

#### Short form

```dataviewjs
dv.list(dv.current().file.inlinks
.filter(i =&gt; !dv.current().file.outlinks.some(
o =&gt; o.path === i.path)));
```
</code></pre>
26 changes: 26 additions & 0 deletions scripts/allenormond_1627055184000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title:
author: allenormond (https://forum.obsidian.md/u/allenormond)
Publication Date: Fri Jul 23 2021
Last modification Date: Fri Jul 23 2021
---


<p>Any reliable way to filter by checking if an array includes a value? I have files with:</p>
<pre><code class="lang-auto">---
School: [NFHS]
---
</code></pre>
<p>and</p>
<pre><code class="lang-auto">---
School: [NFHS, FHS]
---
</code></pre>
<p>When I use the following, both files are returned:</p>
<pre><code class="lang-auto">```dataview
TABLE Season
WHERE contains(School,&quot;FHS&quot;)
</code></pre>
<p>Any way to create a query that would only return the second file?<br>
Thanks!</p>

35 changes: 35 additions & 0 deletions scripts/macdrifter_1630668027000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title:
author: macdrifter (https://forum.obsidian.md/u/macdrifter)
Publication Date: Fri Sep 03 2021
Last modification Date: Fri Sep 03 2021
---


<p>EDIT:</p>
<p>&#x201C;econtains&#x201D; is the wrong operator. This query works:</p>
<pre><code>```dataview
LIST
WHERE contains(company,&quot;Disney&quot;)
```
</code></pre>
<p>====================</p>
<p>I&#x2019;ve seen several examples on here of using the WHERE clause in interesting ways but none seem to address my use case. I&#x2019;d like to use a WHERE LIKE style phrase. I understand that the closest to a &#x201C;LIKE&#x201D; operator is the &#x201C;contains&#x201D; clause in Dataview.</p>
<p>Use Case follows.</p>
<p>I use meta fields to create a lite CRM in Obsidian.</p>
<p>I have &#x201C;company&#x201D; notes spread across multiple folders in Obsidian. When I create a note for a person I will add a YAML field for &#x201C;company&#x201D; and use internal linking to insert the company name property.</p>
<p>I have a field for &#x201C;company&#x201D; that looks like this for each &#x201C;person&#x201D; note:</p>
<pre><code>---
company: [[Notes/Disney]]
date: 2021-09-03
tags: contact
---
</code></pre>
<p>I&#x2019;d like to use Dataview to display all notes with the company &#x201C;Disney&#x201D; meta field. I don&#x2019;t want to worry about the folder that the &#x201C;Disney&#x201D; note is in. I&#x2019;ve tried variations of this Dataview query but they all fail:</p>
<pre><code>```dataview
LIST
WHERE econtains(company,&quot;Disney&quot;)
```
</code></pre>
<p>I get zero result for the above query</p>
31 changes: 31 additions & 0 deletions scripts/pseudometa_1628872449000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title:
author: pseudometa (https://forum.obsidian.md/u/pseudometa)
Publication Date: Fri Aug 13 2021
Last modification Date: Fri Aug 13 2021
---


<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.obsidian.md/uploads/default/original/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54.png" data-download-href="https://forum.obsidian.md/uploads/default/355a6d274b43c8b611671d7ea37ca7c7fccb8d54" title="129053094-6dcbb2e5-fc40-4038-93f2-07223ce6bcc2"><img src="https://forum.obsidian.md/uploads/default/optimized/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54_2_517x202.png" alt="129053094-6dcbb2e5-fc40-4038-93f2-07223ce6bcc2" data-base62-sha1="7BZ2HrRbrusk7HhHW2PoP66UP7S" width="517" height="202" srcset="https://forum.obsidian.md/uploads/default/optimized/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54_2_517x202.png, https://forum.obsidian.md/uploads/default/optimized/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54_2_775x303.png 1.5x, https://forum.obsidian.md/uploads/default/original/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54.png 2x" data-small-upload="https://forum.obsidian.md/uploads/default/optimized/3X/3/5/355a6d274b43c8b611671d7ea37ca7c7fccb8d54_2_10x10.png"><div class="meta">
<svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"/></svg><span class="filename">129053094-6dcbb2e5-fc40-4038-93f2-07223ce6bcc2</span><span class="informations">937&#xD7;368 34 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"/></svg>
</div></a></div><p></p>
<pre><code class="lang-auto">```dataview
TABLE round(file.size * 1.005) as &quot;Character Est.&quot;, round(file.size * 1.005 / 4.79) as &quot;Word Est. (English)&quot;
FROM &quot;folder&quot;
```
</code></pre>
<p>This is a simple snippet to display character count of all notes in a folder &amp; also calculate an <em>estimate</em> of the word count.</p>
<p>Since dataview only offers <code>file.size</code> as attribute, there were some workarounds to achieve this:</p>
<ul>
<li>One character takes approximately <strong>1,005 bytes</strong>, <a href="https://stackoverflow.com/questions/32348137/obtaining-a-reliable-character-count-from-a-text-files-size-in-bytes" rel="noopener ugc">due to variable-width character encoding</a>
</li>
<li>According to a <a href="http:https://norvig.com/mayzner.html" rel="noopener ugc">comprehensive Google Books Analysis</a>, the average length of a word in an <strong>English</strong> text is <strong>4,79 characters</strong> long.</li>
<li>taken together, this results in <code>round(file.size * 1.005 / 4.79)</code> as an estimation for the word count.</li>
<li>if the notes are written in a different language, the factor will have to be adjusted. In German, for example, <a href="https://www.duden.de/sprachwissen/sprachratgeber/Durchschnittliche-Lange-eines-deutschen-Wortes" rel="noopener ugc">the average word in a given text is 5,99 characters long</a>.</li>
</ul>
<p>Caveats:</p>
<ul>
<li>the notes do appear in alphabetical order. If you are doing longform writing and the order of notes (chapters) is relevant, the notes need to have a specific numbering prepended.</li>
</ul>
<p>(I have created/contributed to feature requests at the <a href="https://github.com/blacksmithgu/obsidian-dataview/issues/397" rel="noopener ugc">dataview-plugin</a>, <a href="https://github.com/kevboh/longform/issues/14" rel="noopener ugc">longform-plugin</a>, and <a href="https://github.com/lukeleppan/better-word-count/issues/22" rel="noopener ugc">Better Word Count plugin</a>, hoping that one of them will implement a better and more precise solution, but until then, this snippet will have to do.)</p>

0 comments on commit 2575232

Please sign in to comment.