yagit

Yet another static site generator for Git 🙀️

Commit
50aeb7185230681e76ac27c281b8e475138bf528
Parent
cc8f8e6dd611a0ff19b43fa4d28fb8315ac861d3
Author
Pablo <pablo-pie@riseup.net>
Date

Moved config keys to TOML

Moved te compile-time configuration keys to config.toml

Diffstats

6 files changed, 48 insertions, 28 deletions

Status Name Changes Insertions Deletions
Modified Cargo.toml 2 files changed 1 0
Modified README.md 2 files changed 1 1
Modified TODO.md 2 files changed 0 1
Added config.toml 1 file changed 23 0
Modified src/config.rs 2 files changed 17 20
Modified src/main.rs 2 files changed 6 6
diff --git a/Cargo.toml b/Cargo.toml
@@ -8,3 +8,4 @@ description = "Yet another static site generator for Git"
 git2 = "0.20.0"
 libc = "0.2.170"
 pulldown-cmark = "0.13.0"
+static-toml = "1.3.0"
diff --git a/README.md b/README.md
@@ -51,7 +51,7 @@ For more information check the `yagit.1` man page.
 ## Configuration
 
 A number of configuration options is provided at compile-time. See
-`src/config.rs`.
+`config.toml`.
 
 ### Customizing the HTML Output
 
diff --git a/TODO.md b/TODO.md
@@ -2,7 +2,6 @@
 
 * do performance analysis with flamegraph to identify bottlenecks
 
-* Documment the subcommand system
 * Add functionality:
   * subcommand for re-rendering the index
   * subcommand for deleting an existing repo
diff --git /dev/null b/config.toml
@@ -0,0 +1,23 @@
+[output]
+tree_subdir         = "tree"
+blob_subdir         = "blob"
+commit_subdir       = "commit"
+private_output_root = "private/"
+
+[output.release]
+path = "/var/www/git"
+
+[output.debug]
+path = "./site"
+
+[git]
+store_owner = "Pablo"
+user = "git"
+
+[git.release]
+store_path         = "/var/git/public"  # path to the public  repo store
+private_store_path = "/var/git/private" # path to the private repo store
+
+[git.debug]
+store_path         = "./test/public"  # path to the public  repo store
+private_store_path = "./test/private" # path to the private repo store
diff --git a/src/config.rs b/src/config.rs
@@ -1,33 +1,30 @@
 //! Compile-time configuration keys
-// TODO: [feature]: read this from a TOML file at build-time?
-
-#[cfg(not(debug_assertions))]
-pub const REPOS_DIR: &str = "/var/git/public";
-
-#[cfg(debug_assertions)]
-pub const REPOS_DIR: &str = "./test/public";
 
+static_toml::static_toml! {
+  static CONFIG = include_toml!("config.toml");
+}
 
 #[cfg(not(debug_assertions))]
-pub const PRIVATE_REPOS_DIR: &str = "/var/git/private";
+pub const OUTPUT_PATH: &str = CONFIG.output.release.path;
 
 #[cfg(debug_assertions)]
-pub const PRIVATE_REPOS_DIR: &str = "./test/private";
+pub const OUTPUT_PATH: &str = CONFIG.output.debug.path;
 
+pub const TREE_SUBDIR:         &str = CONFIG.output.tree_subdir;
+pub const BLOB_SUBDIR:         &str = CONFIG.output.blob_subdir;
+pub const COMMIT_SUBDIR:       &str = CONFIG.output.commit_subdir;
+pub const PRIVATE_OUTPUT_ROOT: &str = CONFIG.output.private_output_root;
 
 #[cfg(not(debug_assertions))]
-pub const OUTPUT_PATH: &str = "/var/www/git";
+pub const GIT_USER: &str = CONFIG.git.user;
+pub const OWNER: &str = CONFIG.git.store_owner;
 
 #[cfg(debug_assertions)]
-pub const OUTPUT_PATH: &str = "./site";
-
-pub const PRIVATE_OUTPUT_ROOT: &str = "private/";
+pub const STORE_PATH:         &str = CONFIG.git.debug.store_path;
+#[cfg(debug_assertions)]
+pub const PRIVATE_STORE_PATH: &str = CONFIG.git.debug.private_store_path;
 
 #[cfg(not(debug_assertions))]
-pub const GIT_USER: &str = "git";
-
-pub const OWNER: &str = "Pablo";
-
-pub const TREE_SUBDIR:   &str = "tree";
-pub const BLOB_SUBDIR:   &str = "blob";
-pub const COMMIT_SUBDIR: &str = "commit";
+pub const STORE_PATH:         &str = CONFIG.git.release.store_path;
+#[cfg(not(debug_assertions))]
+pub const PRIVATE_STORE_PATH: &str = CONFIG.git.release.private_store_path;
diff --git a/src/main.rs b/src/main.rs
@@ -189,9 +189,9 @@ impl RepoInfo {
   /// `config::PRIVATE_REPOS_DIR`.
   fn index(private: bool) -> Result<Vec<Self>, ()> {
     let repos_dir = if private {
-      config::PRIVATE_REPOS_DIR
+      config::PRIVATE_STORE_PATH
     } else {
-      config::REPOS_DIR
+      config::STORE_PATH
     };
 
     match fs::read_dir(repos_dir) {
@@ -1542,9 +1542,9 @@ fn main() -> ExitCode {
   }
 
   let repos_dir = if cmd.flags.private() {
-    config::PRIVATE_REPOS_DIR
+    config::PRIVATE_STORE_PATH
   } else {
-    config::REPOS_DIR
+    config::STORE_PATH
   };
 
   match cmd.sub_cmd {
@@ -1627,9 +1627,9 @@ fn main() -> ExitCode {
     }
     SubCmd::Init { repo_name, description } => {
       let mut repo_path = if cmd.flags.private() {
-        PathBuf::from(config::PRIVATE_REPOS_DIR)
+        PathBuf::from(config::PRIVATE_STORE_PATH)
       } else {
-        PathBuf::from(config::REPOS_DIR)
+        PathBuf::from(config::STORE_PATH)
       };
       repo_path.push(&repo_name);