Commit 0b0f035d authored by berumuron's avatar berumuron
Browse files

imp: Show finale URLs instead of files path

When building the website, it is better to know the URL of the article
or the page instead of its path. Indeed, it's easier to find the path
because it is on the same computer. Also, the path is displayed if the
URL is set to `filesystem` in development.
parent bc9410d0
...@@ -144,6 +144,10 @@ class Page: ...@@ -144,6 +144,10 @@ class Page:
def slug(self): def slug(self):
return self.meta["PAGE_SLUG"] return self.meta["PAGE_SLUG"]
def url(self):
site_url = self.meta.get("SITE_URL", "")
return f"{site_url}{self.slug()}.html"
def content(self): def content(self):
return self.meta["PAGE_CONTENT"] return self.meta["PAGE_CONTENT"]
...@@ -255,7 +259,7 @@ def main(environment): ...@@ -255,7 +259,7 @@ def main(environment):
# And write the file # And write the file
with open(output_filepath, "w") as output_file: with open(output_filepath, "w") as output_file:
output_file.write(page.render()) output_file.write(page.render())
print(f"Written page: file://{os.path.abspath(output_filepath)}") print(f"Written page: {page.url()}")
# Check that a ./static folder exists and copy its content under the ./site # Check that a ./static folder exists and copy its content under the ./site
# folder # folder
...@@ -297,7 +301,7 @@ def main(environment): ...@@ -297,7 +301,7 @@ def main(environment):
output_filepath = os.path.join(output_path, f"{article.slug()}.html") output_filepath = os.path.join(output_path, f"{article.slug()}.html")
with open(output_filepath, "w") as output_file: with open(output_filepath, "w") as output_file:
output_file.write(article.render()) output_file.write(article.render())
print(f"Written article: file://{os.path.abspath(output_filepath)}") print(f"Written article: {article.url()}")
# Write the page with the list of articles if blog template exists # Write the page with the list of articles if blog template exists
blog_template_filepath = os.path.join("templates", "blog.html") blog_template_filepath = os.path.join("templates", "blog.html")
...@@ -309,7 +313,7 @@ def main(environment): ...@@ -309,7 +313,7 @@ def main(environment):
blog_output_filepath = os.path.join(output_path, f"blog.html") blog_output_filepath = os.path.join(output_path, f"blog.html")
with open(blog_output_filepath, "w") as output_file: with open(blog_output_filepath, "w") as output_file:
output_file.write(blog_template.render(context)) output_file.write(blog_template.render(context))
print(f"Written page: file://{os.path.abspath(blog_output_filepath)}") print(f"Written page: {configuration['SITE_URL']}blog.html")
# Just create some variables so it's easier to manipulate after # Just create some variables so it's easier to manipulate after
site_url = configuration["SITE_URL"] site_url = configuration["SITE_URL"]
...@@ -355,7 +359,7 @@ def main(environment): ...@@ -355,7 +359,7 @@ def main(environment):
os.mkdir(feed_dirpath) os.mkdir(feed_dirpath)
feed_filepath = os.path.join(feed_dirpath, "all.atom.xml") feed_filepath = os.path.join(feed_dirpath, "all.atom.xml")
feed.write(feed_filepath) feed.write(feed_filepath)
print(f"Written feed: file://{os.path.abspath(feed_filepath)}") print(f"Written feed: {configuration['SITE_URL']}feeds/all.atom.xml")
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment