summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs12
-rw-r--r--src/stories.rs0
-rw-r--r--src/works/mod.rs12
-rw-r--r--src/works/stories.rs21
-rw-r--r--stories.json10
5 files changed, 54 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 81c2c61..b3e907d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,9 @@
use tera::{Context, Tera};
+use self::works::Work;
+
+mod works;
+
fn main() {
let tera = match Tera::new("templates/**/*.html") {
Ok(t) => t,
@@ -17,4 +21,12 @@ fn main() {
std::fs::write("docs/index.html", output)
.expect("Failed to write rendered output to index.html");
+
+ let mut file = match std::fs::File::open(std::path::PathBuf::from("stories.json")) {
+ Ok(file) => file,
+ Err(err) => panic!("Trying to open stories.json in readmode - {:?}", err),
+ };
+
+ let stories = works::stories::Stories::new_from_file(file);
+ println!("Stories: {:?}", stories);
}
diff --git a/src/stories.rs b/src/stories.rs
deleted file mode 100644
index e69de29..0000000
--- a/src/stories.rs
+++ /dev/null
diff --git a/src/works/mod.rs b/src/works/mod.rs
new file mode 100644
index 0000000..ab7bcf5
--- /dev/null
+++ b/src/works/mod.rs
@@ -0,0 +1,12 @@
+use serde::Deserialize;
+
+pub mod stories;
+
+pub trait Works: for<'a> Deserialize<'a> {
+ fn new_from_file(file: std::fs::File) -> Self {
+ match serde_json::from_reader(std::io::BufReader::new(file)) {
+ Ok(work) => work,
+ Err(err) => panic!("Trying to create work from JSON File - {:?}", err),
+ }
+ }
+}
diff --git a/src/works/stories.rs b/src/works/stories.rs
new file mode 100644
index 0000000..b437fb4
--- /dev/null
+++ b/src/works/stories.rs
@@ -0,0 +1,21 @@
+use serde::Deserialize;
+
+#[derive(Debug, Deserialize)]
+pub struct Stories(pub Vec<Story>);
+
+#[derive(Debug, Deserialize)]
+pub struct Story {
+ pub title: String,
+ pub description: String,
+ pub path_to_document: String,
+ pub slug: String,
+ pub language: Language,
+}
+
+impl super::Works for Stories {}
+
+#[derive(Deserialize, Debug)]
+pub enum Language {
+ German,
+ English,
+}
diff --git a/stories.json b/stories.json
index 0967ef4..6ee46a6 100644
--- a/stories.json
+++ b/stories.json
@@ -1 +1,9 @@
-{}
+[
+ {
+ "title": "Test",
+ "description": "Test",
+ "path_to_document": "Test",
+ "slug": "Test",
+ "language": "German"
+ }
+]