feat(rss): generate unformatted file titles
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
17c12cadf4
commit
1cc66385ab
|
@ -5,21 +5,20 @@ import pathlib
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print("\nusage: python feed.py ROOT\n")
|
print("\nusage: python feed.py ROOT\n")
|
||||||
print("\n")
|
print("\n")
|
||||||
print("\t\ROOT\tbase folder")
|
print("\t\ROOT\tbase folder")
|
||||||
|
|
||||||
def validate():
|
# check args for at most one file paths
|
||||||
# check args for at least one file path
|
if len(sys.argv) > 2:
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print_usage()
|
print_usage()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
validate()
|
base_folder = sys.argv[1] if len(sys.argv) == 2 else os.getcwd()
|
||||||
|
print(base_folder)
|
||||||
base_folder = sys.argv[1]
|
|
||||||
|
|
||||||
def get_paths() -> [str]:
|
def get_paths() -> [str]:
|
||||||
return [x for x in glob.glob(f"{base_folder}/*.md")]
|
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:
|
#def to_html(md : str) -> str:
|
||||||
# return markdown.markdown(md, extensions=["fenced_code"])
|
# 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):
|
def get_entry(path):
|
||||||
return get_title(get_text(path))
|
return get_title(get_text(path))
|
||||||
|
|
||||||
def get_title(md):
|
|
||||||
return re.compile(r"^# (.+)\n").match(md).group(1)
|
|
||||||
|
|
||||||
def get_entries() -> [str]:
|
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:
|
def get_header() -> str:
|
||||||
return """<?xml version="1.0" encoding="utf-8" ?>
|
return """<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
|
Loading…
Reference in New Issue