add recently changed (fix #5)

master
Tomáš Mládek 2021-07-25 13:40:04 +02:00
parent b746274203
commit 690bb6715b
3 changed files with 87 additions and 23 deletions

View File

@ -208,6 +208,21 @@ async fn render(
let normalized_name = normalize_name(filename); let normalized_name = normalize_name(filename);
let mut recently_changed = cache
.pages
.clone()
.into_iter()
.filter_map(|i| match i.1.timestamp {
Some(ts) => Some((
i.0,
ts.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(),
)),
None => None,
})
.collect::<Vec<(String, u64)>>();
recently_changed.sort_by_key(|i| i.1);
recently_changed.reverse();
let mut backlinks: Vec<String> = vec![]; let mut backlinks: Vec<String> = vec![];
for (path, page) in cache.pages.iter() { for (path, page) in cache.pages.iter() {
if page if page
@ -228,6 +243,7 @@ async fn render(
data.title.as_ref().unwrap_or(&"Digital Garden".to_string()), data.title.as_ref().unwrap_or(&"Digital Garden".to_string()),
); );
context.insert("files", &cache.files); context.insert("files", &cache.files);
context.insert("recently_changed", &recently_changed);
context.insert( context.insert(
"page_title", "page_title",
&match page { &match page {

View File

@ -70,6 +70,10 @@ aside h1 {
font-variant: small-caps; font-variant: small-caps;
} }
aside h2 {
font-size: 12pt;
}
@media screen and (max-width: 800px) { @media screen and (max-width: 800px) {
body { body {
flex-direction: column-reverse; flex-direction: column-reverse;
@ -129,6 +133,14 @@ nav li {
margin: .25em 0; margin: .25em 0;
} }
nav ul a {
text-decoration: none;
}
nav .filepath {
text-decoration: underline;
}
nav .file { nav .file {
font-style: italic; font-style: italic;
opacity: .8; opacity: .8;
@ -138,6 +150,18 @@ nav .not-last {
opacity: .5; opacity: .5;
} }
nav .timestamp {
opacity: .8;
}
nav .timestamp:before {
content: "[";
}
nav .timestamp:after {
content: "]";
}
footer { footer {
padding: 1em 0; padding: 1em 0;
color: gray; color: gray;
@ -165,19 +189,15 @@ main footer {
background: #141414; background: #141414;
color: #e3e3e3; color: #e3e3e3;
} }
a { a {
color: #90d7e5; color: #90d7e5;
} }
a:visited { a:visited {
color: #3d9bb3; color: #3d9bb3;
} }
nav h1 a { nav h1 a {
color: white; color: white;
} }
code { code {
background: black; background: black;
color: #F8F8FC; color: #F8F8FC;

View File

@ -25,25 +25,53 @@
<aside> <aside>
<nav> <nav>
<h1><a href="/">{{garden_title}}</a></h1> <h1><a href="/">{{garden_title}}</a></h1>
<ul> {% if recently_changed %}
{% for file in files %} <section>
{% if file is containing(".md") %} <h2>Recently changed</h2>
<li class="page"> <ul>
<a href="/{{file}}"> {% for file_mtime in recently_changed | slice(end=5) %}
{% for component in file | trim_end_matches(pat=".md") | split(pat=".") %} <li class="page">
{%- if not loop.last -%} <a href="/{{file_mtime.0}}">
<span class="not-last">{{component}}.</span> <span class="timestamp">{{ file_mtime.1 | date(format="%Y-%m-%d %H:%M") }}</span>
{%- else -%} <span class="filepath">
<span>{{component}}</span> {% for component in file_mtime.0 | trim_end_matches(pat=".md") | split(pat=".") %}
{%- endif -%} {%- if not loop.last -%}
{% endfor %} <span class="not-last">{{component}}.</span>
</a> {%- else -%}
</li> <span>{{component}}</span>
{% else %} {%- endif -%}
<li class="file"><a href="/{{file}}">{{file}}</a></li> {% endfor %}
{% endif %} </span>
{% endfor %} </a>
</ul> </li>
{% endfor %}
</ul>
</section>
{% endif %}
<section>
<h2>All entries</h2>
<ul>
{% for file in files %}
{% if file is containing(".md") %}
<li class="page">
<a href="/{{file}}">
<span class="filepath">
{% for component in file | trim_end_matches(pat=".md") | split(pat=".") %}
{%- if not loop.last -%}
<span class="not-last">{{component}}.</span>
{%- else -%}
<span>{{component}}</span>
{%- endif -%}
{% endfor %}
</span>
</a>
</li>
{% else %}
<li class="file"><a href="/{{file}}">{{file}}</a></li>
{% endif %}
{% endfor %}
</ul>
</section>
</nav> </nav>
<footer><a href="https://gitlab.com/tmladek/gardenserver">gardenserver {{version}}</a></footer> <footer><a href="https://gitlab.com/tmladek/gardenserver">gardenserver {{version}}</a></footer>
</aside> </aside>