summaryrefslogtreecommitdiff
path: root/megapixels/app/site
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-01-04 23:37:34 +0100
committerJules Laplace <julescarbon@gmail.com>2019-01-04 23:37:34 +0100
commit276c16e1055c23350abd3d9d071cfce9b4f1b27f (patch)
treeb85c3b3c8ff0f7bfb77323d3f77be0f88bb3086f /megapixels/app/site
parente5b6ef658e936c32d9500ff7f781171d9785315a (diff)
rm rotation on homepage, add dataset list
Diffstat (limited to 'megapixels/app/site')
-rw-r--r--megapixels/app/site/builder.py20
-rw-r--r--megapixels/app/site/parser.py16
2 files changed, 28 insertions, 8 deletions
diff --git a/megapixels/app/site/builder.py b/megapixels/app/site/builder.py
index ff1a0c83..fac49c24 100644
--- a/megapixels/app/site/builder.py
+++ b/megapixels/app/site/builder.py
@@ -14,7 +14,7 @@ env = Environment(
autoescape=select_autoescape([])
)
-def build_page(fn, research_posts):
+def build_page(fn, research_posts, datasets):
"""
build a single page from markdown into the appropriate template
- writes it to site/public/
@@ -40,6 +40,8 @@ def build_page(fn, research_posts):
elif 'research/' in fn:
skip_h1 = True
template = env.get_template("research.html")
+ elif 'datasets/index' in fn:
+ template = env.get_template("datasets.html")
else:
template = env.get_template("page.html")
@@ -60,17 +62,18 @@ def build_page(fn, research_posts):
content=content,
research_posts=research_posts,
latest_research_post=research_posts[-1],
+ datasets=datasets,
)
os.makedirs(output_path, exist_ok=True)
with open(output_fn, "w") as file:
file.write(html)
-def build_research_index(research_posts):
+def build_index(key, research_posts, datasets):
"""
build the index of research (blog) posts
"""
- metadata, sections = parser.read_metadata('../site/content/research/index.md')
+ metadata, sections = parser.read_metadata('../site/content/{}/index.md'.format(key))
template = env.get_template("page.html")
s3_path = s3.make_s3_path(cfg.S3_SITE_PATH, metadata['path'])
content = parser.parse_markdown(sections, s3_path, skip_h1=False)
@@ -80,8 +83,9 @@ def build_research_index(research_posts):
content=content,
research_posts=research_posts,
latest_research_post=research_posts[-1],
+ datasets=datasets,
)
- output_fn = cfg.DIR_SITE_PUBLIC + '/research/index.html'
+ output_fn = '{}/{}/index.html'.format(cfg.DIR_SITE_PUBLIC, key)
with open(output_fn, "w") as file:
file.write(html)
@@ -90,14 +94,16 @@ def build_site():
build the site! =^)
"""
research_posts = parser.read_research_post_index()
+ datasets = parser.read_datasets_index()
for fn in glob.iglob(os.path.join(cfg.DIR_SITE_CONTENT, "**/*.md"), recursive=True):
- build_page(fn, research_posts)
- build_research_index(research_posts)
+ build_page(fn, research_posts, datasets)
+ build_index('research', research_posts, datasets)
def build_file(fn):
"""
build just one page from a filename! =^)
"""
research_posts = parser.read_research_post_index()
+ datasets = parser.read_datasets_index()
fn = os.path.join(cfg.DIR_SITE_CONTENT, fn)
- build_page(fn, research_posts)
+ build_page(fn, research_posts, datasets)
diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py
index b3d3a8c2..d3eccfca 100644
--- a/megapixels/app/site/parser.py
+++ b/megapixels/app/site/parser.py
@@ -66,6 +66,8 @@ def format_applet(section, s3_path):
opt = None
if command == 'python' or command == 'javascript' or command == 'code':
return format_section([ section ], s3_path)
+ if command == '':
+ return ''
applet['command'] = command
if opt:
@@ -221,8 +223,20 @@ def read_research_post_index():
"""
Generate an index of the research (blog) posts
"""
+ return read_post_index('research')
+
+def read_datasets_index():
+ """
+ Generate an index of the datasets
+ """
+ return read_post_index('datasets')
+
+def read_post_index(basedir):
+ """
+ Generate an index of posts
+ """
posts = []
- for fn in sorted(glob.glob('../site/content/research/*/index.md')):
+ for fn in sorted(glob.glob('../site/content/{}/*/index.md'.format(basedir))):
metadata, valid_sections = read_metadata(fn)
if metadata is None or metadata['status'] == 'private' or metadata['status'] == 'draft':
continue