oleeskild / obsidian-digital-garden

MIT License
1.36k stars 124 forks source link

Dataview Remove Broken Links #619

Closed wchorski closed 2 months ago

wchorski commented 2 months ago

When using dataview to list recently updated notes, it looks like non published notes are listed as well.

Is there any way to either

  1. skip over unpublished notes
  2. remove broken links

Dataview Example

TABLE dateformat(file.mtime, "dd.MM.yyyy - HH:mm") AS "Last modified"
FROM "mynotes"
SORT file.mtime DESC
LIMIT 10

What the Published site looks like

image

all broken links point to https://pywrite-garden.tawtaw.site/404/

stalegjelsten commented 2 months ago

Hi @wchorski, adding where dg-publish to your Dataview query would probably fix this.

TABLE dateformat(file.mtime, "dd.MM.yyyy - HH:mm") AS "Last modified"
FROM "mynotes"
WHERE dg-publish
SORT file.mtime DESC
LIMIT 10

If you would like to have all your notes listed in Obsidian, but only show the published notes in the dataview tables in your digital garden you can use the following "hack".

In your dataview queries, add a line containing WHERE file.mtime in a separate line, e.g.

TABLE dateformat(file.mtime, "dd.MM.yyyy - HH:mm") AS "Last modified"
FROM "mynotes"
WHERE file.mtime
SORT file.mtime DESC
LIMIT 10

(It doesn't need to be file.mtime, but choose something which matches all notes, but at the same time is not something you would ever add an actual where filter for).

Then you can use a Digital garden custom filter which replaces WHERE file.mtime with WHERE dg-publish 👇

image
wchorski commented 2 months ago

Thank you. This is exactly what I needed. The flexibility of having my dataviews in my local vault vs my garden can be reflected or filtered on publish lets me do whatever I want per dataview.

Also, this gives me more ideas on how to use custom filters. (i'm gonna put this tip in my vault too)