summaryrefslogtreecommitdiff
path: root/scraper/builder.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-12-04 21:12:59 +0100
committerJules Laplace <julescarbon@gmail.com>2018-12-04 21:12:59 +0100
commitd69086a1b2d7d6e6def55f35e30d0623701de011 (patch)
tree1f73899aa4bcb9ecf0600f0d95f5909c79818780 /scraper/builder.py
parent966e27c7418d6e188ea4b1f651a5e6c67495b765 (diff)
embedding images
Diffstat (limited to 'scraper/builder.py')
-rw-r--r--scraper/builder.py69
1 files changed, 0 insertions, 69 deletions
diff --git a/scraper/builder.py b/scraper/builder.py
deleted file mode 100644
index c55b6dff..00000000
--- a/scraper/builder.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/python
-
-import os
-import glob
-import mistune
-from jinja2 import Environment, FileSystemLoader, select_autoescape
-
-public_path = "../site/public"
-content_path = "../site/content"
-template_path = "../site/templates"
-
-env = Environment(
- loader=FileSystemLoader(template_path),
- autoescape=select_autoescape([])
-)
-
-renderer = mistune.Renderer(escape=False)
-markdown = mistune.Markdown(renderer=renderer)
-
-def wide_section(line):
- return "<section class='wide'>" + markdown(line) + "</section>"
-
-def normal_section(lines):
- if len(lines):
- return "<section>" + markdown("\n\n".join(lines)) + "</section>"
- return ""
-
-def build_file(fn):
- print(fn)
- output_path = os.path.dirname(fn).replace(content_path, public_path)
- output_fn = os.path.join(output_path, "index.html")
- with open(fn, "r") as file:
- sections = file.read().split("\n\n")
- metadata = {}
- for line in sections[0].split("\n"):
- print(line)
- key, value = line.split(': ', 1)
- metadata[key.lower()] = value
-
- groups = []
- current_group = []
- for section in sections[1:]:
- if '![wide]' in section:
- groups.append(normal_section(current_group))
- groups.append(wide_section(section))
- current_group = []
- else:
- current_group.append(section)
- groups.append(normal_section(current_group))
- content = "".join(groups)
-
- if 'blog/' in fn:
- template = env.get_template("blog.html")
- else:
- template = env.get_template("page.html")
- html = template.render(metadata=metadata, content=content)
-
- os.makedirs(output_path, exist_ok=True)
- with open(output_fn, "w") as file:
- file.write(html)
-
-def build_site():
- print("Building...")
- for fn in glob.iglob(os.path.join(content_path, "**/index.txt"), recursive=True):
- print(fn)
- build_file(fn)
-
-if __name__ == '__main__':
- build_site()