Commit 5d7de713 authored by Marien Fressinaud's avatar Marien Fressinaud

Require index.html to be at the root folder

parent 99c8bd31
......@@ -32,51 +32,44 @@ $ source ~/.bashrc
## Usage
First, create a project directory:
First, create a project and execute the Boop! command:
```console
$ mkdir my-website && cd my-website
```
Create a `./content` folder and execute the Boop! command:
```console
$ mkdir content
$ echo '<h1>Welcome!</h1>' > content/index.html
$ echo '<h1>Welcome!</h1>' > index.html
$ boop.py
Boop!
```
Now, you should have your "production-ready" website under a `./site` folder.
For example, if your website consists in a single `index.html` page, you should
obtain the following structure:
Now, you should have your "production-ready" website under a `./site` folder
that you can upload on your server.
```console
$ tree
.
├── content
│   └── index.html
├── index.html
└── site
└── index.html
```
Boop! basically just copied `content` files under a `site` directory. But it
can convert Markdown files in HTML too. For that, you'll need a template file
for articles:
Well OK, Boop! basically just copied the `index.html` file under the `site`
directory. Let's write an article then.
For that, you'll need a template file:
```console
$ mkdir theme
$ echo '<html><body>{{ ARTICLE_CONTENT }}</body></html' > theme/article.html
```
Then, you can create your Markdown file as you did with the HTML one:
Then, you can create a Markdown file under a `./content` folder:
```console
$ echo '# Welcome!' > content/markdown-index.md
$ mkdir content
$ echo '# My first article' > content/my-article.md
$ boop.py
$ echo site/markdown-index.html
<html><body><h1>Welcome!</h1></body></html>
$ echo site/my-article.html
<html><body><h1>My first article</h1></body></html>
```
You can define meta variables in the Markdown file which will be accessible
......@@ -85,7 +78,7 @@ example, for the following Markdown file:
```markdown
---
title: Welcome!
title: An article
author: Marien
---
......@@ -113,10 +106,10 @@ It will produce the following file:
```html
<html>
<head>
<title>Welcome!</title>
<title>An article</title>
</head>
<body>
<h1>Welcome!</h1>
<h1>An article</h1>
<p>By Marien</p>
<p>This is my article.</p>
......@@ -128,6 +121,8 @@ For now, you can use any valid Python expression between `{{ }}`, you have
access to the variables defined in the meta header, the Python builtin
functions and the `datetime` module.
Other files under `./content` are copied to the `./site` folder.
## Tests
There are some tests (i.e. doctests) that can be run to check that everything
......
......@@ -62,12 +62,7 @@ def convert_meta_to_article_vars(meta):
def main():
# Check that content directory exists on the filesystem
content_path = os.path.join(os.curdir, "content")
if not os.path.isdir(content_path):
raise ProgramError("./content directory does not exist")
# Make sure output dir doesn't exist
# Make sure ./site folder is empty
output_path = os.path.join(os.curdir, "site")
if os.path.isdir(output_path):
# it should be a directory...
......@@ -75,6 +70,20 @@ def main():
elif os.path.exists(output_path):
# ... but it also can be a simple file if user created it manually!
os.remove(output_path)
os.makedirs(output_path, exist_ok=True)
# Check that index file exists and copy it under the ./site folder
index_filepath = os.path.join(os.curdir, "index.html")
if not os.path.exists(index_filepath):
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)
# Check that content directory exists on the filesystem
content_path = os.path.join(os.curdir, "content")
if not os.path.isdir(content_path):
# If not, just stop here
return
md = markdown.Markdown(extensions=["meta", "fenced_code", "attr_list"])
......
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