nt-reference

command
v0.0.0-...-a7c3734 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

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:

Provider Implementation Documentation
Wikipedia Infoboxes are parsed to extract and parse attributes. It's not easy to find a list of possible attributes. See official documentation
Google Books The 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:

Function Description Example
json Dump all attributes in compact JSON format Attributes:
{
    "title": "Meditations",
    "authors": ["Marcus Aurelius"]
}

Usage:

{{json .}}

Output:

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

Usage:

{{jsonPretty .}}

Output:

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

Usage:

{{yaml .}}

Output:

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

Usage:

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

Output:

Meditations
title Convert 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
slug Convert 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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL