use std::{path::Path, vec};
use comrak::Options;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct AppConfig {
pub root_title: String,
pub root_description: String,
pub root_readme: String,
pub snapshots: Vec<String>,
pub favicon: String,
pub logo: String,
pub logo_alt: String,
pub logo_link: String,
pub enable_http_clone: bool,
pub enable_index_links: bool,
pub enable_index_owner: bool,
pub clone_prefix: String,
pub ssh_clone_prefix: String,
pub max_commit_message_length: usize,
pub max_repo_desc_length: usize,
}
impl ::std::default::Default for AppConfig {
fn default() -> Self {
Self {
root_title: String::from("Git repository browser"),
root_description: String::new(),
root_readme: String::new(),
snapshots: vec![
String::from("tar.gz"),
String::from("tar.bz2"),
String::from("zip"),
],
favicon: String::new(),
logo: String::new(),
logo_alt: String::from("🏡"),
logo_link: String::from("/"),
enable_http_clone: true,
enable_index_links: false,
enable_index_owner: true,
clone_prefix: String::new(),
ssh_clone_prefix: String::new(),
max_commit_message_length: 0,
max_repo_desc_length: 0,
}
}
}
impl AppConfig {
pub fn load(path: String) -> Self {
confy::load_path(path).unwrap_or_default()
}
pub fn http_clone_enabled(&self) -> bool {
(!self.clone_prefix.is_empty() || !self.ssh_clone_prefix.is_empty())
&& self.enable_http_clone
}
pub fn root_readme_is_valid(&self) -> bool {
Path::new(&self.root_readme).try_exists().unwrap_or(false)
}
}
pub struct ReadmeConfig;
impl ReadmeConfig {
pub fn gfm() -> Options {
let mut options = Options::default();
options.extension.autolink = true;
options.extension.footnotes = true;
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.tagfilter = true;
options.extension.tasklist = true;
options
}
}