Quieter plaintext.sh, add update_index to post_build actions Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Sat, 25 Jan 2020 18:50:23 +0530
3 files changed,
18 insertions(+),
9 deletions(-)
M
bin/plaintext.sh
→
bin/plaintext.sh
@@ -12,8 +12,7 @@
for p in pages/blog/*.md; do basename "$p" [ "$base" != "_index.md" ] && { - echo "$base" - pandoc -s -f "markdown+gutenberg" \ + pandoc --quiet -s -f "markdown+gutenberg" \ "$p" -o "pages/txt/${base%.*}.txt" } done
M
bin/update_index.py
→
bin/update_index.py
@@ -10,8 +10,11 @@ os.chdir("bin")
blog = "../pages/blog/" +print("this is going to take a while...") +print("you might as well serve the site!") + # order files by recency -def getrecents(path): +def get_recents(path): files = [path + f for f in os.listdir(blog) if f not in ["_index.md", "feed.xml"]] files.sort( key=lambda f: markdown_path(f, extras=["metadata"]).metadata["date"],@@ -35,6 +38,12 @@
def update_blog(s): path = "../pages/blog/_index.md" s = s + "\n" + with open(path) as f: + tempf = f.readlines() + + if s in tempf: + print("index has already been updated. quitting...") + sys.exit() for l in fileinput.FileInput(path, inplace=1): if "--:" in l: l = l.replace(l, l + s)@@ -47,13 +56,14 @@ lines = []
fnames = [] for i in range(5): - top_five.append(getrecents(blog)[i]) - metas.append(markdown_path(getrecents(blog)[i], extras=["metadata"]).metadata) - fnames.append(os.path.basename(os.path.splitext(getrecents(blog)[i])[0])) + top_five.append(get_recents(blog)[i]) + metas.append(markdown_path(get_recents(blog)[i], extras=["metadata"]).metadata) + fnames.append(os.path.basename(os.path.splitext(get_recents(blog)[i])[0])) for meta, fname in zip(metas, fnames): url = "/blog/" + fname - lines.append(f"| [{meta['title']}]({url}) | `{meta['date']}` |") + new_line = f"| [{meta['title']}]({url}) | `{meta['date']}` |" + lines.append(new_line) -update_index(lines) +#update_index(lines) update_blog(lines[0])