Markdown Curator

Java 25+ library/application framework for monitoring repositories of Markdown documents, running queries on them, and inserting the output back into the documents.

Java CI with Maven CodeQL

Reliability Rating Maintainability Rating Coverage

Markdown Curator

TL;DR

  • This is a Java 25+ library and small application framework for processing directories of Markdown documents.
  • It is especially well suited for Obsidian vaults and iA Writer libraries. More generally: for Markdown-based wikis that use wikilinks to link to other documents in the same wiki.
  • It detects queries in the documents, executes them, and writes back the results in the documents themselves.
  • It extracts information out of documents as properties and writes them into documents as front matter.
  • As an application, it monitors and processes directories and files in the background.
  • As an application, optionally, it runs an HTTP server that exposes the curators, documents, and queries for use in local automation.

Even shorter: this tool allows you to keep your static content DRY.

The 5-minute introduction

This is a Java library and application framework that spins up a daemon. This daemon monitors one or more wikis: directories of Markdown documents like Obsidian vaults or iA Writer libraries. Based on changes happening in the directories and the Markdown documents, it detects and runs queries embedded in the documents, generates Markdown output for these queries and embeds this output in the documents themselves. It can update the front matter in the documents with properties derived from the content.

Here's an example of what you can write in a Markdown document:

<!--query:list
folder: Articles
-->
THE OUTPUT WILL GO HERE
<!--/query-->

Put this snippet (without the code block) in a document in a directory tracked by this tool, save it, and watch THE OUTPUT WILL GO HERE be magically replaced with a sorted list of links to documents in the Articles subdirectory. Add a new article there, delete one, or update an existing one, and watch the list get updated instantly.

Or, I should say: after 3 seconds. This is the default delay for processing files after changes are detected; it can be changed with the delay setting in the configuration document (see Curator settings). This delay is needed for Obsidian, which automatically saves files every few seconds when you're typing in them. If in the space of the 3-second delay another change is detected, the scheduled processing run is aborted, and a new one is scheduled to run, again in 3 seconds. This little trick ensures the processing doesn't happen unnecessarily often.

The query syntax may weird at first, but notice that it is built up of HTML comment tags. That means that the query definitions disappear from view when you preview the Markdown, or when you export it to another format using the tool of your choice, leaving you with nothing but the query output. In effect, the query syntax is invisible to any tool that processes Markdown correctly.

What can a query do? Anything you can code in Java! The internal API of this tool allows you to extract all kinds of information from your documents or elsewhere and use them in queries.

Don't know which queries are available? Put a blank query in a document in a vault and save it:

<!--query-->
<!--/query-->

After the curator has kicked in, you'll see an overview of all queries available.

By default, this tool provides a limited set of built-in generic queries. See the section on those below for more details. These are useful queries, but to make this tool shine, you will want to create your own queries.

This tool provides several useful, optional queries, in separate modules. By plugging in these modules into your application you instantly gain additional queries to use.

To use this system, you have to code your own Java application, define this tool as a dependency, and implement your own curator, custom change processors, and custom queries. See further on for an example.

The markdown-demo-curator provides a simple example of a repository of notes and an application on top of it to monitor it for changes and process queries.

The template-application folder holds a minimal template for creating your own curator.

Vincent's Markdown Curator (vmc) is my own, personal implementation that I use every day. It runs on top of 4 independent vaults — work, volunteering, personal, and a demo — each with their own unique queries. You might find inspiration in it.

Local HTTP server

When run as a daemon, the application can run an HTTP server that exposes the curators, documents, and queries it manages. Enable the server by adding the --server or -s option. Optionally, specify a port by adding :<port>. to the server option. The default port is 7767.

The server listens on localhost and nothing else. It supports GET requests and nothing else. It’s limited on purpose.

All queries in a curator are available automatically through the HTTP server. Query parameters normally configured in the page can instead be passed as query parameters.

Most queries support both Markdown and JSON format. Specify the requested format through the Accept header. If not specified, the default format is JSON.

Example endpoints:

  • /curators: Returns a list of all curators in the application.
  • /curators/{curator}/document: Returns the contents - as it is known in memory, not on disk! - of a document. (The JSON format is especially useful here.)
  • /curators/{curator}/queries/{query}: Performs a query on a curator.

