summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--docs/index.html2
-rw-r--r--docs/stories.html6
-rw-r--r--docs/stories/das_schweigende_spiegelbild.html34
-rw-r--r--docs/stories/mit_gutem_gewissen.html34
-rw-r--r--src/works/stories.rs35
-rw-r--r--stories.json4
-rw-r--r--templates/base.html2
-rw-r--r--templates/stories.html2
-rw-r--r--templates/story.html6
10 files changed, 109 insertions, 17 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9bd7333..733ace4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,3 +11,4 @@ serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
anyhow = "1.0"
chrono = {version = "0.4", features = ["serde"]}
+lopdf = "0.29"
diff --git a/docs/index.html b/docs/index.html
index 3574a1a..c2416a6 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -5,7 +5,7 @@
<title>Home - Vithuran Vishnuthas</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="./style.css">
+ <link rel="stylesheet" href="style.css">
<link rel="icon" href="data:,">
</head>
diff --git a/docs/stories.html b/docs/stories.html
index c0b2c2a..82b938d 100644
--- a/docs/stories.html
+++ b/docs/stories.html
@@ -5,7 +5,7 @@
<title>Stories - Vithuran Vishnuthas</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="./style.css">
+ <link rel="stylesheet" href="style.css">
<link rel="icon" href="data:,">
</head>
@@ -37,7 +37,7 @@ Despite my linguistic difficulties to express myself, my love for story telling
</div>
<div class="works">
- <a href=".&#x2F;stories&#x2F;das_schweigende_spiegelbild.pdf" class="work-card card" download>
+ <a href="./stories/das_schweigende_spiegelbild.html" class="work-card card">
<div class="title-and-description">
<h3>Das schweigende Spiegelbild</h3>
<p>Das Spiegelbild verzweifelt in seiner Hilflosigkeit gegenüber seinem Ich.</p>
@@ -49,7 +49,7 @@ Despite my linguistic difficulties to express myself, my love for story telling
</div>
</a>
- <a href=".&#x2F;stories&#x2F;mit_gutem_gewissen.pdf" class="work-card card" download>
+ <a href="./stories/mit_gutem_gewissen.html" class="work-card card">
<div class="title-and-description">
<h3>Mit gutem Gewissen</h3>
<p>Der gefährliche Zauber von Leon wird von seinem wegweisenden Freund durchschaut. Kann er ihn stoppen?</p>
diff --git a/docs/stories/das_schweigende_spiegelbild.html b/docs/stories/das_schweigende_spiegelbild.html
new file mode 100644
index 0000000..acffb3f
--- /dev/null
+++ b/docs/stories/das_schweigende_spiegelbild.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <title>Das schweigende Spiegelbild - Vithuran Vishnuthas</title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="style.css">
+ <link rel="icon" href="data:,">
+</head>
+
+<body>
+ <header>
+ <u><a href="./index.html"><h1>Writer V2</h1></a></u>
+ Vithuran Vishnuthas
+ </header>
+ <nav>
+ <a href="./index.html">Home</a>
+ <a href="./stories.html">Stories</a>
+ </nav>
+ <main>
+
+ <h2>Das schweigende Spiegelbild</h2>
+ <a href="das_schweigende_spiegelbild.pdf" download>Download PDF</a>
+
+ </main>
+ <footer>
+ Vithuran Vishnuthas &copy; 2022
+ </footer>
+
+
+</body>
+
+</html>
diff --git a/docs/stories/mit_gutem_gewissen.html b/docs/stories/mit_gutem_gewissen.html
new file mode 100644
index 0000000..312f755
--- /dev/null
+++ b/docs/stories/mit_gutem_gewissen.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <title>Mit gutem Gewissen - Vithuran Vishnuthas</title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="style.css">
+ <link rel="icon" href="data:,">
+</head>
+
+<body>
+ <header>
+ <u><a href="./index.html"><h1>Writer V2</h1></a></u>
+ Vithuran Vishnuthas
+ </header>
+ <nav>
+ <a href="./index.html">Home</a>
+ <a href="./stories.html">Stories</a>
+ </nav>
+ <main>
+
+ <h2>Mit gutem Gewissen</h2>
+ <a href="mit_gutem_gewissen.pdf" download>Download PDF</a>
+
+ </main>
+ <footer>
+ Vithuran Vishnuthas &copy; 2022
+ </footer>
+
+
+</body>
+
+</html>
diff --git a/src/works/stories.rs b/src/works/stories.rs
index c68745a..ccc01e0 100644
--- a/src/works/stories.rs
+++ b/src/works/stories.rs
@@ -5,26 +5,43 @@ use serde::{Deserialize, Serialize};
// derive from JSON
// process to context for HTML
#[derive(Debug, Deserialize, Serialize)]
-pub struct Stories(pub Vec<Story>);
+pub struct Stories(Vec<Story>);
#[derive(Debug, Deserialize, Serialize)]
-pub struct Story {
- pub title: String,
- pub description: String,
- pub path_to_document: String,
- pub number_of_pages: u16,
- pub language: Language,
- pub last_update: NaiveDate,
+struct Story {
+ title: String,
+ description: String,
+ path_to_document: String,
+ number_of_pages: u16,
+ language: Language,
+ last_update: NaiveDate,
}
// see src/works/mod.rs for information of Works trait
impl super::Works for Stories {
+ // render single pages for every story with the extracted text and a download button
fn render_single_pages(
&self,
tera_instance: &tera::Tera,
template_name: &str,
) -> anyhow::Result<()> {
- !unimplemented!()
+ // TODO: Extract story pdf text
+ let mut result = Vec::new();
+ for story in self.0.iter() {
+ let mut context = tera::Context::new();
+ context.insert("story", story);
+ result.push(std::fs::write(
+ format!(
+ // use story document name for the single page
+ // e.g. mit_gutem_gewissen.pdf -> mit_gutem_gewissen.html
+ "docs/stories/{}.html",
+ story.path_to_document.replace(".pdf", "")
+ )
+ .as_str(),
+ tera_instance.render(format!("{}.html", template_name).as_str(), &context)?,
+ ));
+ }
+ Ok(())
}
}
diff --git a/stories.json b/stories.json
index 5b88987..b40342a 100644
--- a/stories.json
+++ b/stories.json
@@ -2,7 +2,7 @@
{
"title": "Mit gutem Gewissen",
"description": "Der gefährliche Zauber von Leon wird von seinem wegweisenden Freund durchschaut. Kann er ihn stoppen?",
- "path_to_document": "./stories/mit_gutem_gewissen.pdf",
+ "path_to_document": "mit_gutem_gewissen.pdf",
"number_of_pages": 7,
"language": "German",
"last_update": "2023-01-28"
@@ -10,7 +10,7 @@
{
"title": "Das schweigende Spiegelbild",
"description": "Das Spiegelbild verzweifelt in seiner Hilflosigkeit gegenüber seinem Ich.",
- "path_to_document": "./stories/das_schweigende_spiegelbild.pdf",
+ "path_to_document": "das_schweigende_spiegelbild.pdf",
"number_of_pages": 2,
"language": "German",
"last_update": "2023-01-28"
diff --git a/templates/base.html b/templates/base.html
index 43117c3..ea8e04f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -5,7 +5,7 @@
<title>{% block title %}{% endblock title %} - Vithuran Vishnuthas</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="./style.css">
+ <link rel="stylesheet" href="style.css">
<link rel="icon" href="data:,">
</head>
diff --git a/templates/stories.html b/templates/stories.html
index 07ebb40..a9efdb3 100644
--- a/templates/stories.html
+++ b/templates/stories.html
@@ -18,7 +18,7 @@ Despite my linguistic difficulties to express myself, my love for story telling
</div>
<div class="works">
{% for work in works | sort(attribute="last_update") | reverse %}
- <a href="{{work.path_to_document}}" class="work-card card" download>
+ <a href="./stories/{{work.path_to_document | replace(from='pdf', to='html')}}" class="work-card card">
<div class="title-and-description">
<h3>{{work.title}}</h3>
<p>{{work.description}}</p>
diff --git a/templates/story.html b/templates/story.html
new file mode 100644
index 0000000..0314629
--- /dev/null
+++ b/templates/story.html
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+{% block title %}{{story.title}}{% endblock title %}
+{% block content %}
+ <h2>{{story.title}}</h2>
+ <a href="{{story.path_to_document}}" download>Download PDF</a>
+{% endblock content %}