Skip to content
Permalink
Browse files

put pages into directories

  • Loading branch information
winks committed Jan 14, 2020
1 parent 8385884 commit d9dd1a3918d6854c72f02e227b79f0995b5df0b2
Showing with 11 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +0 −1 Cargo.lock
  3. +0 −1 Cargo.toml
  4. +10 −10 src/main.rs
@@ -5,3 +5,4 @@
/public
/theme
/tmp
/config.toml

Some generated files are not rendered by default. Learn more.

@@ -6,7 +6,6 @@ edition = "2018"

[dependencies]
pulldown-cmark = "0.6.1"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5.5"
walkdir = "2"
@@ -1,17 +1,15 @@
extern crate pulldown_cmark;
extern crate regex;
extern crate serde;
extern crate tera;
extern crate walkdir;

use pulldown_cmark::{Parser, html};
use regex::Regex;
use serde::Deserialize;
use tera::{Context, Tera};
use toml::value::Datetime;
use walkdir::WalkDir;

use std::{env, fs};
use std::fs;
use std::path::Path;
use std::io::prelude::*;

@@ -31,6 +29,10 @@ struct FrontMatter {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// @TODO DateFormat
// @TODO RSS
// @TODO Section pages + template
// @TODO index
// config file
let mut config_contents = String::new();
let config_file = fs::File::open("./config.toml");
@@ -166,7 +168,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for sec in &content_sections {
let mut sc = String::from(sec);
sc.push_str("/");
println!("x {} {} {:?}", path.display(), sc, path.starts_with(&sc));
if path.starts_with(&sc) {
sc.replace_range(sc.len()-1.., "_");
sc.push_str(&tpl);
@@ -176,13 +177,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

// @TODO DateFormat
// @TODO RSS

let rv = tera.render(&tpl, &globals)?;
let p1 = pp0.join(path).with_extension("html");
println!("d:f: {}",p1.strip_prefix(pp0).unwrap().display());
let mut ofile = fs::File::create(p1)?;
let pd = pp0.join(path).with_extension("");
let pf = pd.join("index.html");
println!("d:f: {}",pf.strip_prefix(pp0).unwrap().display());
fs::create_dir_all(pd)?;
let mut ofile = fs::File::create(pf)?;
ofile.write_all(&rv.trim().as_bytes())?;
}
Ok(())

0 comments on commit d9dd1a3

Please sign in to comment.
You can’t perform that action at this time.