Skip to content

Commit

Permalink
feat(journal): pipe content from stdin (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Feb 7, 2024
1 parent 202c8d4 commit b7cc635
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/logseq_doctor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions rust/logseq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b7cc635

Please sign in to comment.