From 871ff0a30ea9d6698d6dc632637d39dd0134c004 Mon Sep 17 00:00:00 2001 From: Trevor Bentley Date: Thu, 12 Jan 2023 03:00:35 +0100 Subject: [PATCH] added proper default config file --- settings.toml => config.toml | 45 +++++++++++++++++++----------------- src/main.rs | 19 ++++++++++++++- templates/base.html | 2 +- templates/header.html | 4 ++-- 4 files changed, 45 insertions(+), 25 deletions(-) rename settings.toml => config.toml (95%) diff --git a/settings.toml b/config.toml similarity index 95% rename from settings.toml rename to config.toml index 24c61fa..9651efc 100644 --- a/settings.toml +++ b/config.toml @@ -7,17 +7,17 @@ # A friendly name for the generated site. # # This is accessible in all templates. -site_name = "Trevor's Repos" +#site_name = "" # The URL where this generated site is hosted. # # This is accessible in all templates. -site_url = "https://git.trevorbentley.com" +#site_url = "" # A description of the generated site. # # This is accessible in all templates. -site_description = "A bunch of git repos in a stupid format." +#site_description = "" # List of directories, each of which contains Git repositories to # index. @@ -31,7 +31,7 @@ site_description = "A bunch of git repos in a stupid format." # settings for bulk-imported repositories. Repositories that require # specific configuration can be explicitly specified later in this # file. -recursive_repo_dirs = ["repos/"] +#recursive_repo_dirs = [] # List of files to copy to the site's `global_assets` directory. # @@ -44,7 +44,7 @@ recursive_repo_dirs = ["repos/"] # # This can also be set per-repository, in which case the `repo_assets` output # directory is used. -asset_files = ["test.html"] +#asset_files = [] # Whether to render Markdown files in repos into HTML. # @@ -87,7 +87,7 @@ syntax_highlight_theme = "base16-ocean.light" # usage. # # This can also be set per-repository. -limit_history = 500 +#limit_history = 500 # Limits maximum number of commits to output. # @@ -96,7 +96,7 @@ limit_history = 500 # to the templates. # # This can also be set per-repository. -limit_commits = 500 +#limit_commits = 500 # Limits maximum number of branches to parse. # @@ -107,7 +107,7 @@ limit_commits = 500 # values for this are very large, or 0 (to disable branches). # # This can also be set per-repository. -limit_branches = 500 +#limit_branches = 500 # Limits maximum number of tags to parse. # @@ -118,7 +118,7 @@ limit_branches = 500 # for this are very large, or 0 (to disable tags). # # This can also be set per-repository. -limit_tags = 500 +#limit_tags = 500 # Limits directory depth to traverse when parsing files. # @@ -131,7 +131,7 @@ limit_tags = 500 # file listing. If set to 1 or greater, only applies to `all_files`. # # This can also be set per-repository. -limit_tree_depth = 20 +#limit_tree_depth = 20 # Limits size of files in repo with content previews. # @@ -140,7 +140,7 @@ limit_tree_depth = 20 # include the text contents. # # This can also be set per-repository. -limit_file_size = 2097152 +#limit_file_size = 2097152 # Limits size of a single produced repository. # @@ -157,7 +157,7 @@ limit_file_size = 2097152 # disk usage. # # This can also be set per-repository. -limit_repo_size = 52428800 +#limit_repo_size = 52428800 # Limits total size of all output. # @@ -174,7 +174,7 @@ limit_repo_size = 52428800 # disk usage. # # This can also be set per-repository. -limit_total_size = 524288000 +#limit_total_size = 524288000 @@ -342,18 +342,19 @@ generated_by = "Itsy-Gitsy" # The section name is used as the repository name if no `name` attribute is # provided. -[circadian] +#[my_repository] + # Path to the Git repository. -path = "more_repos/circadian" +#path = "/path/to/my_repository" # Name of this repository, if different from the section name. -name = "circadian" +#name = "my_repository" # A description of this repository. -description = "A repository full of code" +#description = "" # URL of website associated with this repository. -website = "https://circadian.trevorbentley.com" +#website = "" # Dictionary of arbitrary, user-defined attributes associated with the repo. # @@ -361,7 +362,7 @@ website = "https://circadian.trevorbentley.com" # # Available in all repo-specific page templates. # -attributes = { status = "active", type = "daemon" } +#attributes = { status = "active", type = "daemon" } # Per-repository settings, same as the global versions described above: @@ -386,5 +387,7 @@ attributes = { status = "active", type = "daemon" } #status = "active" #type = "daemon" -[ossuary] -path = "https://github.com/mrmekon/ossuary" +# Remote HTTPS repositories can also be specified: +# +#[remote_repo] +#path = "https://github.com/my_user_name/remote_repo" diff --git a/src/main.rs b/src/main.rs index 5ede16a..8eb18c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -893,8 +893,20 @@ fn write_rendered(path: &str, rendered: &str) -> usize { fn main() { let start_all = std::time::Instant::now(); let cli = CliArgs::parse(); - let config_path = cli.config.as_deref().unwrap_or(Path::new("config.toml")); + let config_path = cli.config.as_deref().unwrap_or(Path::new("config.toml")).to_owned(); let config_dir = config_path.parent().expect("Config file not in valid directory.").to_owned(); + let config_dir = match config_dir.to_str().unwrap_or_default().len() > 0 { + true => config_dir, + false => PathBuf::from("."), + }; + let config_path = match config_path.canonicalize() { + Ok(d) => d, + _ => config_path.clone(), + }; + let config_dir = match config_dir.canonicalize() { + Ok(d) => d, + _ => config_dir.clone(), + }; VERBOSITY.store(match cli.quiet { true => 0, false => (cli.verbose + 1).into(), @@ -1003,6 +1015,11 @@ fn main() { let mut total_bytes = 0; let mut repos: Vec = vec!(); + if repo_descriptions.len() == 0 { + panic!("No Git repositories defined! Please check your configuration file ({})", + config_path.display()); + } + // Sort the repositories by name let mut repo_vec: Vec = repo_descriptions.drain().collect(); repo_vec.sort_by(|x,y| x.name.as_deref().map(|n| n.cmp(&y.name.as_deref().unwrap_or_default())) diff --git a/templates/base.html b/templates/base.html index ee9c416..882f694 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,7 +1,7 @@ {% block html_head -%} -{{site_name}} +{{site_name | default(value="Itsy-Gitsy")}} {% block html_head_extra -%} {% endblock html_head_extra -%} {% endblock html_head -%} diff --git a/templates/header.html b/templates/header.html index 3968b07..16e9ddf 100644 --- a/templates/header.html +++ b/templates/header.html @@ -1,3 +1,3 @@ -Site: {{site_name}}
-Description: {{site_description}}
+Site: {{site_name | default(value="Itsy-Gitsy") }}
+Description: {{site_description | default(value="A collection of Git repositories")}}