-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notes list and optimise getting notes
- Loading branch information
1 parent
3108f3a
commit c988131
Showing
5 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
template: all.html | ||
hide: [toc] | ||
--- | ||
|
||
# Notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
import jinja2 | ||
|
||
@jinja2.pass_context | ||
def get_page(context, slug): | ||
nav = context["nav"] | ||
for page in nav.pages: | ||
if page.file.src_uri == slug: | ||
return page | ||
|
||
raise ValueError("Unable to find page for '%s'", slug) | ||
|
||
|
||
@jinja2.pass_context | ||
def get_notes(context): | ||
notes = [] | ||
for page in context["nav"].pages: | ||
if not page.file.src_uri.startswith("notes/"): | ||
continue | ||
|
||
if page.file.src_uri == "notes/index.md": | ||
continue | ||
|
||
notes.append(page) | ||
return sorted(notes, key=lambda p: p.meta["git_creation_date_localized_raw_iso_date"], reverse=True) | ||
|
||
|
||
def on_env(env, config, files): | ||
env.tests["startswith"] = str.startswith | ||
env.globals["get_page"] = get_page | ||
env.globals["get_notes"] = get_notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
{{ super() }} | ||
|
||
<ul> | ||
{% for page in get_notes() %} | ||
<li> | ||
<a href="{{ page.url }}">{{ page.title }}</a> - {{ page.meta.git_creation_date_localized_raw_iso_date }} | ||
{% for tag in page.meta.tags %} | ||
<span class="md-tag">{{ tag }}</span> | ||
{% endfor %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters