add recently changed (fix #5)
This commit is contained in:
parent
b746274203
commit
690bb6715b
3 changed files with 87 additions and 23 deletions
16
src/main.rs
16
src/main.rs
|
@ -208,6 +208,21 @@ async fn render(
|
|||
|
||||
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![];
|
||||
for (path, page) in cache.pages.iter() {
|
||||
if page
|
||||
|
@ -228,6 +243,7 @@ async fn render(
|
|||
data.title.as_ref().unwrap_or(&"Digital Garden".to_string()),
|
||||
);
|
||||
context.insert("files", &cache.files);
|
||||
context.insert("recently_changed", &recently_changed);
|
||||
context.insert(
|
||||
"page_title",
|
||||
&match page {
|
||||
|
|
|
@ -70,6 +70,10 @@ aside h1 {
|
|||
font-variant: small-caps;
|
||||
}
|
||||
|
||||
aside h2 {
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
body {
|
||||
flex-direction: column-reverse;
|
||||
|
@ -129,6 +133,14 @@ nav li {
|
|||
margin: .25em 0;
|
||||
}
|
||||
|
||||
nav ul a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
nav .filepath {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
nav .file {
|
||||
font-style: italic;
|
||||
opacity: .8;
|
||||
|
@ -138,6 +150,18 @@ nav .not-last {
|
|||
opacity: .5;
|
||||
}
|
||||
|
||||
nav .timestamp {
|
||||
opacity: .8;
|
||||
}
|
||||
|
||||
nav .timestamp:before {
|
||||
content: "[";
|
||||
}
|
||||
|
||||
nav .timestamp:after {
|
||||
content: "]";
|
||||
}
|
||||
|
||||
footer {
|
||||
padding: 1em 0;
|
||||
color: gray;
|
||||
|
@ -165,19 +189,15 @@ main footer {
|
|||
background: #141414;
|
||||
color: #e3e3e3;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #90d7e5;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #3d9bb3;
|
||||
}
|
||||
|
||||
nav h1 a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
code {
|
||||
background: black;
|
||||
color: #F8F8FC;
|
||||
|
|
|
@ -25,25 +25,53 @@
|
|||
<aside>
|
||||
<nav>
|
||||
<h1><a href="/">{{garden_title}}</a></h1>
|
||||
<ul>
|
||||
{% for file in files %}
|
||||
{% if file is containing(".md") %}
|
||||
<li class="page">
|
||||
<a href="/{{file}}">
|
||||
{% 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 %}
|
||||
</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="file"><a href="/{{file}}">{{file}}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if recently_changed %}
|
||||
<section>
|
||||
<h2>Recently changed</h2>
|
||||
<ul>
|
||||
{% for file_mtime in recently_changed | slice(end=5) %}
|
||||
<li class="page">
|
||||
<a href="/{{file_mtime.0}}">
|
||||
<span class="timestamp">{{ file_mtime.1 | date(format="%Y-%m-%d %H:%M") }}</span>
|
||||
<span class="filepath">
|
||||
{% for component in file_mtime.0 | 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>
|
||||
{% 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>
|
||||
<footer><a href="https://gitlab.com/tmladek/gardenserver">gardenserver {{version}}</a></footer>
|
||||
</aside>
|
||||
|
|
Loading…
Reference in a new issue