From c8ffa6722ef948879fa6ed9642ad134a2193fa4b Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 12 Sep 2023 22:45:16 +0200 Subject: Write metadata in TOML --- README.md | 28 +++++++++++++++------------- bin/get-books | 9 +++++---- flake.nix | 1 + 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 9130a59..9c530de 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,25 @@ Visualize a book library. ## Book library -Organize folders as you wish, only `metadata.json` files matter: - -```json -{ - "title": "Title of the Book", - "subtitle": "Optional subtitle", - "authors": [ "Author 1", "Author 2" ], - "authorsSort": "Author sorting", - "genres": [ "Foo", "Bar", "Baz" ], - "year": "1234", - "read": "Read" -} +Organize folders as you wish, only `metadata.toml` files matter: + +```toml +title = "Title of the Book" +subtitle = "Optional subtitle" +authors = [ "Author 1", "Author 2" ] +authorsSort = "Author sorting" +genres = [ "Foo", "Bar", "Baz" ] +year = 1234 +summarry = """ +First paragraph +Second paragraph +""" +read = "Read" ``` `read` is one of: `Read`, `Unread`, `Reading`, `Stopped`. -Each `metadata.json` file correspond to a book, and there **must** be a cover +Each `metadata.toml` file correspond to a book, and there **must** be a cover named `cover.ext` in the same directory. Any extension works. ## Show library diff --git a/bin/get-books b/bin/get-books index d3ac0f6..1c9bf67 100755 --- a/bin/get-books +++ b/bin/get-books @@ -11,13 +11,14 @@ fi echo "const bookLibrary = [" -for METADATA in $(find "$BOOK_DIR" -name 'metadata.json'); do +for METADATA in $(find "$BOOK_DIR" -name 'metadata.toml'); do DIR=$(dirname "$METADATA") COVER=$(ls $DIR/cover.*) - cat "$METADATA" | head -n -1 - echo ", \"cover\": \"$COVER\"" - echo "}," + TOML=$(cat "$METADATA") + WITH_COVER=$(echo -e "$TOML\ncover = \"$COVER\"") + echo "$WITH_COVER" | toml2json + echo "," done echo "]" diff --git a/flake.nix b/flake.nix index 48ae045..0f50d16 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ nodePackages.typescript psmisc # fuser python3 + toml2json watchexec ]; }; -- cgit v1.2.3