From c652657ea79c9f2acd98bf41104f86f4df79454a Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 11 Sep 2023 17:48:03 -0700 Subject: [PATCH] Allow txt content and deny robots --- build.py | 44 ++++++++++++++++++++++++-------------------- src/robots.txt | 2 ++ 2 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 src/robots.txt diff --git a/build.py b/build.py index 13cd7a8..79bafc0 100755 --- a/build.py +++ b/build.py @@ -40,7 +40,7 @@ def main(): count += 1 # Future-proofing - if not filename.endswith(".html") and not filename.endswith(".md"): + if filename.rsplit(".")[-1] not in ("html", "md", "txt"): raise Exception("Support for this filetype is not yet supported:", filename) path = src / dirpath / filename @@ -58,30 +58,34 @@ def main(): content = md.convert(content) meta = md.Meta - # Inject content into the template - page_content = bs4.BeautifulSoup(content, features="html.parser") - page = copy.copy(template) - article = page.new_tag("article") - article.append(page_content) - page.article.replace_with(article) + if dest.name.endswith("html"): + # Inject content into the template + page_content = bs4.BeautifulSoup(content, features="html.parser") + page = copy.copy(template) + article = page.new_tag("article") + article.append(page_content) + page.article.replace_with(article) - # Inject path into the nav - for i in range(len(dirpath.parts)): - a = page.new_tag("a") - a["href"] = "/" + "/".join(dirpath.parts[:i+1]) + "/" - a.string = dirpath.parts[i] - page.nav.append(a) - page.nav.append(page.new_string("/")) + # Inject path into the nav + for i in range(len(dirpath.parts)): + a = page.new_tag("a") + a["href"] = "/" + "/".join(dirpath.parts[:i+1]) + "/" + a.string = dirpath.parts[i] + page.nav.append(a) + page.nav.append(page.new_string("/")) - # Apply metadata to the template - if meta_title := meta.get("title"): - title = "".join(meta_title) - page.title.string = title - page.header.h1.string = title + # Apply metadata to the template + if meta_title := meta.get("title"): + title = "".join(meta_title) + page.title.string = title + page.header.h1.string = title + + # The fully templated page is the new content + content = str(page) # Write the destination file print("Writing ", dest) - dest.write_text(str(page)) + dest.write_text(content) print("Processed", count, "files") diff --git a/src/robots.txt b/src/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/src/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: /