From ccabcf657f700e1b8c15b97925ed8535d21491f3 Mon Sep 17 00:00:00 2001 From: Midgard <2885-Midgard@users.noreply.framagit.org> Date: Tue, 16 Jun 2020 03:00:31 +0200 Subject: [PATCH] Solve problems, and use redirection in makefile --- makefile | 6 +++--- page.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/makefile b/makefile index 32f7f82..2c48211 100644 --- a/makefile +++ b/makefile @@ -7,11 +7,11 @@ PYTHON ::= venv/bin/python .PHONY: all clean public -all: $(BUILD_DIR)/index.html $(BUILD_DIR)/feed.xml $(BUILD_DIR)/syntax.css public $(BLOG_HTML) +all: $(BUILD_DIR)/index.html $(BUILD_DIR)/rss.xml $(BUILD_DIR)/syntax.css public $(BLOG_HTML) $(BUILD_DIR)/index.html: templates/index.html $(BLOG) page.py @mkdir -p "$(@D)" - $(PYTHON) page.py --index "$<" "$@" $(BLOG) + $(PYTHON) page.py --index "$<" $(BLOG) > "$@" $(BUILD_DIR)/rss.xml: $(BLOG) rss.py page.py @mkdir -p "$(@D)" @@ -19,7 +19,7 @@ $(BUILD_DIR)/rss.xml: $(BLOG) rss.py page.py $(BUILD_DIR)/blog/%.html: blog/%.md templates/blog.html page.py @mkdir -p "$(@D)" - $(PYTHON) page.py "$<" "$@" + $(PYTHON) page.py "$<" > "$@" $(BUILD_DIR)/syntax.css: makefile @mkdir -p "$(@D)" diff --git a/page.py b/page.py index 1a8dd8c..949d192 100755 --- a/page.py +++ b/page.py @@ -63,29 +63,28 @@ def safe_metadata(metadata): def main(): if sys.argv[1] == "--index": blog_post_list = ( - ipo(sys.argv[4:]) | + ipo(sys.argv[3:]) | p(map, blog_page_metadata) | p(sorted, key=lambda x: x["published"]) | p(map, safe_metadata) | p(map, lambda metadata: LIST_ITEM_TEMPLATE.format(**metadata)) | "".join - ) + ).data - with open(sys.argv[2]) as file_in, open(sys.argv[3], "w") as file_out: + with open(sys.argv[2]) as file_in: print( file_in.read().format(blog_posts=blog_post_list), - end="", file=file_out + end="" ) else: metadata = safe_metadata(blog_page_metadata(sys.argv[1])) body = blog_page_body(sys.argv[1]) - with open(sys.argv[2], "w") as file_out: - print( - blog_page_template().format(**metadata, body=body), - end="", file=file_out - ) + print( + blog_page_template().format(**metadata, body=body), + end="" + ) if __name__ == '__main__': main()