commit aab7616ebf653aa476dca645075d2d88531158a6 Author: Alina Marquardt Date: Sun Apr 9 01:15:51 2023 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2b2c70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +# Project specific + +/pub + + +# Created by https://www.toptal.com/developers/gitignore/api/rust,nova,macos,sass +# Edit at https://www.toptal.com/developers/gitignore?templates=rust,nova,macos,sass + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### nova ### +.nova/* + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +### Sass ### +.sass-cache/ +*.css.map +*.sass.map +*.scss.map + +# End of https://www.toptal.com/developers/gitignore/api/rust,nova,macos,sass diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9056cb9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lf-builder" +version = "0.1.0" +edition = "2021" +authors = [ "Alina Marquardt" ] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +chrono = "0.4.24" diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c39ec5 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# lastfuture.de static page generator + +Static page generator for lastfuture.de, written in Rust + +## Features +- generates static HTML pages in Rust + +## Planned features +- Templating using Mustache +- SCSS preprocessing +- TypeScript preprocessing +- Minification +- Deploy script diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5d590b4 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,46 @@ +use std::fs::File; +use std::io::{Write, BufReader, BufRead, Error}; +use chrono; +use std::time::Instant; + +const PUBLISH_PATH: &str = "./pub/"; +const TEMPLATE_PATH: &str = "./src/templates/"; + +fn render_html(file: &str, template: &str, data: Vec) -> Result<(), Error> { + let output_path = &format!("{}{}", PUBLISH_PATH, file); + let template_path = &format!("{}{}", TEMPLATE_PATH, template); + + let now = Instant::now(); + // TODO: Templating with template and data + let html_string = "

Hello!

"; + let elapsed = now.elapsed(); + + let mut output_file = File::create(output_path)?; + write!(output_file, +"{}\n +", + html_string, + template, + chrono::offset::Local::now(), + elapsed + )?; + + let input = File::open(output_path)?; + let buffered = BufReader::new(input); + + for line in buffered.lines() { + println!("{}", line?); + } + + Ok(()) +} + +fn main() { + + render_html("index.html", "index.tmpl", vec![1, 2, 3]); + +}