Solve problems, and use redirection in makefile

This commit is contained in:
Midgard 2020-06-16 03:00:31 +02:00
parent 24a41ca958
commit ccabcf657f
Signed by untrusted user who does not match committer: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 11 additions and 12 deletions

View file

@ -7,11 +7,11 @@ PYTHON ::= venv/bin/python
.PHONY: all clean public .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 $(BUILD_DIR)/index.html: templates/index.html $(BLOG) page.py
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
$(PYTHON) page.py --index "$<" "$@" $(BLOG) $(PYTHON) page.py --index "$<" $(BLOG) > "$@"
$(BUILD_DIR)/rss.xml: $(BLOG) rss.py page.py $(BUILD_DIR)/rss.xml: $(BLOG) rss.py page.py
@mkdir -p "$(@D)" @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 $(BUILD_DIR)/blog/%.html: blog/%.md templates/blog.html page.py
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
$(PYTHON) page.py "$<" "$@" $(PYTHON) page.py "$<" > "$@"
$(BUILD_DIR)/syntax.css: makefile $(BUILD_DIR)/syntax.css: makefile
@mkdir -p "$(@D)" @mkdir -p "$(@D)"

17
page.py
View file

@ -63,29 +63,28 @@ def safe_metadata(metadata):
def main(): def main():
if sys.argv[1] == "--index": if sys.argv[1] == "--index":
blog_post_list = ( blog_post_list = (
ipo(sys.argv[4:]) | ipo(sys.argv[3:]) |
p(map, blog_page_metadata) | p(map, blog_page_metadata) |
p(sorted, key=lambda x: x["published"]) | p(sorted, key=lambda x: x["published"]) |
p(map, safe_metadata) | p(map, safe_metadata) |
p(map, lambda metadata: LIST_ITEM_TEMPLATE.format(**metadata)) | p(map, lambda metadata: LIST_ITEM_TEMPLATE.format(**metadata)) |
"".join "".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( print(
file_in.read().format(blog_posts=blog_post_list), file_in.read().format(blog_posts=blog_post_list),
end="", file=file_out end=""
) )
else: else:
metadata = safe_metadata(blog_page_metadata(sys.argv[1])) metadata = safe_metadata(blog_page_metadata(sys.argv[1]))
body = blog_page_body(sys.argv[1]) body = blog_page_body(sys.argv[1])
with open(sys.argv[2], "w") as file_out: print(
print( blog_page_template().format(**metadata, body=body),
blog_page_template().format(**metadata, body=body), end=""
end="", file=file_out )
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()