The NoteWriter is fundamentally a CLI to extract objects from Markdown files.
The NoteWriter Objects
When running commands like nt add, The NoteWriter parses Mardown files to extract different objects.
file
Each parsed file generates an object file representing the file as a YAML document.
Ex (Mardown):
Ex (Internal):
note
Each note, independent of its kind, generates an object note representing the note as a YAML document.
Ex (Markdown):
Ex (Internal):
flashcard
Each note of kind flashcard generates an additional object flashcard representing the flashcard to learn as a YAML document.
Ex (Markdown):
Ex (Internal):
media
Each link inside note referencing a local file generates an object media representing the media file as a YAML document.
Ex (Markdown):
Ex (Internal):
link
Each link (internal or external) that includes a Go link inside the link’s title generates an additional object link representing the special link as a YAML document.
Ex (Markdown):
Ex (Internal):
reminder
Reminders are defined using a special tag syntax and generate additional reminder object representing the reminders as YAML document:
Ex (Markdown):
Ex (Internal):
The NoteWriter Database
Above objects are stored (indirectly) in the index. Ex:
This section documents the format of the different files that composed the internal database.
.nt/objects/
This directory contains two kinds of objects:
Pack Files (a group of edited objects referenced by a single commit).
Blobs (the raw bytes for a single media file, the metadata are stored in the media object referencing the blob inside a commit object).
All objects (leafs such as note or pack files) and all blobs are uniquely identified by their OID, a 40-character string similar to the SHA-1 used by Git. This OID is used to spread the files into subdirectories and avoid having thousands of files directly under .nt/objects. For example, the pack file afe988e5f40e4d1181a86f522e3c1f2e6f0241e3 and the blob 6ee8a9620d3f4d3f9fbd159744ef85b83400b0d4 will be stored like this:
The directory objects contains an additional file .nt/objects/info/commit-graph containing the linear sequence of commits (and their pack files) applied in this repository.
.nt/objects/{xx}/{packfile-sha1}
Pack files are YAML objects.
Ex:
Each object is self-containing through the data attribute and compressed using zlib and encoded in Base 64. You can easily retrieve the uncompressed content:
The main motivation behind pack files is to limit the number of files on disk (and the number of files to transfer when using a remote repository).
.nt/objects/info/commit-graph
The commit-graph file lists in a sequential order all commits that were processed in this repository. The list is useful when retrieving new objects from a remote to quickly determine the missing commits and pack files to replay.
Ex:
.nt/index
The index file serves multiple purposes. It contains the staging area (= the list of objects to include in the next commit) and keeps a list of all objects to quickly locate the commit and pack file containing them.
Ex:
.nt/refs/
In the same way that Git Branches are simply aliases to commit SHA-1, references contains a commit OID.
.nt/refs/main is the reference for the local repository (= the last commit OID present in commit-graph)
.nt/refs/remote is only present when using a remote. It contains the last known commit when the remote was last checked.
.nt/database.db
In addition to raw files, The NoteWriter also comprises a SQLite database (populated using the same information as present in object files). This database is used to speed up commands but also to benefit from the full-text search support when using the desktop application.
Example
Setup a new repository
Inspect the database:
Most files are still missing and will be populated only after adding files.
Add a new note
Inspect the database:
Database files have now been created. We have a new object under objects representing the unique pack file (4a03d1ab3dbe4c5d9efacd0e05e187179c5415c6) contained in our commit and containing the objects:
The commit has been recording into the commit-graph:
The reference main points to this commit:
And our index has been updated to clear the staging area:
Edit the note to reference a new media
Check that the staging area is not empty:
Commit changes
The commit has been recorded:
That’s all. You have seen the various files in action.