Alfred workflow

A separate Markdown Curator workflow that I built for Alfred sits on top of the HTTP server and serves as an example of the functionality it exposes.

The workflow is built with shell scripting, using curl and jq, for maximum compatibility. A stock macOS installation will work. The scripts can be used from the command line, outside Alfred.

To make it work, the curator must run as a daemon with the server enabled, and have the alfred extension loaded: enable alfred (and the journal extension it requires) in the configuration document. Its settings are the paths of the folders Alfred needs: contacts-path, projects-path, reminders-path, systems-path, teams-path, third-parties-path, and the links-section.

Obsidian users: Ye be warned!

If you're an Obsidian user, then note that most of the things this library does can be achieved using plugins, like Dataview. I do not like those kinds of plugins. They defeat Obsidian's purpose. For me Obsidian is all about storing knowledge in portable Markdown files. Sprinkling those same files with code (queries) that an application like Obsidian with specific plugins installed can understand is not the right idea to me.

With this tool I get the best of both worlds: portable Markdown and "dynamic" content. Query output is embedded in the documents as Markdown content. As far as Obsidian is concerned, this tool is not even there.

On the other hand, Obsidian plugins are much easier to install and use. This library requires you to get your hands dirty with Java. You must build your own application. That's not for everyone.

Shouldn't I have built this library as an Obsidian plugin itself? Maybe. Probably. But I didn't. Why not? Because I'm sure my use of Markdown will outlive my use of Obsidian. Also, being able to change files in a vault with any editor and have this tool continue working in the background leads to fewer surprises.

Case in point: with the June 2022 release of iA Writer 6 and its support for wikilinks, compatible with Obsidian's, there's now a native and focused macOS app for personal knowledge management. iA Writer has far fewer bells and whistles than Obsidian, but that's exactly why I happen to like it. And because I do not depend on Obsidian-specific plugins for my content, I can switch between them at will and even use them simultaneously.

Extracting information from content to front matter properties

When maintaining notes in my personal knowledge system, I try to follow two rules:

  1. Never duplicate information manually.
  2. Make all relevant, meaningful information part of the content itself.

The first rule is why this tool exists. With it, content can be sliced and diced in any way conceivable and then represented back as part of the content itself, automatically. Change the original content, and all its transformations follow. No mistakes are possible.

The second rule exists because I believe information should be in human-readable plain text (Markdown), and not forced in some kind of structure to satisfy some tool. Tools should adapt to the people using them, not the other way around. I do not consider front matter in a document to be part of the content of that document. It's metadata. Metadata should be one of two things:

  1. Operational data: data that supports some tool in doing its work and that is non essential to the content. Examples: "Use this CSS template for the HTML export", or "Use this image as a cover for the cards view", or "Allow these aliases for the document".
  2. Derived data: data that is extracted from the content and persisted in an easier digestible way for tools. Examples: "The status of a project" or "The author of a book" or "The poster of a movie".

Front matter has its use. For example, Obsidian plugins like Bases allow Notion-like datasets to be created with it conveniently. But, there's a danger in them, because they can either lead to crucial information being duplicated — both in the content and in the properties — or moved out of the content into the metadata. I'm not certain which is worse.

This is why the curator can update front matter automatically. The content — the Markdown — is where the source information is. Front matter properties must not replace or manually duplicate source information. But they can be derived from it. Both rules are followed, and tools that act on front matter are satisfied at the same time.

