From b7cc63574af66a35d6232c34ae90afedeb909321 Mon Sep 17 00:00:00 2001 From: "W. Augusto Andreoli" Date: Wed, 7 Feb 2024 03:20:18 +0100 Subject: [PATCH] feat(journal): pipe content from stdin (#17) --- python/logseq_doctor/cli.py | 7 ++++++- rust/logseq/src/lib.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/logseq_doctor/cli.py b/python/logseq_doctor/cli.py index b5b2574..4d95fdb 100644 --- a/python/logseq_doctor/cli.py +++ b/python/logseq_doctor/cli.py @@ -17,6 +17,7 @@ from __future__ import annotations import re +import sys from dataclasses import dataclass from enum import Enum from pathlib import Path # noqa: TCH003 Typer needs this import to infer the type of the argument @@ -118,5 +119,9 @@ def journal( content: list[str] = typer.Argument(None, metavar="CONTENT", help="Content to appended to the current journal"), ) -> None: """Append content to the current journal page in Logseq.""" - markdown = flat_markdown_to_outline(" ".join(content)) + lines = [" ".join(content)] + if not sys.stdin.isatty(): + lines.extend(sys.stdin.readlines()) + + markdown = flat_markdown_to_outline("\n".join(lines)) rust_ext.add_content(cast(GlobalOptions, ctx.obj).logseq_graph_path, markdown) diff --git a/rust/logseq/src/lib.rs b/rust/logseq/src/lib.rs index 2e9863f..4117c20 100644 --- a/rust/logseq/src/lib.rs +++ b/rust/logseq/src/lib.rs @@ -87,6 +87,12 @@ impl Journal { pub fn append(&self, markdown: String) -> anyhow::Result<()> { let path = self.as_path(); + // if no markdown content, print an error and return + if markdown.is_empty() { + eprintln!("No content to append to {:?}", path); + return Ok(()); + } + let empty: bool; if let Ok(content) = fs::read_to_string(&path) { let trimmed_content = content.trim_end().trim_start_matches('-').trim_start();