From bffbb0f37141f511951adc9bc8f2e059581a0822 Mon Sep 17 00:00:00 2001 From: ktyl Date: Wed, 15 Nov 2023 01:06:36 +0000 Subject: [PATCH] feat(rss): generate unformatted file titles --- src/garden/feed.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/garden/feed.py b/src/garden/feed.py index 3b06350..1b66aeb 100644 --- a/src/garden/feed.py +++ b/src/garden/feed.py @@ -5,21 +5,20 @@ import pathlib import sys import re import glob +import os def print_usage(): print("\nusage: python feed.py ROOT\n") print("\n") print("\t\ROOT\tbase folder") -def validate(): - # check args for at least one file path - if len(sys.argv) < 2: - print_usage() - sys.exit(1) +# check args for at most one file paths +if len(sys.argv) > 2: + print_usage() + sys.exit(1) -validate() - -base_folder = sys.argv[1] +base_folder = sys.argv[1] if len(sys.argv) == 2 else os.getcwd() +print(base_folder) def get_paths() -> [str]: return [x for x in glob.glob(f"{base_folder}/*.md")] @@ -31,14 +30,20 @@ def get_text(path): #def to_html(md : str) -> str: # return markdown.markdown(md, extensions=["fenced_code"]) +def get_title(md): + m = re.compile(r"^# (.+)\n").match(md) + if m is not None: + return m.groups(1)[0] + + # truncated first line of file for auto-title + return md.splitlines()[0][0:30] + def get_entry(path): return get_title(get_text(path)) -def get_title(md): - return re.compile(r"^# (.+)\n").match(md).group(1) - def get_entries() -> [str]: - return "\n\n".join([get_entry(p) for p in get_paths()]) + entries = [get_entry(p) for p in get_paths()] + return "\n\n".join(entries) def get_header() -> str: return """