(In Obsidian, I prefer to hide document properties. I don't need to see them, because everything I might need is in the content. But I do use them.)

"Vincent Flavored Markdown"

This tool is specifically written for a variant of Markdown that I call Vincent Flavored Markdown. Basically, VFM is the same as Github Flavored Markdown (GFM) with the following constraints and additions:

  • A document can have YAML front matter, between ---.
  • For headers only ATX (#) headers are supported, without the optional closing sequence of #s. Setext-style headers are not supported.
  • Headers are always aligned to the left margin.
  • Code blocks are always surrounded with backticks, not indented.
  • Internal links (links to other documents in the same repository) use double square brackets. ([[Like this]]). The link always points to a file name within the repository. (This is what Obsidian and iA Writer do.)
  • File names are considered to be globally unique within the repository. Surprises might happen otherwise.
  • The document's title is, in this order of preference:
    • The title of the first level 1 header, if present and at the top of the document.
    • The value of the YAML front matter field title, if present.
    • The file name, without extension.
  • The file extension is .md.
  • Queries can be defined in HTML comments for this tool to process. See below.

In practice, I almost never use level 1 headers or the title property. In 99% of the cases the file name is appropriate. I do not duplicate the file name inside the document, because, well, that would be duplication.

If these limitations are not to your liking, then feel free to send me a pull request to support your own personal preferences.

Not a Markdown parser!

This library/application does not correctly parse Markdown. It processes Markdown on a line-by-line level to break up documents in blocks of:

  • Front matter
  • Sections (these can be nested on different levels)
  • Code
  • Queries
  • Text

A text block is "anything not of the above". The content of a text block itself is not parsed. Whether text is in bold or italic, holds a list or a table, uses CriticMarkup or another flavor of Markdown: the internal parser is oblivious to it; it's all text. When you build your own queries, it's up to you to extract content out of the various blocks, as you see fit.

Creating your own application

Creating your own application means that you'll need to:

  • Create a new Java artifact
  • Create and publish a custom curator
  • Create and register one or more queries
  • Create your own custom change processors

Create a new Java artifact

  • Copy the template-application in this repository to a new directory.
  • Update the pom.xml in your copy:
    • Set your own groupId and artifactId.
    • Make sure to use the latest version of dependencies and plugins.

A mvn clean package and java -jar target/my-markdown-curator.jar should result in the application starting up and exiting immediately, telling you that it can't find any curators.

Because I have not published his library to Maven central yet, or anywhere else, you have to install this library in your local repository first. To do so: clone it and do an mvn install.

Create and publish a custom curator

  • Define a Dagger @Module to set up the context of your curator. In the module include at least the nl.ulso.curator.CuratorModule.
  • Define a Dagger @Component that depends on your module and that exposes your Curator instance. This component is an interface with one method.
  • Compile your code with Maven or in your IDE. If all was well, you'll end up with extra code generated by Dagger. If you named your component MyComponent, there will be a DaggerMyComponent now.
  • Implement the CuratorFactory interface. In its implementation use the Dagger-generated code to create and return your Curator instance.
  • Add your CuratorFactory implementation to the file src/main/resources/META-INF/services/nl.ulso.curator.CuratorModule.

See the markdown-curator-demo for an example.

An mvn package and java -jar target/my-markdown-curator.jar should result in the application starting up and staying up, monitoring the directory you provided in your own custom curator.

Try changing a file in any Markdown document in your document repository now. For example, add the toc query. Magic should happen!

<!--query:toc-->
<!--/query-->

Create and register one or more queries

  • Implement the Query interface.
  • Register the query in your own module, by binding the concrete instance into a Query set:
@Binds @IntoSet abstract Query bindMyOwnCustomQuery(MyOwnCustomQuery query);

Rebooting your application should result in the availability of the new query.

Create your own custom change processors

Once you've implemented a couple of queries, you might run into a couple of issues:

  1. Duplication. When extracting specific values from documents, these same values might be needed across queries.
  2. Complexity. Extracting values from documents might be complex, and might lead to queries that are hard to use.
  3. Heavy processing. Running many queries across large data sets on every change, no matter how small, can be CPU intensive.

This is where the concept of the ChangeProcessor comes in. The Markdown Curator runs in two phases. One is to run queries and generate output. This is the second phase. The first phase is to act on incoming changes and build custom data models from these changes. These data models can then be used by the queries.

To do so, implement the ChangeProcessor interface and register it in your curator module:

@Binds @IntoSet abstract ChangeProcessor bindMyOwnCustomProcessor(MyOwnCustomChangeProcessor processor);

When a change is detected, the curator executes all processors to handle the incoming change, optionally producing new changes for custom domain objects. After all processors have been executed, after a slight delay, it inspects all query instances in the vault and runs those that need it.

IMPORTANT: make sure your change processor are registered as @Singletons!

By extending the ChangeProcessorTemplate class you get a head-start into change processing, and an easy way to split the logic of the various processing in separate methods.

If your change processor transforms objects of one type (e.g. Documents) into another (e.g. Projects) and stores them in a repository for use in queries, then extend either the MapBasedEntityRepository or the SetBasedEntityRepository. These do all the heavy lifting, leaving the minor details to you.

As an example of a custom change processor, see the built-in Journal or ProjectRepository.

Load and unload extensions at runtime

Statically registered change processors and queries are fixed when the application starts. An extension is a set of change processors, queries, query result formatters and measurement trackers that can be loaded into and unloaded from a running curator, as configured in a document in the vault. The built-in project, journal, project journal, OmniFocus, Alfred and backlinks modules are all extensions.

To enable extensions in your curator:

  • Provide the name of a configuration document in your curator module:
@Provides @Named(CuratorModule.CONFIGURATION_DOCUMENT_KEY) static String configurationDocument() { return "CONFIG"; }
  • All built-in extensions (project, journal, projectjournal, omnifocus, alfred and backlinks) are registered by the CuratorModule, so there's nothing to include for those. To make a custom extension available, include its module in your curator module.
  • Enable extensions in the first YAML code block (language yaml or yml) of the configuration document, either as a list of names, or as a map of names to their settings. The front matter and any other code blocks in the document are ignored, so you're free to document your configuration around it:
```yaml
extensions:
  project:
    folder: Projects
  journal:
  projectjournal:
```

Whenever the extensions property in that code block changes, the curator loads the new set of extensions and performs a complete refresh, exactly like touching the watch document does.

Extensions that can't be loaded are left out, together with the extensions that depend on them; the others are loaded. Reasons for an extension not to load are: it's unknown, it has unsupported settings, it requires a service that no other loaded extension provides, its change processors consume a payload type nobody produces, or its queries have names that are already taken. Use the configuration query to see which extensions are available and active, what they require and provide, what settings they support, and why extensions weren't loaded. Only if the configuration can't be parsed at all is it rejected as a whole, keeping the current extensions.

Curator settings

The same YAML code block also holds the settings of the curator itself. All of them are optional:

  • delay: the number of seconds the curator waits after the last detected change before it runs the queries and writes documents to disk; the default is 3. Changes coming in during this delay restart it. It must be a non-negative integer; for invalid values the default applies.
  • locale: the language of the query output, as a language tag like nl or en-GB; the default is en-US. Translations are available in English and Dutch; for other languages the output is in English, but dates are still formatted in the configured language. For an unknown language the default applies.
```yaml
delay: 5
locale: nl
extensions:
  journal:
```

Changes to the settings apply immediately. A change of the locale changes the output of all queries, so it also triggers a complete refresh.

Creating an extension

  • Define a public Dagger @Subcomponent, annotated with @ExtensionScope, that extends Extension and includes the ExtensionModule and your own module. (It must be public, because Dagger generates its implementation in the package of the curator that loads it.)
  • In your module, qualify all change processor, query, query result formatter, tracker, service and lifecycle bindings with @ExtensionBinding. Formatters of the curator take precedence over those of extensions, unless an extension's formatter handles a more specific query result type.
  • Annotate all classes in your module with @ExtensionScope instead of @Singleton.
  • Implement an ExtensionFactory that describes the extension - its description, supported settings, required and provided services, and contributions - and that creates the subcomponent.
  • Register the subcomponent and the factory in a module for curators to include: @Module(subcomponents = MyExtension.class) and @Binds @IntoMap @StringKey("my-extension") abstract ExtensionFactory bindMyExtensionFactory(MyExtensionFactory factory);.

Dependencies between extensions

Extensions interact in three ways:

  • Payload types in the changelog, exactly like statically configured change processors.
  • Services: an extension can provide services to other extensions, and require services from them. There's only ever one provider of a service. Extensions declare what they provide and require in their factory; the curator creates providers before their consumers. The factory gets the required services through ExtensionContext.service and passes them into the subcomponent with @BindsInstance, so that the classes in the extension can inject them as usual. Extensions publish services by binding a ServiceRegistration into a set.
  • Contributions (the whiteboard pattern): an extension can own an ExtensionPoint - a typed constant it declares - that other extensions contribute values to, through extensionPoint.contribute(value). The owner collects all of them through ExtensionContext.contributionsTo(extensionPoint). Contributions are collected from all factories before any extension is created, so they don't impose an order: the OmniFocus extension contributes a project attribute definition to the project extension, while requiring the project extension's ProjectRepository.

The curator itself can publish services and contributions too, by binding a ServiceRegistration or Contribution into a set in its module. Extensions can also inject anything the curator binds, like the Vault. Infrastructure that is shared with static code, like the NewDayAlarm and JavaScript for Automation, is best kept that way: the module of the extension includes the module that binds it. Note that a type that the curator binds can't be passed into an extension with @BindsInstance as well; Dagger reports that as a duplicate binding.

Lifecycle

Extensions are created whenever the configuration changes, but they are not necessarily loaded. Their constructors must therefore not acquire resources, like threads. Instead, bind an ExtensionLifecycle into the set of lifecycles of the extension. It's started when the extension is loaded, before its change processors run for the first time, and stopped when it's unloaded. See the OmniFocus extension for an example.

Query collections

This section lists all readily available queries and explains what they do. Each query supports arguments to be passed to it. To know what they are, use the help query somewhere in a monitored repository. For example:

<!--query:help
name: timeline
-->
<!--/query-->

This will write information on the selected query (in this case: timeline), including the parameters it supports as the query output.

Built-in queries

Built-in queries are always available and cannot be disabled.

configuration

This query shows the active configuration of the curator: the settings in effect, like the delay and the locale (invalid settings are ignored, so these might differ from what's in the configuration document), and all available extensions: whether they are active, what they require and provide, what settings they support (with a description of each), and why they weren't loaded, if they weren't; and all queries that are currently available, with their descriptions. It's typically placed in the configuration document itself.

list

This query generates a sorted list of documents in a folder. Each item is a link to a document. Through the configuration the list can be reverse sorted, and documents in subfolders can be recursively added.

table

This query generates a sorted table of pages, with optional front matter fields in additional columns. This is a more powerful version of the list query.

Through the configuration you can extract any front matter field from the individual documents and add them to the table. Next to that you can (reverse) sort the table on any front-matter field.

toc

This query generates a table of contents for the current document. You can tweak the table by configuring the minimum and maximum header levels to include.

Journal module queries

The Journal module supports Logseq-like daily outlines and has a number of queries to slice and dice information from these outlines.

I like the way Logseq puts emphasis on the daily log as the place to write notes. What I do not like about Logseq, however:

  • Everything is an outline. I prefer the freedom full Markdown gives me. When I write an article, for example, I use sections and paragraphs, without bullets. Like this README.
  • It's all dynamic, and therefore the functionality works only in Logseq itself. I like to be able to use any text editor.
  • All documents are stored in the same folder. I prefer using a couple of folders to categorize documents: "Projects", "Contacts", "Articles", and so on.

This module addresses that by generating static timelines from the daily logs. The journal looks at a specific section in the daily log, where it expects an outline. That means the daily log may contain other content as well.

For example, here is the template I currently use for my daily notes:

<!--query:dayNav-->
<!--/query-->

## 🗓️ On the agenda

<!--query:timeline-->
<!--/query-->

## 🏃 Activities

- *Put your outline here!*

The journal is an extension named journal. The CuratorModule makes it available; enable it in the configuration document. All settings are optional; these are the defaults:

extensions:
  journal:
    folder: Journal                 # Where daily journal pages are kept
    markers-folder: Markers         # Where marker descriptions are kept
    activities-section: Activities  # Name of the section with the outline
    projects-folder: Projects       # Where project notes are kept

timeline

The timeline query generates a timeline on a certain topic; by default, this is the page the timeline query is added to. The timeline is sorted by date, newest first. Each entry for the selected topic contains the context from the daily journal, similar to how Logseq does it.

marked

The marked query generates a selection of lines annotated with a specific marker, one section per marker, on a certain topic. By default, the topic is the page the query is added to. Lines in each section are ordered according to the timeline; oldest first. The markers themselves are removed from each line.

A marker is nothing more than a reference to a document. That can be any document. The document might not even exist. Markers are useful to collect specific segments from the timeline and show them prominently in their own section, for example, at the top of a document.

Markers apply to a topic if they are exactly one level lower than the topic itself. This is so that you can reuse markers for different topics, even when the topics are nested.

For example, let's say you have a timeline somewhere that looks like this:

- Important meeting on [[Topic 1]].
    - Meeting note 1
    - [[❗️]] Important meeting note 2
    - We also discussed [[Topic 2]].
        - [[❗️]] We shouldn't forget this!

If you now put the following query on the page of "Topic 1":

<!--query:markers markers: [❗]️-->
<!--/query-->

...this query will produce the output:

## ❗️

- Important meeting note 2

It lists all lines marked with a reference to ❗️ and collects them in a single section. It doesn't show "We shouldn't forget about this!", because the marker on that line applies to Topic 2.

You can change the header titles of the section for each marker in the query output by adding a title property to the marker document. This ensures consistency across the vault and simplifies the query definition.

In this example, if you were to define the page ❗️ as follows:

---
title: ❗️ Important!
---

(Here it's useful to explain what the marker is used for.)

...then the section title in all query outputs would include the text "Important!".

If you want to group the entries for a marker by date in the output, then add the front matter variable group-by-date with a value of true.

Creating marker documents has more advantages than being able to influence the query output:

  • They're documents like any other, so features like backlinks "just work".
  • They can define aliases in their front matter, natively supported by Obsidian.
  • They allow you to explain what a marker is supposed to be used for, for future reference.
  • They prevent dead links in your vault.
  • ...they could even have their own timeline, or embed other queries!

period

The period query generates a list of notes from a specific folder that were referenced in a certain period. For example:

<!--query:period
start: 2023-09-01
end: 2023-09-30
folder: 'Contacts'
-->
- [[Contact A]]
- [[Contact D]]
- [[Contact M]] 
<!--/query-->

This example shows all contacts referenced from the daily log in September 2023, in a sorted list.

weekly

The weekly query is a specialization of the period query. It picks a specific week of a specific year. If your weekly notes are named YYYY Week ww (e.g. 2023 Week 42) and you place this query in that note, then no configuration is necessary. It will list all projects referenced in that week.

dayNav

Put this query at the top of the daily log pages.

The dayNav query generates a set of links to the previous and next daily entry in the journal and to the weekly entry that the day's entry belongs to. It also prints the date as a readable text, like "Sunday, October 1, 2023".

weekNav

Put this query at the top of the weekly log pages.

The weekNav query generates a set of links to the previous and next weekly entry in the journal, and to each of the individual entries in the week. It also prints the week as a readable text, like "2023, Week 39".

Project module queries

The Project module turns one folder in your vault, excluding subdirectories, into a project repository. Every document in the folder represents a project that you want to track.

Apart from being a normal document, a project has a number of additional properties. These come built-in:

  • Priority: an integer value denoting the priority. The lower the more important. Property name: priority.
  • Status: a simple string; I use emojis myself: 🟢, 🟠, 🛑, ⛔️, ✅, 🗑️. Property name: status.
  • Last modification date: a date representing when the project was last worked on. Property name: last_modified.
  • Lead: a reference to some other document, typically representing a person. Property name: lead.

By default, these properties are read from and written to front matter in the project document, using the properties mentioned above, but their source can be overruled by providing custom plugins to resolve these values from wherever you want. See below.

The project model is an extension named project. The CuratorModule makes it available; enable it in the configuration document:

extensions:
  project:
    folder: Projects    # Where project notes are kept; this is the default

The extension provides the ProjectRepository and ProjectAttributeRepository services to other extensions. The set of project attributes is an extension point, ProjectAttributeDefinition.PROJECT_ATTRIBUTES: other extensions can contribute a ProjectAttributeDefinition to it.

projectlist

This query generates a list of all active projects. In its simplest form, in list format, that's all it does. But switch to the table format, and you'll get multiple columns, including the properties mentioned above.

projectlead

This query is a specialization of the projectlist query: it selects only those projects with a specific project lead. The selected lead defaults to the document the query is used in. In other words: stick this query in the document that represents one of your co-workers, and you'll instantly get an overview of projects they're in the lead for; no further configuration needed.

Project Journal module

The Project Journal module does not provide any queries of its own. Instead, it provides a number of plugins to resolve the last modification date, the project status, and the project lead from the journal instead of front matter properties. This means you can write updates to projects in daily log entries. For example:

- Important update to [[Project]].
	- I finally [[Status|Finished]] the project!

This updates the last modification date and the status of project Project to Finished automatically, provided that this text is the most recent update to the project in the journal, that Status is a marker, and Finished a valid project status. Read on for details on how to make that happen.

The module ensures that properties are always in line with the journal, no matter how the journal is modified.

The project journal is an extension named projectjournal. It requires the services of both the project and the journal extensions. The CuratorModule makes all three available.

Then enable all three in the configuration document. The project journal has no settings of its own:

extensions:
  project:
  journal:
  projectjournal:

Last modification date

The simplest plugin in this module is the one that updates the last_modified property: it takes the date from the most recent daily that refers to a project. Link to the project in the journal, and that's it. This requires no further configuration.

Status

To update the status property from the journal, you need a special marker first. See the general description on markers in the Journal module for a generic explanation of markers.

To tag a marker as a project status marker, add a property project-statuses to it, that contains a list of all valid statuses. For example, I have a marker ⭕️ that looks like this:

---
aliases: 
  - "⭕️ Status:"
title: ⭕️ Status Log
group-by-date: true
project-statuses: 
  - 🟢
  - 🟠
  - 🔴
  - ✅
  - 🗑️
---

(The title and group-by-date properties are not necessary for this module, they're there as configuration for the generic marker behavior.)

Now, when a marker is used for a project including an alias as defined in the project-statuses property, that becomes the project status. I like to do that like this:

- [[Project]]
	[[⭕️]] Generic status update; no status change, but it will show in the status log.
	[[⭕|✅]] Party time! This project is done!

If a single journal entry contains multiple status updates, the system picks the last one. It works under the assumption that the log is chronologically ordered.

Lead

Like the status property, the lead property requires a special marker before it can be resolved from the journal. This is a marker with the property project-leads that lists all the aliases to trigger on.

For example, this is how the marker 💁🏼 is configured in my own vaults:

project-leads:
  - ☝🏻

Now, when I write like this:

- [[Project]]
	[[💁|☝🏻]] [[Mike]] is leading this project.

Then Mike is set as the project lead, provided that Mike links to an existing document in the vault.

A line in the journal with the project lead marker may contain multiple document links. The system will use the first one that links to an existing document.

If a single journal entry has multiple project lead markers for the same project, the system picks the last one.

OmniFocus module

The OmniFocus module adds:

  • Two project attributes, omnifocus and priority. The first is a link to the project in OmniFocus, the second its priority in OmniFocus.
  • A query to list the differences between the project in the vault and the project in OmniFocus.

If you use OmniFocus and you store projects that match the projects in the vault in a folder, then you can use this module to keep your projects in sync.

OmniFocus support is an extension named omnifocus, which requires the project extension. The CuratorModule makes both available; enable both in the configuration document:

extensions:
  project:
  omnifocus:
    folder: Work          # The OmniFocus folder that has the projects to sync; required
    exclude-prefixes:     # Optional: ignore OmniFocus projects whose names start with these
      - ⚡️
    exclude:              # Optional: ignore OmniFocus projects with these names
      - 🤖 Routine
    database: /path/to/OmniFocus.ofocus  # Optional: defaults to the OmniFocus 4 location

This is all that's needed to get the extension to work. Suddenly the projects query will sort the projects in the same order as OmniFocus does, and each project will have an omnifocus property in its front matter that links to the same project in OmniFocus.

omnifocus

The omnifocus query has no configuration. Stick it in a document and watch a report appear in it, comparing your vault with OmniFocus. It lists all projects in the one and not in the other, and vice versa.

Backlinks module

The Backlinks module lists the documents that link to a document. Backlinks are a familiar feature of editors like Obsidian, but they're only visible inside the editor. With this module they become part of the document itself.

To keep memory usage low, the module tracks backlinks only for the documents that are actually targeted by a backlinks query anywhere in the vault. Adding the query to a document is enough to start tracking backlinks to it; removing the last query for a document drops them again.

Backlinks support is an extension named backlinks. It has no settings and requires no other extensions. The CuratorModule makes it available; enable it in the configuration document:

extensions:
  backlinks:

backlinks

The backlinks query generates a list of links to all documents that link to the selected document, sorted by name, ignoring emojis. The selected document defaults to the document the query is in; use the document setting to select another one.

Reminders

  • The system is event-driven. Every incoming change — a folder is created, a document is updated, and so on — is an event. When building change processors, take the mindset of changing internal state one change at a time. Always. (At application startup the curator generates an event per document and folder in the vault.)
  • Subscribing to Folder events is hardly ever needed. When a Folder is created or deleted, this triggers events for every folder and document inside it.
  • A rename to a Document or Folder always results into a creation and deletion event, and never in an update event.
  • Always define a Java interface with the API that queries need — read-only access only — and then implement this interface in a change processor. This acts as a clean separation of the two phases in the system.
  • When implementing a change processor, consider implementing the MeasurementTracker interface. All base classes do this; all you need to do is register your implementation in the corresponding Dagger module.
  • Remember to implement the isImpactedBy method in your queries to inspect the changelog.

FAQ

Help! Changes to some files are not detected!

Solution: set the environment to use the right language, e.g. LC_CTYPE=UTF-8.

My personal experience:

  • When run from the command line, changes to all files were detected.
  • When run from within IntelliJ IDEA, changes to files with emojis in their name where not detected.

Adding the LC_CTYPE variable to the Run configuration environment fixed it. The command line already had it.

How do I force a query to re-generate its output?

This shouldn't be needed, but when in doubt, it's easy: remove or change the hash at the bottom of the query definition.

The curator uses the hash to detect changes in query output; not the query output itself. It does this because the query output is not stored in memory in between runs of the curator. That's why you see these hashes show up in the query output (as part of the closing HTML comment).

When you change the hash in any way, the curator will assume the content has changed and will replace it with a fresh query result.

Can I run the application not as a daemon, but just once, for example in a build pipeline?

Yes, you can! By providing the argument "-1" or "--once" at start-up, the curator will do its work once and then quit.

How hungry on resources is this tool?

I've gone out of my way to limit both the amount of memory and CPU it uses. This is a Java application; there's that. There's a considerable minimal memory footprint. But on top of that, I aim to use as little as possible.

However, this application reads all Markdown files in memory and keeps them there. Note that this is excluding the output of the queries in the content; those are only kept in memory during a processing run. I made this choice explicitly; see ADR00003. This means that the amount of memory used grows with the number and size of documents in a repository. Since those documents are normally written by hand, I figured it would take about forever to use more memory than is available in modern hardware. And by that time the amount of memory will likely have doubled at least.

When changes are detected, the application kicks in by first executing all available change processors, then inspecting all query instances in the vault, then running all queries that require it, and finally writing to disk those files that have changed. The queries run in parallel, using Java virtual threads.

This is all nice and good, but what does it mean?

I use vincents-markdown-curator (vmc) all day, every day. It sits on top of 4 repositories, with around 5000 Markdown documents in there. My work repository is the largest by far, with over 3700 documents. In those documents there are over 4900 embedded queries. And this number is growing, because I create at least one document for every working day to hold the daily log, and every daily log embeds at least two queries.

I've limited vmc to use at most 128 MB of memory. When it's not doing anything, it currently uses a little over 65 MB, according to jconsole. When it's running all queries in my work repository, this spikes to about twice that, but then quickly comes down again. And it almost never runs all queries, just a few.

CPU-wise I don't get to see it use more than 5% of my M1 Pro and then only during processing. Otherwise, it's using around 0.3%.

Running all 4900 queries takes around 100 milliseconds. During normal operations it runs only runs a couple of queries, and with that, much faster. Milliseconds.

All in all, I don't notice that vmc is running. It will be many years from now that I'll have so many documents with so many embedded queries in them that performance becomes an issue.

Related

How to Install

  1. Download the template file from GitHub
  2. Move it anywhere in your vault (or your sidebar notes)
  3. Open it in Obsidian — done!

Stats

Stars

9

Forks

2

License

MIT

Last updated 1d ago

Categories

Tags

javamarkdownobsidian