Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
authors page
Browse files Browse the repository at this point in the history
rochacbruno committed Nov 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6d159c8 commit 9270ec9
Showing 6 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/content/markdown-format.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ date: 2024-10-17 12:00:01
slug: markdown-format
description: The content here accepts any valid CommonMark or Github Flavoured markdown and some GFM extensions.
tags: docs, markdown, Common Mark, GFM
authors: rochacbruno,karlamagueta
authors: rochacbruno,karlamagueta,john
extra:
math: true
mermaid: true
12 changes: 11 additions & 1 deletion example/templates/content_authors.html
Original file line number Diff line number Diff line change
@@ -2,14 +2,24 @@
<div class="content-authors">
<ul>
{% for username in content.authors %}
{% if username in site.authors %}
{% set author = site.authors[username] %}
<li>
<a href="author-{{username}}.html">
<img src="{{ author.avatar }}" alt="{{ author.name }}" class="avatar">
{{ author.name }}
</a>
</li>
{% else %}
{# handle the case when author is defined on content but not on config #}
<li >
<a class="secondary" href="author-{{username}}.html" title="Author information not found, register on marmite.yaml">
<img src="https://robohash.org/{{username}}" alt="{{ username }}" class="avatar">
{{ username }}
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
{% endif %}
7 changes: 4 additions & 3 deletions src/content.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use unicode_normalization::UnicodeNormalization;
pub enum Kind {
Tag,
Archive,
Author,
}

#[allow(clippy::module_name_repetitions)]
@@ -45,11 +46,11 @@ impl GroupedContent {
}
vec.sort_by(|a, b| b.1.len().cmp(&a.1.len()));
}
Kind::Archive => {
for (year, contents) in &self.map {
Kind::Archive | Kind::Author => {
for (text, contents) in &self.map {
let mut contents = contents.clone();
contents.sort_by(|a, b| b.date.cmp(&a.date));
vec.push((year, contents));
vec.push((text, contents));
}
vec.sort_by(|a, b| b.0.cmp(a.0));
}
8 changes: 8 additions & 0 deletions src/markdown.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,14 @@ pub fn process_file(path: &Path, site_data: &mut Data) -> Result<(), String> {
for tag in content.tags.clone() {
site_data.tag.entry(tag).or_default().push(content.clone());
}
// authors
for username in content.authors.clone() {
site_data
.author
.entry(username)
.or_default()
.push(content.clone());
}
// archive by year
let year = date.year().to_string();
site_data
16 changes: 16 additions & 0 deletions src/site.rs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ pub struct Data {
pub pages: Vec<Content>,
pub tag: GroupedContent,
pub archive: GroupedContent,
pub author: GroupedContent,
}

impl Data {
@@ -39,6 +40,7 @@ impl Data {
pages: Vec::new(),
tag: GroupedContent::new(Kind::Tag),
archive: GroupedContent::new(Kind::Archive),
author: GroupedContent::new(Kind::Author),
}
}

@@ -361,6 +363,20 @@ fn handle_author_pages(
format!("author-{}", &author_slug).as_ref(),
)?;
}

// Render authors.html group page
let mut authors_list_context = global_context.clone();
authors_list_context.insert("title", &site_data.site.tags_title);
authors_list_context.insert("current_page", "authors.html");
authors_list_context.insert("kind", "author");
render_html(
"group.html",
"authors.html",
tera,
&authors_list_context,
output_dir,
)?;

Ok(())
}

1 change: 1 addition & 0 deletions src/tera_functions.rs
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ impl Function for Group {
let grouped_content = match kind {
"tag" => &self.site_data.tag,
"archive" => &self.site_data.archive,
"author" => &self.site_data.author,
_ => return Err(tera::Error::msg("Invalid `kind` argument")),
};

0 comments on commit 9270ec9

Please sign in to comment.