Commit fa2f5f47 authored by Marien Fressinaud's avatar Marien Fressinaud

add: Support HTML pages

parent f354bf7d
......@@ -188,6 +188,37 @@ timezone: Europe/Paris
You can declare as many variables as you want, they all will be accessible in
the article template, uppercased and prepended by `SITE_`.
You might find yourself limited by the article-only system. If you want to
create additional pages, just put HTML files under a `pages` folder. The
directory structure will be preserved.
```console
$ mkdir -p pages/foo
$ echo '<html><body>My page</body></html>' > pages/foo/index.html
$ boop.py
$ tree
.
├── articles
│   └── my-article.md
├── pages
│   └── foo
│   └── index.html
├── site
│   ├── feeds
│   │   └── all.atom.xml
│   ├── foo
│   │   └── index.html
│   ├── index.html
│   ├── my-article.html
│   └── style.css
├── static
│   └── style.css
├── templates
│   └── article.html
├── configuration.yml
└── index.html
```
## Tests
There are some tests (i.e. doctests) that can be run to check that everything
......
......@@ -120,6 +120,13 @@ def dir_tree(path):
yield filename
def mkdirs_for_file(filepath):
"""Create parent directories for a given file.
"""
path = os.path.dirname(filepath)
os.makedirs(path, exist_ok=True)
def main():
# Make sure ./site folder is empty
output_path = os.path.join(os.curdir, "site")
......@@ -137,7 +144,26 @@ def main():
raise ProgramError("./index.html file does not exist")
index_output_filepath = os.path.join(output_path, "index.html")
shutil.copyfile(index_filepath, index_output_filepath)
print(f"Written: file://{os.path.abspath(index_output_filepath)}")
print(f"Written page: file://{os.path.abspath(index_output_filepath)}")
# Check that pages directory exists on the filesystem
pages_path = os.path.join(os.curdir, "pages")
if os.path.isdir(pages_path):
for filename in dir_tree(pages_path):
_, ext = os.path.splitext(filename)
if ext != ".html":
# Don't consider files which are not HTML
continue
page_filepath = os.path.join(pages_path, filename)
output_filepath = os.path.join(output_path, filename)
# Create dir structure for the file
mkdirs_for_file(output_filepath)
# And copy it
shutil.copyfile(page_filepath, output_filepath)
print(f"Written page: file://{os.path.abspath(output_filepath)}")
# Check that a ./static folder exists and copy its content under the ./site
# folder
......@@ -200,7 +226,7 @@ def main():
output_filepath = os.path.join(output_path, f"{article.slug()}.html")
with open(output_filepath, "w") as output_file:
output_file.write(article.render())
print(f"Written: file://{os.path.abspath(output_filepath)}")
print(f"Written article: file://{os.path.abspath(output_filepath)}")
# Just create some variables so it's easier to manipulate after
site_url = configuration["SITE_URL"]
......@@ -246,7 +272,7 @@ def main():
os.mkdir(feed_dirpath)
feed_filepath = os.path.join(feed_dirpath, "all.atom.xml")
feed.write(feed_filepath)
print(f"Written: file://{os.path.abspath(feed_filepath)}")
print(f"Written feed: file://{os.path.abspath(feed_filepath)}")
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