Skip to content

Commit

Permalink
Add list view of all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Welch committed Dec 24, 2018
1 parent 4ea596c commit 2c27fc4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
24 changes: 23 additions & 1 deletion jinja/list.html
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
TODO
{% extends "base.template" %}

{% block title %}pages - list{% endblock %}

{% block header %}
list
{% endblock %}

{% block content %}
<ul class="page-list">
{% for page in pages %}
<li class="page-list">
<h2 class="josefin"><a href="{{ page.link }}">{{ page.title }}</a></h2>
<p class="std-font">
{{ page.description }}
</p>
<p class="small-font trailing-p">
last updated {{ page.last_modified_at.strftime('%B %d, %Y') }}
</p>
</li>
{% endfor %}
</ul>
{% endblock %}
1 change: 1 addition & 0 deletions markdown/hacks.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: pentesting reference
description: some penetration testing snippets and resources
published_at: 2018-12-20
last_modified_at: 2018-12-20
---
Expand Down
33 changes: 33 additions & 0 deletions static/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ a:active {
font-weight: 700;
}

.std-font {
font-size: 1.25rem;
}

.small-font {
font-size: 0.75rem;
}


/* nav bar */

Expand All @@ -80,6 +88,31 @@ div.nav-options a {
}


/* lists */

ul.page-list {
list-style-type: none;
padding: 0px;
}

li.page-list {
border-bottom: 1px solid #4e42f4;
margin-top: 25px;
}

li.page-list > p.trailing-p {
margin-bottom: 25px;
}

li.page-list:last-child {
border: none;
}

li.page-list > h2 {
margin: 0px;
}


/* specific tweaks */

h1.title {
Expand Down
40 changes: 27 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import print_function

import datetime
import markdown2
import os
import shutil
Expand All @@ -26,9 +27,12 @@

MD_EXTRAS = ['fenced-code-blocks', 'header-ids', 'metadata', 'tables']

DT_IN_FORMAT = '%Y-%m-%d'

Page = namedtuple(
'Page',
['published_at', 'last_modified_at', 'title', 'raw_html'])
['description', 'link', 'published_at', 'last_modified_at', 'raw_html',
'title'])


def _mkdir_if_not_present(dirname):
Expand All @@ -50,33 +54,34 @@ def _iter_paths(directory, glob_pattern):
yield path


def _to_dt(dt_str):
"""Convert a string to a datetime.datetime object."""
return datetime.datetime.strptime(dt_str, DT_IN_FORMAT)


def build():
"""Compile the site into the build directory."""
clean()
_mkdir_if_not_present(BUILD_DIR)

# compile html pages
env = Environment(loader=FileSystemLoader(JINJA_DIR))
for html_path in _iter_paths(JINJA_DIR, '*.html'):
template = env.get_template(html_path.name)
rendered_page = template.render()
dest_path = os.path.join(BUILD_DIR, html_path.name)
with open(dest_path, 'w') as f:
f.write(rendered_page)
print('[*] Compiled HTML pages into', BUILD_DIR)

# compile markdown pages
pages = []
md_template = env.get_template('md_page.template')
for md_path in _iter_paths(MD_DIR, '*.md'):
with md_path.open(encoding='utf-8') as f:
md_source = f.read()

md_as_html = markdown2.markdown(md_source, extras=MD_EXTRAS)
page = Page(
md_as_html.metadata['published_at'],
md_as_html.metadata['last_modified_at'],
md_as_html.metadata['title'],
str(md_as_html))
md_as_html.metadata['description'],
'/' + md_path.stem,
_to_dt(md_as_html.metadata['published_at']),
_to_dt(md_as_html.metadata['last_modified_at']),
str(md_as_html),
md_as_html.metadata['title'])
pages.append(page)
rendered_page = md_template.render(page=page)

dest_fname = md_path.stem + '.html'
Expand All @@ -85,6 +90,15 @@ def build():
f.write(rendered_page)
print('[*] Compiled markdown pages into', BUILD_DIR)

# compile html pages
for html_path in _iter_paths(JINJA_DIR, '*.html'):
template = env.get_template(html_path.name)
rendered_page = template.render(pages=pages)
dest_path = os.path.join(BUILD_DIR, html_path.name)
with open(dest_path, 'w') as f:
f.write(rendered_page)
print('[*] Compiled HTML pages into', BUILD_DIR)

# copy static files into the build static directory
shutil.copy(FAVICON_PATH, BUILD_DIR)
_rmdir_if_present(BUILD_STATIC_DIR)
Expand Down

0 comments on commit 2c27fc4

Please sign in to comment.