mirror of
https://github.com/RealOrangeOne/notes.git
synced 2024-11-18 18:09:13 +00:00
Add notes list and optimise getting notes
This commit is contained in:
parent
3108f3a01f
commit
c988131d09
5 changed files with 57 additions and 3 deletions
6
docs/notes/index.md
Normal file
6
docs/notes/index.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
template: all.html
|
||||||
|
hide: [toc]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Notes
|
|
@ -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):
|
def on_env(env, config, files):
|
||||||
env.tests["startswith"] = str.startswith
|
env.tests["startswith"] = str.startswith
|
||||||
|
env.globals["get_page"] = get_page
|
||||||
|
env.globals["get_notes"] = get_notes
|
||||||
|
|
|
@ -26,7 +26,7 @@ theme:
|
||||||
features:
|
features:
|
||||||
- navigation.top
|
- navigation.top
|
||||||
- navigation.sections
|
- navigation.sections
|
||||||
- navigation.index
|
- navigation.indexes
|
||||||
- toc.follow
|
- toc.follow
|
||||||
- search.suggest
|
- search.suggest
|
||||||
- navigation.top
|
- navigation.top
|
||||||
|
@ -102,6 +102,7 @@ plugins:
|
||||||
exclude:
|
exclude:
|
||||||
- tags.md
|
- tags.md
|
||||||
- README.md
|
- README.md
|
||||||
|
- notes/index.md
|
||||||
- minify_html
|
- minify_html
|
||||||
- social
|
- social
|
||||||
- rss:
|
- rss:
|
||||||
|
|
16
theme/all.html
Normal file
16
theme/all.html
Normal file
|
@ -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 %}
|
|
@ -5,8 +5,11 @@
|
||||||
|
|
||||||
<h2>Recent notes</h2>
|
<h2>Recent notes</h2>
|
||||||
|
|
||||||
|
{% set notes_index = get_page('notes/index.md') %}
|
||||||
|
{% set notes = get_notes() %}
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for page in (nav.pages|selectattr("url", "startswith", "notes/")|sort(attribute="meta.git_creation_date_localized_raw_iso_datetime", reverse=True))[:10] %}
|
{% for page in notes[:10] %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ page.url }}">{{ page.title }}</a> - {{ page.meta.git_creation_date_localized_raw_iso_date }}
|
<a href="{{ page.url }}">{{ page.title }}</a> - {{ page.meta.git_creation_date_localized_raw_iso_date }}
|
||||||
{% for tag in page.meta.tags %}
|
{% for tag in page.meta.tags %}
|
||||||
|
@ -16,5 +19,5 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p><a href="{{ 'tags/'|url }}">View all →</a></p>
|
<p><a href="{{ notes_index.url }}">View all {{ notes|length }} →</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue