Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
berumuron
Boop
Commits
a069ecbc
Commit
a069ecbc
authored
Dec 03, 2018
by
berumuron
Browse files
add: Convert Markdown files to HTML
parent
9ef8be10
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a069ecbc
# 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`
).
```
console
$
git clone https://framagit.org/marien.fressinaud/boop.git
$
cd
boop
$
pip3
install
-r
requirements.txt
$
cd
..
```
Then, add the path to your
`.bashrc`
:
```
console
$
echo export
PATH
=
"
$(
pwd
)
/boop:
\$
PATH"
>>
~/.bashrc
```
And source it so it considers the change:
```
console
$
source
~/.bashrc
```
## Usage
In this section, we assume you are using Linux.
First, create a project directory:
```
console
$
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:
```
console
$
mkdir
content
$
echo
'<h1>Welcome!</h1>'
>
content/index.html
$
./
boop.py
$
boop.py
Boop!
```
...
...
@@ -23,13 +53,19 @@ $ tree
.
├── content
│ └── index.html
├── output
│ └── index.html
└── boop.py
└── 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:
```
console
$
echo
'# Welcome!'
>
content/markdown-index.md
$
boop.py
$
echo
output/markdown-index.html
<h1>
Welcome!</h1>
```
## Tests
...
...
boop.py
View file @
a069ecbc
...
...
@@ -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!
os
.
remove
(
output_path
)
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
mkdirs_for_file
(
output_filepath
)
# 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
(
content_file
.
read
())
# And we write it as a HTML file
with
open
(
output_filepath
,
"w"
)
as
output_file
:
output_file
.
write
(
html
)
else
:
# ... else, we simply copy the file to the output directory
shutil
.
copyfile
(
content_filepath
,
output_filepath
)
if
__name__
==
"__main__"
:
...
...
requirements.txt
0 → 100644
View file @
a069ecbc
markdown
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment