This commit is contained in:
Tyrel Souza 2023-10-14 23:23:58 -04:00
parent 7fed8e907a
commit 257b6cc155
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
2 changed files with 58 additions and 5 deletions

52
README.md Normal file
View File

@ -0,0 +1,52 @@
# Tyrel's Rust Static Site Generator
## Links
Configuration
* `config.yaml`
* links.yaml`
* template html
* static directory
### example: `config.yaml`
```yaml
output_dir: public/
links:
source: data/links/links.yaml
template: templates/links/links.html
static_dir: static/
```
### example: `links.yaml`
```yaml
config:
title: Where to find Tyrel Souza
name: Tyrel Souza
description: Software Engineer, gamer, tech-enthusiast, ham, pilot, father
avatar: loupe.jpg
background: moroccan-flower-dark.png
background_opacity: 0.7
links:
- title: Sites
links:
- text: Blog
icon: fa fa-blog
href: https://tyrel.dev
- title: Social
- text: Mastodon
rels: me
icon: fa fa-mastodon
href: https://mastodon.social/@tyrel
- title: Gaming
- text: Switch Friendcode
icon: fa-solid fa-gamepad
copy: "SW-1711-7753-4091"
```
### example `template.html`
[Example code Here](./templates/links/links.html)
### static dir
This is optional, but everything inside will be copied directly next to the `index.html` in the `links` directory

View File

@ -15,8 +15,8 @@ pub struct Config {
blog: Option<BlogConfig>,
}
fn load_config() -> Config {
let config_file = std::fs::File::open("./config.yaml").expect("Could not find config.yaml file");
fn load_config(filename: &str) -> Config {
let config_file = std::fs::File::open(filename).expect("Could not find config.yaml file");
let config: Result<Config, serde_yaml::Error> = serde_yaml::from_reader(config_file);
match config {
@ -28,9 +28,10 @@ fn load_config() -> Config {
let msg = &err.to_string()[..=last_backtick_index];
eprintln!("Error with Configuration file: {}", msg);
} else {
// If there are no backticks, you may want to handle this differently
eprintln!("Error with Configuration file: {}", &err.to_string());
let msg = &err.to_string();
eprintln!("Error with Configuration file: {}", msg);
}
}
}
@ -43,7 +44,7 @@ fn main() {
let blog_str = "blog";
// let blog_dir = PathBuf::from(blog_str);
let config: Config = load_config();
let config: Config = load_config("./config.yaml");
let output_dir = PathBuf::from(&config.output_dir);
// absolutely destroy any /public data, so we have a clean slate to write to