pub path: PathBuf,
pub repo_list: Option<String>,
pub repo_summary: Option<String>,
+ pub history: Option<String>,
pub commit: Option<String>,
+ pub branches: Option<String>,
pub branch: Option<String>,
+ pub tags: Option<String>,
pub tag: Option<String>,
pub file: Option<String>,
pub dir: Option<String>,
pub cloned_repos: Option<String>,
pub repo_list: Option<String>,
pub repo_summary: Option<String>,
+ pub history: Option<String>,
pub commit: Option<String>,
+ pub branches: Option<String>,
pub branch: Option<String>,
+ pub tags: Option<String>,
pub tag: Option<String>,
pub file: Option<String>,
pub dir: Option<String>,
}
//step_map_first!(boil_in_wort, Boil, Wort, |b: &Boil| { b.wort_start() });
+#[rustfmt::skip]
impl GitsySettingsOutputs {
- output_path_fn!(repo_list, GitObject, full_hash, false, "repos.html");
- output_path_fn!(repo_summary, GitObject, full_hash, false, "%REPO%/summary.html");
- output_path_fn!(commit, GitObject, full_hash, false, "%REPO%/commit/%ID%.html");
- output_path_fn!(branch, GitObject, full_hash, false, "%REPO%/branch/%ID%.html");
- output_path_fn!(tag, GitObject, full_hash, false, "%REPO%/tag/%ID%.html");
- output_path_fn!(file, GitFile, id, false, "%REPO%/file/%ID%.html");
- output_path_fn!(syntax_css, GitObject, full_hash, false, "%REPO%/file/syntax.css");
- output_path_fn!(dir, GitFile, id, false, "%REPO%/dir/%ID%.html");
- output_path_fn!(error, GitObject, full_hash, false, "404.html");
- output_path_fn!(global_assets, GitObject, full_hash, true, "assets/");
- output_path_fn!(repo_assets, GitObject, full_hash, true, "%REPO%/assets/");
+ output_path_fn!(repo_list, GitObject, full_hash, false, "repos.html");
+ output_path_fn!(repo_summary, GitObject, full_hash, false, "%REPO%/summary.html");
+ output_path_fn!(history, GitObject, full_hash, false, "%REPO%/history%PAGE%.html");
+ output_path_fn!(commit, GitObject, full_hash, false, "%REPO%/commit/%ID%.html");
+ output_path_fn!(branches, GitObject, full_hash, false, "%REPO%/branches%PAGE%.html");
+ output_path_fn!(branch, GitObject, full_hash, false, "%REPO%/branch/%ID%.html");
+ output_path_fn!(tags, GitObject, full_hash, false, "%REPO%/tags%PAGE%.html");
+ output_path_fn!(tag, GitObject, full_hash, false, "%REPO%/tag/%ID%.html");
+ output_path_fn!(file, GitFile, id, false, "%REPO%/file/%ID%.html");
+ output_path_fn!(syntax_css, GitObject, full_hash, false, "%REPO%/file/syntax.css");
+ output_path_fn!(dir, GitFile, id, false, "%REPO%/dir/%ID%.html");
+ output_path_fn!(error, GitObject, full_hash, false, "404.html");
+ output_path_fn!(global_assets, GitObject, full_hash, true, "assets/");
+ output_path_fn!(repo_assets, GitObject, full_hash, true, "%REPO%/assets/");
}
#[derive(Clone, Deserialize, Default, Debug)]
pub syntax_highlight: Option<bool>,
pub syntax_highlight_theme: Option<String>,
pub attributes: Option<BTreeMap<String, toml::Value>>,
+ pub paginate_history: Option<usize>,
+ pub paginate_branches: Option<usize>,
+ pub paginate_tags: Option<usize>,
pub limit_history: Option<usize>,
pub limit_commits: Option<usize>,
pub limit_branches: Option<usize>,
pub templates: GitsySettingsTemplates,
#[serde(rename(deserialize = "gitsy_outputs"))]
pub outputs: GitsySettingsOutputs,
+ pub paginate_history: Option<usize>,
+ pub paginate_branches: Option<usize>,
+ pub paginate_tags: Option<usize>,
pub limit_history: Option<usize>,
pub limit_commits: Option<usize>,
pub limit_branches: Option<usize>,
global_to_repo!(settings, repo, render_markdown);
global_to_repo!(settings, repo, syntax_highlight);
global_to_repo!(settings, repo, syntax_highlight_theme);
+ global_to_repo!(settings, repo, paginate_history);
+ global_to_repo!(settings, repo, paginate_branches);
+ global_to_repo!(settings, repo, paginate_tags);
global_to_repo!(settings, repo, limit_history);
global_to_repo!(settings, repo, limit_commits);
global_to_repo!(settings, repo, limit_branches);
render_markdown: settings.render_markdown.clone(),
syntax_highlight: settings.syntax_highlight.clone(),
syntax_highlight_theme: settings.syntax_highlight_theme.clone(),
+ paginate_history: settings.paginate_history.clone(),
+ paginate_branches: settings.paginate_branches.clone(),
+ paginate_tags: settings.paginate_tags.clone(),
limit_history: settings.limit_history.clone(),
limit_commits: settings.limit_commits.clone(),
limit_branches: settings.limit_branches.clone(),
}
(settings, repo_descriptions)
}
+
+ pub fn paginate_history(&self) -> usize {
+ match self.paginate_history.unwrap_or(usize::MAX) {
+ x if x == 0 => usize::MAX,
+ x => x,
+ }
+ }
+
+ pub fn paginate_branches(&self) -> usize {
+ match self.paginate_branches.unwrap_or(usize::MAX) {
+ x if x == 0 => usize::MAX,
+ x => x,
+ }
+ }
+
+ pub fn paginate_tags(&self) -> usize {
+ match self.paginate_tags.unwrap_or(usize::MAX) {
+ x if x == 0 => usize::MAX,
+ x => x,
+ }
+ }
}
use crate::git::GitFile;
use chrono::{naive::NaiveDateTime, offset::FixedOffset, DateTime};
+use serde::Serialize;
use std::collections::HashMap;
+use std::path::PathBuf;
use tera::{to_value, try_get_value, Filter, Function, Value};
fn ts_to_date(ts: i64, offset: Option<i64>, format: Option<String>) -> String {
Ok(to_value(ts_to_git_timestamp(ts, tz)).unwrap())
}
}
+
+#[derive(Serialize)]
+pub struct Pagination {
+ pub pages: usize,
+ pub page_idx: usize,
+ pub page_str: String,
+ pub cur_page: String,
+ pub next_page: Option<String>,
+ pub prev_page: Option<String>,
+}
+impl Pagination {
+ pub fn new(cur: usize, total: usize, url_template: &str) -> Self {
+ let digits = total.to_string().len().max(2);
+ let next = match cur + 1 <= total {
+ true => Some(cur + 1),
+ false => None,
+ };
+ let prev = match cur <= 1 {
+ true => None,
+ false => Some(cur - 1),
+ };
+ let cur_str = match cur <= 1 {
+ true => String::new(),
+ false => format!("{:0w$}", cur, w = digits),
+ };
+ let next_str = match next.unwrap_or(0) <= 1 {
+ true => String::new(),
+ false => format!("{:0w$}", next.unwrap_or(0), w = digits),
+ };
+ let prev_str = match prev.unwrap_or(0) <= 1 {
+ true => String::new(),
+ false => format!("{:0w$}", prev.unwrap_or(0), w = digits),
+ };
+ let cur_page = url_template.replace("%PAGE%", &cur_str);
+ let next_page = match next {
+ Some(_) => Some(url_template.replace("%PAGE%", &next_str)),
+ _ => None,
+ };
+ let prev_page = match prev {
+ Some(_) => Some(url_template.replace("%PAGE%", &prev_str)),
+ _ => None,
+ };
+ Pagination {
+ pages: total,
+ page_idx: cur,
+ page_str: cur_str.clone(),
+ cur_page,
+ next_page,
+ prev_page,
+ }
+ }
+
+ pub fn with_relative_paths(&self) -> Self {
+ let cur_page = {
+ let path = PathBuf::from(&self.cur_page);
+ path.file_name()
+ .expect(&format!("Invalid output filename: {}", self.cur_page))
+ .to_string_lossy()
+ .to_string()
+ };
+ let next_page = match &self.next_page {
+ Some(p) => {
+ let path = PathBuf::from(p);
+ Some(
+ path.file_name()
+ .expect(&format!("Invalid output filename: {}", p))
+ .to_string_lossy()
+ .to_string(),
+ )
+ }
+ _ => None,
+ };
+ let prev_page = match &self.prev_page {
+ Some(p) => {
+ let path = PathBuf::from(p);
+ Some(
+ path.file_name()
+ .expect(&format!("Invalid output filename: {}", p))
+ .to_string_lossy()
+ .to_string(),
+ )
+ }
+ _ => None,
+ };
+ Pagination {
+ pages: self.pages,
+ page_idx: self.page_idx,
+ page_str: self.page_str.clone(),
+ cur_page,
+ next_page,
+ prev_page,
+ }
+ }
+}
+{% extends "base.html" %}
+
+{% block content %}
+<table class="branches">
+ <tr>
+ <th>Branch</th>
+ <th>Commit ID</th>
+ <th>Message</th>
+ <th>Author</th>
+ <th>Date</th>
+ </tr>
+ {% for entry in branches -%}
+ <tr class="branch">
+ <td class="name"><a href="branch/{{entry.full_hash}}.html">{{entry.ref_name}}</a></td>
+ <td class="oid">{{entry.short_hash}}</td>
+ <td class="commit-msg" style="font-family: sans-serif;">{{entry.summary}}</td>
+ <td class="author">{{entry.author.name}}</td>
+ <td class="date">{{ts_to_date(ts=entry.ts_utc, tz=entry.ts_offset)}}</td>
+ </tr>
+ {% endfor -%}
+</table>
+{% if page.prev_page %}<a href="{{ page.prev_page }}">PREV</a>{% endif %} <a href="{{ page.cur_page }}">CUR</a> {%if page.next_page %}<a href="{{ page.next_page }}">NEXT</a>{% endif %}<br>
+{% endblock content %}
+{% extends "base.html" %}
+
+{% block content %}
+<table class="commits">
+ <tr>
+ <th>Commit ID</th>
+ <th>Message</th>
+ <th>Author</th>
+ <th>Date</th>
+ <th>Diff</th>
+ <th>Refs</th>
+ </tr>
+ {% for entry in history -%}
+ {% if loop.index0 < 250 -%}
+ <tr class="commit">
+ <td class="oid"><a href="commit/{{entry.full_hash}}.html">{{entry.short_hash}}</a></td>
+ <td class="commit-msg" style="font-family: sans-serif;">{{entry.summary}}</td>
+ <td class="author" style="font-family: sans-serif;">{{entry.author.name}}</td>
+ <td class="date">{{ts_to_date(ts=entry.ts_utc, tz=entry.ts_offset)}}</td>
+ <td class="diff">{{entry.stats.files}} (+{{entry.stats.additions}}/-{{entry.stats.deletions}})</td>
+ <td class="refs">{%- for ref in entry.alt_refs -%}{%- if loop.index0 > 0 -%}, {%- endif -%}<span class="commit-ref">{{ref}}</span>{%- endfor -%}</td>
+</tr>
+{% endif -%}
+{% endfor -%}
+</table>
+{% if page.prev_page %}<a href="{{ page.prev_page }}">PREV</a>{% endif %} <a href="{{ page.cur_page }}">CUR</a> {%if page.next_page %}<a href="{{ page.next_page }}">NEXT</a>{% endif %}<br>
+{% endblock content %}
{% extends "base.html" %}
{% block content %}
+<a href="history.html">Commit history</a><br>
+<a href="branches.html">All branches</a><br>
+<a href="tags.html">All tags</a><br>
+<br/>
<table class="commits">
<tr>
<th>Commit ID</th>
<th>Refs</th>
</tr>
{% for entry in history -%}
- {% if loop.index0 < 250 -%}
+ {% if loop.index0 < 10 -%}
<tr class="commit">
<td class="oid"><a href="commit/{{entry.full_hash}}.html">{{entry.short_hash}}</a></td>
<td class="commit-msg" style="font-family: sans-serif;">{{entry.summary}}</td>
<th>Date</th>
</tr>
{% for entry in branches -%}
+ {% if loop.index0 < 10 -%}
<tr class="branch">
<td class="name"><a href="branch/{{entry.full_hash}}.html">{{entry.ref_name}}</a></td>
<td class="oid">{{entry.short_hash}}</td>
<td class="author">{{entry.author.name}}</td>
<td class="date">{{ts_to_date(ts=entry.ts_utc, tz=entry.ts_offset)}}</td>
</tr>
+ {% endif -%}
{% endfor -%}
</table>
<th>Date</th>
</tr>
{% for entry in tags -%}
+ {% if loop.index0 < 10 -%}
<tr class="tag">
<td class="name"><a href="tag/{{entry.full_hash}}.html">{{entry.ref_name}}</a></td>
<td class="oid">{{entry.short_hash}}</td>
<td class="author">{{entry.author.name}}</td>
<td class="date">{{ts_to_date(ts=entry.ts_utc, tz=entry.ts_offset)}}</td>
</tr>
+ {% endif -%}
{% endfor -%}
</table>
+{% extends "base.html" %}
+
+{% block content %}
+<table class="tags">
+ <tr>
+ <th>Tag</th>
+ <th>Commit ID</th>
+ <th>Message</th>
+ <th>Author</th>
+ <th>Date</th>
+ </tr>
+ {% for entry in tags -%}
+ <tr class="tag">
+ <td class="name"><a href="tag/{{entry.full_hash}}.html">{{entry.ref_name}}</a></td>
+ <td class="oid">{{entry.short_hash}}</td>
+ <td class="commit-msg" style="font-family: sans-serif;">{{entry.summary}}</td>
+ <td class="author">{{entry.author.name}}</td>
+ <td class="date">{{ts_to_date(ts=entry.ts_utc, tz=entry.ts_offset)}}</td>
+ </tr>
+ {% endfor -%}
+</table>
+{% if page.prev_page %}<a href="{{ page.prev_page }}">PREV</a>{% endif %} <a href="{{ page.cur_page }}">CUR</a> {%if page.next_page %}<a href="{{ page.next_page }}">NEXT</a>{% endif %}<br>
+{% endblock content %}