158 lines
No EOL
3.8 KiB
Markdown
158 lines
No EOL
3.8 KiB
Markdown
# 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.
|
|
|
|
```bash
|
|
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 `-`).
|
|
|
|
```bash
|
|
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.
|
|
|
|
```bash
|
|
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)
|
|
|
|
```bash
|
|
# Dry run
|
|
./run_full_cleanup.sh --dry-run ~/notes_test/journals/
|
|
|
|
# Process a single file
|
|
./run_full_cleanup.sh ~/notes_test/journals/2026_10_23.md
|
|
|
|
# Process recursively
|
|
./run_full_cleanup.sh -r ~/notes_test/journals/
|
|
```
|
|
|
|
## Usage Examples
|
|
|
|
### Quick Single File Cleanup
|
|
```bash
|
|
# Use the master script for complete cleanup
|
|
./run_full_cleanup.sh path/to/journal.md
|
|
```
|
|
|
|
### Batch Process All Journals
|
|
```bash
|
|
# Preview first
|
|
./run_full_cleanup.sh --dry-run -r journals/
|
|
|
|
# Then execute
|
|
./run_full_cleanup.sh -r journals/
|
|
```
|
|
|
|
### Individual Script Usage
|
|
```bash
|
|
# 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:
|
|
```markdown
|
|
- - 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:
|
|
```markdown
|
|
- ## Daily Tasks
|
|
- DONE Zyrtec
|
|
:LOGBOOK:
|
|
CLOCK: [2026-10-23 Fri 17:22:24]--[2026-10-23 Fri 17:22:30] => 00:00:06
|
|
: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
|
|
|
|
```bash
|
|
# 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:
|
|
```bash
|
|
logseq-clean --dry-run ~/logseq/journals/
|
|
```
|
|
|
|
## Testing
|
|
|
|
A test file (`test_input.md`) is included with sample Logseq content. To test:
|
|
|
|
```bash
|
|
# 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. |