Commit a069ecbc authored by berumuron's avatar berumuron
Browse files

add: Convert Markdown files to HTML

parent 9ef8be10
# Boop! – a simple "low-tech" static site generator, for fun.
## Installation
In this guide, we assume you are using Linux.
First, you should clone the Boop! repository and install its dependencies.
Boop! requires Python 3.6 to work (mainly because of our use of the `f-strings`).
$ git clone
$ cd boop
$ pip3 install -r requirements.txt
$ cd ..
Then, add the path to your `.bashrc`:
$ echo export PATH="$(pwd)/boop:\$PATH" >> ~/.bashrc
And source it so it considers the change:
$ source ~/.bashrc
## Usage
In this section, we assume you are using Linux.
First, create a project directory:
$ mkdir my-website && cd my-website
Create your website in a `./content` folder and execute the Boop! command:
Create a `./content` folder and execute the Boop! command:
$ mkdir content
$ echo '<h1>Welcome!</h1>' > content/index.html
$ ./
......@@ -23,13 +53,19 @@ $ tree
├── content
│   └── index.html
├── output
│   └── index.html
└── output
└── index.html
Yeah, it's kinda too simple for the moment (it only copies the files from
`./content` to `./output`), but new features are coming soon!
Boop! basically just copied `content` files under a `output` directory. But it
can convert Markdown files in HTML too:
$ echo '# Welcome!' > content/
$ echo output/markdown-index.html
## Tests
......@@ -4,6 +4,8 @@ import os
import sys
import shutil
import markdown
class ProgramError(Exception):
"""Exception raised during the program execution.
......@@ -54,16 +56,30 @@ def main():
# ... but it also can be a simple file if user created it manually!
md = markdown.Markdown()
# And copy the files from ./content to ./output
for filepath in dir_tree(content_path):
base, ext = os.path.splitext(filepath)
content_filepath = os.path.join(content_path, filepath)
output_filepath = os.path.join(output_path, filepath)
if ext == ".md":
output_filepath = os.path.join(output_path, f"{base}.html")
# First we need to create all the parent directories for our file
# Then, we copy content file to its output destination
shutil.copyfile(content_filepath, output_filepath)
if ext == ".md":
# Then, if it is a Markdown file, we convert it
with open(content_filepath, "r") as content_file:
html = md.convert(
# And we write it as a HTML file
with open(output_filepath, "w") as output_file:
# ... else, we simply copy the file to the output directory
shutil.copyfile(content_filepath, output_filepath)
if __name__ == "__main__":
Supports Markdown
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