Browse Source

Ability to display orphan fragments

master
David Larlet 1 year ago
parent
commit
ed213aa943
No known key found for this signature in database
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      site.py

+ 13
- 5
site.py View File

@@ -124,11 +124,19 @@ class Page:


@cli
def fragment(title: str):
"""Create a new fragment and open it in iA Writer."""
fragment_path = DAVID / "2020" / "fragments" / f"{title}.md"
open(fragment_path, "w+").write(f"## {title}")
os.popen(f'open -a "iA Writer" "{fragment_path}"')
def orphans():
"""Print out fragments not linked to any page."""
linked_fragments = []
for file_path in each_markdown_from(DAVID / "2020"):
for line in open(file_path).readlines():
if line.startswith(".. include:: fragments/"):
linked_fragments.append(line[len(".. include:: fragments/") : -1])
all_fragments = []
for file_path in each_markdown_from(DAVID / "2020" / "fragments"):
all_fragments.append(file_path[len("david/2020/fragments/") :])
for fragment_filename in set(all_fragments) - set(linked_fragments):
# Prepending path for easy command+click from fish.
print(DAVID / "2020" / "fragments" / fragment_filename)


@cli

Loading…
Cancel
Save