aboutsummaryrefslogtreecommitdiff
path: root/src/templ_data/repo.rs
blob: 989c9b4046202602e4bebceef261d89d0f0c52af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Repository specific template data

use std::collections::BTreeMap;

/// A simple overview of a repository
///
/// This type can be generated by the octopus Repository state wrapper
#[derive(Clone)]
pub(crate) struct RepoData {
    pub owner: String,
    pub name: String,
    pub tagline: String,
    pub num_commit: usize,
    pub num_branch: usize,
    pub num_tag: usize,
    pub num_contributor: usize,
    pub size: String,
    pub logo: String,
}

/// Data about an individual commit
#[derive(Clone)]
pub(crate) struct CommitData {
    pub hash: String,
    pub message: String,
    pub author: String,
    pub date: String,
    pub diff: (usize, usize),
}

/// Data about a branch
#[derive(Clone)]
pub(crate) struct BranchData {
    pub name: String,
    pub last_commit: CommitData,
}

/// Data about a repository tree
#[derive(Clone)]
pub(crate) struct TreeData {
    /// The path segments in the current directory
    curr_dir: Vec<String>,
    /// The set of children in this tree segment
    files: BTreeMap<String, FileData>,
}

/// Information about a concrete file in a tree
#[derive(Clone)]
pub(crate) struct FileData {
    name: String,
    last_commit: CommitData,
    is_directory: bool,
}

pub(crate) mod pages {
    use super::*;
    use crate::templ_data::BaseData;
    use askama::Template;

    #[derive(Template)]
    #[template(path = "repo/about.html")]
    pub(crate) struct About {
        pub base: BaseData,
        pub repo: RepoData,

        // Template specific
        pub readme: String,
    }

    #[derive(Template)]
    #[template(path = "repo/details.html")]
    pub(crate) struct Details {
        pub base: BaseData,
        pub repo: RepoData,

        // Template specifics
        pub branches: Vec<BranchData>,
        pub commits: Vec<CommitData>,
    }
}