Keep resources of one type, such as tasks, in a directory of Markdown files, one per resource, as Obsidian keeps notes. Since each change only touches the file of the resource changed, a file synchronization tool (Syncthing, Dropbox, etc.) can merge changes made in several places.
A config is a map described by the ::config spec:
:path The directory's path. It's created, along with any missing parent directories, the first time a resource is saved, and a missing directory holds none
A component describes the type of resource stored:
:spec The spec a resource must satisfy to be saved
:encode A function of a resource to JSON-ready data: a map with only
the keys that are saved (see dgknght.json for dates and times)
:decode A function of a map read back from JSON with string keys to a
resource
:noun What the resource is called in error messages, e.g. "task"
Each file holds a resource's :description as its body, after a YAML front matter block with the rest of the encoded resource:
The good kind
Only the directory's own files whose names end in .md are read, and those whose names start with a dot are left out. A file with no front matter is all body, and a file with no :uid takes its name, less the extension, as its :uid. Front matter keys with no value are left out. Leading blank lines and trailing whitespace aren't part of the body, and a blank body is no :description.
A resource is identified by its :uid, and two files holding the same :uid (as a synchronization tool's conflict copy would) make the directory unreadable until one is removed. A resource's file is named after its :summary, or its :uid when it has none, with characters that aren't allowed in file names (or in Obsidian links) replaced with -. When another file has that name, a number is added ("Buy milk 2.md"). The file is renamed when its resource is saved with a :summary that gives another name.
Each file is replaced atomically so that a reader never sees it half written. The directory has no protection against several services or processes writing it at the same time, so callers serialize their changes and share one service per directory.
Failures throw an ex-info whose data has a :type of:
::invalid-config The config map isn't a valid ::config ::invalid-resource The resource can't be saved: it doesn't satisfy the component's :spec, or it's being deleted without a :uid ::invalid-file A file can't be read as a resource, two files hold the same :uid, or the path isn't a directory
Keep resources of one type, such as tasks, in a directory of Markdown
files, one per resource, as Obsidian keeps notes. Since each change only
touches the file of the resource changed, a file synchronization tool
(Syncthing, Dropbox, etc.) can merge changes made in several places.
A config is a map described by the `::config` spec:
:path The directory's path. It's created, along with any missing parent
directories, the first time a resource is saved, and a missing
directory holds none
A component describes the type of resource stored:
:spec The spec a resource must satisfy to be saved
:encode A function of a resource to JSON-ready data: a map with only
the keys that are saved (see `dgknght.json` for dates and times)
:decode A function of a map read back from JSON with string keys to a
resource
:noun What the resource is called in error messages, e.g. "task"
Each file holds a resource's :description as its body, after a YAML front
matter block with the rest of the encoded resource:
---
uid: 6b1f0c3e-2a4d-4e8f-9b7a-1c2d3e4f5a6b
summary: Buy milk
due: 2026-12-01
status: needs-action
---
The good kind
Only the directory's own files whose names end in .md are read, and those
whose names start with a dot are left out. A file with no front matter is
all body, and a file with no :uid takes its name, less the extension, as
its :uid. Front matter keys with no value are left out. Leading blank lines
and trailing whitespace aren't part of the body, and a blank body is no
:description.
A resource is identified by its :uid, and two files holding the same :uid
(as a synchronization tool's conflict copy would) make the directory
unreadable until one is removed. A resource's file is named after its
:summary, or its :uid when it has none, with characters that aren't
allowed in file names (or in Obsidian links) replaced with -. When another
file has that name, a number is added ("Buy milk 2.md"). The file is
renamed when its resource is saved with a :summary that gives another
name.
Each file is replaced atomically so that a reader never sees it half
written. The directory has no protection against several services or
processes writing it at the same time, so callers serialize their changes
and share one service per directory.
Failures throw an ex-info whose data has a :type of:
::invalid-config The config map isn't a valid ::config
::invalid-resource The resource can't be saved: it doesn't satisfy the
component's :spec, or it's being deleted without a
:uid
::invalid-file A file can't be read as a resource, two files hold
the same :uid, or the path isn't a directory(delete config {:keys [noun] :as component} {:keys [uid] :as resource})Deletes the file of the resource with the resource's :uid, if there is one, and returns nil.
Deletes the file of the resource with the resource's :uid, if there is one, and returns nil.
(fetch config component uid)Reads the resource with the :uid, or returns nil if there's none.
Reads the resource with the :uid, or returns nil if there's none.
(fetch-all config component)Reads every resource in the directory, or none when there's no directory.
Reads every resource in the directory, or none when there's no directory.
(save config component resource)Saves the resource to its file, renaming it if its :summary gives it another name, or to a new file when there's none, and returns it as saved. A resource without a :uid gets a new random UUID.
Saves the resource to its file, renaming it if its :summary gives it another name, or to a new file when there's none, and returns it as saved. A resource without a :uid gets a new random UUID.
(validate-config config)Throws an ::invalid-config unless the config is a valid ::config.
Throws an ::invalid-config unless the config is a valid ::config.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |