struct file cleanups

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

2
src/blog/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod structs;
pub use structs::{BlogConfig};

6
src/blog/structs.rs Normal file
View File

@ -0,0 +1,6 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct BlogConfig {
source: String,
}

View File

@ -1,56 +1,12 @@
use serde::{Serialize, Deserialize}; pub mod structs;
pub use structs::{LinksConfig, RustyLinks, MetaData};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde_yaml::{self}; use serde_yaml::{self};
use minijinja::Environment; use minijinja::Environment;
use std::path::PathBuf; use std::path::PathBuf;
use crate::file_utils::{write_file, copy_recursively}; use crate::file_utils::{write_file, copy_recursively};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct LinksConfig {
pub source: String,
pub template: String,
pub static_dir: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct RustyLinks {
config: Config,
links: Vec<Links>,
pub metadata: Option<MetaData>,
}
#[derive(Serialize, Deserialize, Debug)]
struct MetaData {
pub last_updated: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct Config {
title: String,
name: String,
description: String,
avatar: String,
background: String,
background_opacity: f64,
}
#[derive(Serialize, Deserialize, Debug)]
struct Links {
title: String,
links: Vec<Link>,
}
#[derive(Serialize, Deserialize, Debug)]
struct Link {
text: String,
icon: String,
href: Option<String>,
copy: Option<String>,
rels: Option<String>,
}
fn load_links(config: &LinksConfig) -> RustyLinks { fn load_links(config: &LinksConfig) -> RustyLinks {
let links_yaml = std::fs::File::open(&config.source).expect(&format!("Could not find {}", config.source)); let links_yaml = std::fs::File::open(&config.source).expect(&format!("Could not find {}", config.source));

45
src/links/structs.rs Normal file
View File

@ -0,0 +1,45 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Links {
title: String,
links: Vec<Link>,
}
#[derive(Serialize, Deserialize, Debug)]
struct Link {
text: String,
icon: String,
href: Option<String>,
copy: Option<String>,
rels: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct LinksConfig {
pub source: String,
pub template: String,
pub static_dir: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct RustyLinks {
config: Config,
links: Vec<Links>,
pub metadata: Option<MetaData>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MetaData {
pub last_updated: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct Config {
title: String,
name: String,
description: String,
avatar: String,
background: String,
background_opacity: f64,
}

View File

@ -1,16 +1,13 @@
mod links; mod links;
mod file_utils; mod file_utils;
mod blog;
use crate::links::{LinksConfig, create_links}; use crate::links::{LinksConfig, create_links};
use crate::blog::{BlogConfig};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct BlogConfig {
source: String,
}
#[derive(Serialize, Deserialize, Debug, Default)] #[derive(Serialize, Deserialize, Debug, Default)]
pub struct Config { pub struct Config {
output_dir: String, output_dir: String,