Skip to content

masanobbb/booknote.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

booknote.nvim

A Neovim plugin that allows you to search for books using the Google Books API and create markdown notes with book metadata.

Features

  • Search for books by title, author, publisher, or ISBN
  • View search results and select a book using fzf-lua
  • Create new markdown notes with book metadata from the search result
  • Find existing book notes by filename using fzf-lua
  • Grep existing book notes by content using fzf-lua
  • Support for custom templates
  • Support for Google Books API

Installation

Requirements

  • Neovim >= 0.8.0
  • plenary.nvim
  • fzf-lua
  • ripgrep (optional, recommended) - used by :BookNote grep; falls back to grep if not installed

Using lazy.nvim

Add the following to your lazy.nvim plugin configuration:

{
  "masanobbb/booknote.nvim",
  dependencies = {
    "nvim-lua/plenary.nvim",
    "ibhagwan/fzf-lua",
  },
  cmd = { "BookNote" },
  keys = {
    {
      "<leader>bc",
      function()
        require("booknote").create_book_note()
      end,
      desc = "BookNote create",
    },
    {
      "<leader>bf",
      function()
        require("booknote").find_book_note()
      end,
      desc = "BookNote find",
    },
    {
      "<leader>bg",
      function()
        require("booknote").grep_book_note()
      end,
      desc = "BookNote grep",
    },
  },
  opts = {
    -- Required: Directory where book notes are created, found, and grepped
    booknote_location = "~/Documents/BookNotes",

    -- Optional: Customize the filename format
    new_file_name = "{{title}}",

    -- Optional: Path to custom template file
    template_file = "~/.config/nvim/templates/book-template.md",

    -- Optional: API key for Google Books (recommended to avoid rate limits)
    api_key = os.getenv("BOOKS_API_KEY"),

    -- Optional: Enable edge curl effect for cover images (default: true)
    cover_image_edge_curl = true,
  },
}

Configuration

The booknote_location option is required. Without it, the plugin will fail to create, find, or grep notes.

You can set environment variables for sensitive data like API keys:

# In your .bashrc, .zshrc, or similar
export BOOKS_API_KEY="your-google-books-api-key"

Usage

Commands

  • :BookNote create - Search for a book and create a note
  • :BookNote find - Find .md files under booknote_location by filename using fzf-lua
  • :BookNote grep - Grep the contents of .md files under booknote_location using fzf-lua (Available once the plugin is loaded — see the lazy.nvim config above.)

Keymaps

No default keymap is set. Define your own — see the keys example in the lazy.nvim config above.

Template Variables

You can use the following variables in your custom templates:

Variable Description
title The title of the book
subtitle The subtitle of the book (if available)
author Comma-separated list of authors
authors Array of author names
description Book description
publisher Book publisher
publishDate Publication date
totalPage Total number of pages
category Comma-separated list of categories
categories Array of category names
isbn10 ISBN-10 identifier
isbn13 ISBN-13 identifier
coverUrl URL to the book cover image
coverSmallUrl URL to a smaller version of the cover image
DATE Current date (YYYY-MM-DD format)
DATE:format Current date with custom format

Default Template

If no template file is found, the plugin will use a built-in default template.

---
tag: 📚Book
title: "{{title}}"
subtitle: "{{subtitle}}"
author: [{{author}}]
category: [{{category}}]
publisher: {{publisher}}
publish: {{publishDate}}
total: {{totalPage}}
isbn: {{isbn10}} {{isbn13}}
cover: {{coverUrl}}
status: unread
created: {{DATE:YYYY-MM-DD HH:mm:ss}}
updated: {{DATE:YYYY-MM-DD HH:mm:ss}}
---

# {{title}}

![cover|150]({{coverUrl}})

## Description

{{description}}

## Notes

API Key for Google Books

To avoid rate limits, it's recommended to set up your own Google Books API key:

  1. Create a project on Google Cloud
  2. Enable the Books API for your project using the Books API page
  3. Create an API key from the Google Cloud Credentials page
  4. Add the API key to your plugin configuration

Acknowledgements

This plugin was inspired by Obsidian Book Search Plugin by @anpigon.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages