mdtags2dir

Posted

mdtags2dir is a small program I wrote to keep in sync a selection of my Markdown notes stored in Dropbox (flat directory structure) and my website (hierarchical directory structure). I tag with public all the notes that should be copied to my website’s directory.

Since it’s easier to show than to explain what it does, consider the file-naming scheme used by Denote:

DATE--TITLE__TAG1_TAG2_TAGN.md

And a Markdown file which follows the scheme named 20230317T185705--note__public_updates_life.md with the content:

---
title: "Note"
tags: ["public" "updates" "life"]
---

If you run:

$ mdtags2dir -target /tmp/test 20230317T185705--note__public_updates_life.md

The file will be copied to /tmp/test under three different subdirectories (one per tag), and each copy will be renamed to TITLE.md:

$ find /tmp/test -type f
/tmp/test/public/note.md
/tmp/test/updates/note.md
/tmp/test/life/note.md

Filtering

Consider two Markdown files named 20230313T134742--note-01__public_updates.md and 20230316T032343--note-02__private.md with the content:

---
title: "Note 01"
tags: ["public" "updates"]
---
---
title: "Note 02"
tags: ["private"]
---

The following command will copy only 20230313T134742--note-01__public_updates.md as it’s the only one that matches the filter:

$ mdtags2dir -target /tmp/test -filter public ~/my-notes
$ find /tmp/test -type f
/tmp/test/updates/note-01.md

Note that it doesn’t copy the file to the matching subdirectory of the used filter (i.e. the file is not copied to /tmp/test/public/note-01.md).

The following command will copy only 20230316T032343--note-02__private.md and use a default tag after filtering:

$ mdtags2dir -target /tmp/test -filter private -default notes ~/my-notes
$ find /tmp/test -type f
/tmp/test/notes/note-02.md