notes-utils/logseq_cleanup
2026-11-12 16:55:28 -08:00
..
batch_cleanup_journals.sh Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00
clean_empty_bullets.py Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00
clean_task_lists.py Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00
ensure_newline_ending.py Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00
README.md Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00
run_full_cleanup.sh Refactor Logseq scripts to their own directory 2026-11-12 16:55:28 -08:00

Logseq Task List Query Cleaner

A suite of Python scripts to clean up and normalize Logseq journal pages.

Available Scripts

1. clean_task_lists.py - Remove Task List Query Blocks

Removes auto-generated "Task List" query blocks that Logseq adds to journal pages.

python3 clean_task_lists.py --dry-run journals/
python3 clean_task_lists.py -r journals/

2. clean_empty_bullets.py - Remove Empty Bullet Lines

Removes empty bullet lines (lines with only whitespace and/or a single dash -).

python3 clean_empty_bullets.py --dry-run journals/
python3 clean_empty_bullets.py -r journals/

3. ensure_newline_ending.py - Normalize File Endings

Ensures all files end with exactly one newline character.

python3 ensure_newline_ending.py --dry-run journals/
python3 ensure_newline_ending.py -r journals/

4. run_full_cleanup.sh - Master Cleanup Script

Runs all cleanup scripts in the correct order:

  1. Remove Task List query blocks (largest changes first)
  2. Remove empty bullet lines (cleanup remnants)
  3. Ensure single trailing newline (final normalization)
# Dry run
./run_full_cleanup.sh --dry-run ~/notes_test/journals/

# Process a single file
./run_full_cleanup.sh ~/notes_test/journals/JOURNAL_FILE.md

# Process recursively
./run_full_cleanup.sh -r ~/notes_test/journals/

Usage Examples

Quick Single File Cleanup

# Use the master script for complete cleanup
./run_full_cleanup.sh path/to/journal.md

Batch Process All Journals

# Preview first
./run_full_cleanup.sh --dry-run -r journals/

# Then execute
./run_full_cleanup.sh -r journals/

Individual Script Usage

# Just remove query blocks
python3 clean_task_lists.py -r journals/

# Just fix empty bullets
python3 clean_empty_bullets.py -r journals/

# Just normalize endings
python3 ensure_newline_ending.py -r journals/

What Gets Removed

The script removes blocks like:

- - query-table:: false
  #+BEGIN_QUERY {:title "✅ Task List" :query [:find (pull ?h [*]) :where ... ] :group-by-page? false :collapsed? false}
  #+END_QUERY

And also handles variants with sorting options:

- ## Daily Tasks
  - DONE Zyrtec
    :LOGBOOK:
    :END:
  - query-table:: true
    query-sort-by:: page
    query-sort-desc:: false
    #+BEGIN_QUERY {:title "✅ Task List" :query [:find (pull ?h [*]) :where ... ] :group-by-page? false :collapsed? false}
    #+END_QUERY

What Gets Preserved

✅ All meeting notes
✅ All task descriptions and progress
✅ All CLOCK entries and time tracking
✅ All tags and links
✅ All bullet points and nested content
✅ All other query blocks (non-Task-List)

Safety Features

  • Dry run mode - See what would change before making modifications
  • Batch processing - Handle entire directories of journals
  • Pattern-specific - Only removes blocks with "✅ Task List" title
  • Non-destructive - All actual content is preserved

Requirements

  • Python 3.6+
  • No external dependencies (uses only stdlib re, argparse, pathlib)

Installation

# Clone the repository
git clone <repo-url> logseq-cleanup
cd logseq-cleanup

# Make executable (optional)
chmod +x clean_task_lists.py

# Create a symlink for easy access
ln -s $(pwd)/clean_task_lists.py ~/bin/logseq-clean

Then use:

logseq-clean --dry-run ~/logseq/journals/

Testing

A test file (test_input.md) is included with sample Logseq content. To test:

# Dry run on test file
python3 clean_task_lists.py --dry-run test_input.md

# Actually process test file
cp test_input.md test_output.md
python3 clean_task_lists.py test_output.md

# Compare
diff test_input.md test_output.md

License

MIT License - Feel free to modify for your own Logseq setup.