Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions build-digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ def heading_depth(relpath: Path, is_index: bool) -> int:


def main():
"""Parse arguments, collect markdown files, and write the digest."""
if len(sys.argv) != 4:
print(f"Usage: {sys.argv[0]} <content_dir> <output_file> <title>")
sys.exit(1)

content_dir = Path(sys.argv[1])
output_file = Path(sys.argv[2])
content_dir_display = sys.argv[1]
output_file_display = sys.argv[2]
content_dir = Path(content_dir_display).resolve()
output_file = Path(output_file_display).resolve()
doc_title = sys.argv[3]

if not content_dir.is_dir():
print(f"Error: content directory '{content_dir_display}' does not exist or is not a directory.", file=sys.stderr)
sys.exit(1)

# Collect all markdown files, excluding releases and helm-chart-values
md_files = []
for f in sorted(content_dir.rglob("*.md")):
Expand All @@ -128,7 +135,7 @@ def main():
now = datetime.now(timezone.utc).strftime("%Y-%m-%d")
out_lines = [
f"# {doc_title}\n",
f"> Auto-generated documentation digest. Source: `{content_dir}` ",
f"> Auto-generated documentation digest. Source: `{content_dir_display}` ",
f"> Generated: {now}\n",
"---\n",
]
Expand All @@ -155,9 +162,10 @@ def main():
out_lines.append("\n\n---\n")
file_count += 1

output_file.parent.mkdir(parents=True, exist_ok=True)
output_file.write_text('\n'.join(out_lines), encoding='utf-8')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw a raw FileNotFoundError if the parent directory of output_file doesn't exist — Path.write_text() doesn't create missing parent dirs. Might be worth adding a guard for output_file.parent

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed. Added output_file.parent.mkdir(parents=True, exist_ok=True) before the write_text() call so the parent directory is created automatically if it doesn't exist.

total_lines = sum(1 for _ in output_file.read_text().split('\n'))
print(f"Done: {total_lines} lines, {file_count} documents written to {output_file}")
print(f"Done: {total_lines} lines, {file_count} documents written to {output_file_display}")


if __name__ == '__main__':
Expand Down
Loading