package
0.0.0-20240606191042-2e1bc129bc57
Repository: https://github.com/julien-sobczak/the-notewriter.git
Documentation: pkg.go.dev

# README

Command nt-reference

nt-reference is an interactive CLI to generate reference files or notes already filled with metadata. Several sources are supported like Google Books, Zotero, and Wikipedia.

Configuration

The command reads the same configuration file .nt/config as the command nt. To use this command, declare new sections like [reference.ABC] where each section represents one kind of generation.

For example:

[reference.books]
title = "A book"
manager = "google-books"
path = """references/books/{{index . "title" | slug}}.md"""
template = """---
title: "{{index . "title" | title}}{{ if index . "subtitle"}}:{{index . "subtitle" | title}}{{end}}"
short_title: "{{index . "title" | title}}"
name: {{index . "authors" | join ", "}}
occupation: Unknown
nationality: Unknown
{{- if index . "pageCount"}}
numPages: {{index . "pageCount"}}
{{- end -}}
{{- if index . "industryIdentifiers"}}
isbn: "{{index . "industryIdentifiers" | jq ". | first | .identifier"}}"
{{- end }}
---

# {{index . "title" | title}}
"""

Usage

$ nt-reference new

The CLI is interactive. No option or argument is expected. Simply run it and answer the different questions until your file or note is generated.

FAQ

How to determine available attributes?

You can check the online documentation for the different providers:

ProviderImplementationDocumentation
WikipediaInfoboxes are parsed to extract and parse attributes. It's not easy to find a list of possible attributes.See official documentation
Google BooksThe volumeInfo attribute is extracted and exposed.See official documentation
Zotero (legacy)All attributes returned by the API are exposed. Note that Zotero defines different schemas for the different kinds of work.See project on GitHub or check Zotero Translation Server schemas

Another solution (even simpler to try), is to print all available attributes in your template:

[reference.book]
template = "{{ . | jsonPretty }}"

Once you know which attribute to use, edit the template and relaunch the command.

What is the supported syntax for templates?

The command uses the Go package text/template under the hood. Please read the official documentation. In addition, the command provides additional custom functions:

FunctionDescriptionExample
jsonDump all attributes in compact JSON format Attributes:
{
    "title": "Meditations",
    "authors": ["Marcus Aurelius"]
}

Usage:

{{json .}}

Output:

{ "title": "Meditations", "authors": ["Marcus Aurelius"] }
jsonPrettyDump all attributes in a human-readable format Attributes:
{
    "title": "Meditations",
    "authors": ["Marcus Aurelius"]
}

Usage:

{{jsonPretty .}}

Output:

{
    "title": "Meditations",
    "authors": [
        "Marcus Aurelius"
    ]
}
yamlDump all attributes in a human-readable format Attributes:
{
    "title": "Meditations",
    "authors": ["Marcus Aurelius"]
}

Usage:

{{yaml .}}

Output:

title: "Meditations"
authors:
  - "Marcus Aurelius"
jqSupport jq expressions to extract values Attributes:
{
    "title": "Meditations",
    "authors": ["Marcus Aurelius"]
}

Usage:

{{jq '. | .title' .}}

Output:

Meditations
titleConvert using common book title case Attributes:
{
    "title": "How to take smart notes",
    "authors": ["Sönke Ahrens"]
}

Usage:

{{index . "title" | title}}

Output:

How to Take Smart Notes
slugConvert to a URL-compliant slug Attributes:
{
    "title": "How to Take Smart Notes",
    "authors": ["Sönke Ahrens"]
}

Usage:

{{index . "title" | slug}}

Output:

how-to-take-smart-notes