String>);
impl Virtual {
pub fn new(path: P, call: F) -> Self
where
P: AsRef,
- F: Fn(&[&Asset]) -> String + 'static
+ F: Fn(&Everything) -> String + 'static
{
Self(path.as_ref().into(), Box::new(call))
}
@@ -58,16 +59,18 @@ pub fn render(items: &[Item]) {
})
.collect();
+ let everything = Everything { assets: &assets };
+
for item in items {
match item {
- Item::Real(real) => render_real(real, &assets),
- Item::Fake(fake) => render_fake(fake, &assets),
+ Item::Real(real) => render_real(real, &everything),
+ Item::Fake(fake) => render_fake(fake, &everything),
}
}
}
-fn render_real(item: &Asset, assets: &[&Asset]) {
+fn render_real(item: &Asset, assets: &Everything) {
match &item.kind {
AssetKind::Html(render) => {
let i = &item.meta.path;
@@ -98,7 +101,7 @@ fn render_real(item: &Asset, assets: &[&Asset]) {
}
}
-fn render_fake(item: &Virtual, assets: &[&Asset]) {
+fn render_fake(item: &Virtual, assets: &Everything) {
let Virtual(out, render) = item;
let o = Path::new("dist").join(&out);
diff --git a/src/html/base.rs b/src/html/base.rs
index b3742a1..8fc94e6 100644
--- a/src/html/base.rs
+++ b/src/html/base.rs
@@ -5,6 +5,8 @@ use crate::REPO;
pub fn head(title: &str) -> impl Renderable + '_ {
+ let title = format!("{} | kamoshi.org", title);
+
maud_move!(
meta charset="utf-8";
meta name="viewport" content="width=device-width, initial-scale=1";
@@ -81,8 +83,7 @@ pub fn navbar() -> impl Renderable {
}
pub fn footer() -> impl Renderable {
- let year = chrono::Utc::now().year();
- let copy = format!("Copyright © {} Maciej Jur", year);
+ let copy = format!("Copyright © {} Maciej Jur", &REPO.year);
let mail = "maciej@kamoshi.org";
let href = format!("mailto:{}", mail);
let repo = format!("{}/tree/{}", &REPO.link, &REPO.hash);
@@ -97,8 +98,13 @@ pub fn footer() -> impl Renderable {
(mail)
}
}
- a href=(repo) {
- "view source"
+ div .repo {
+ a href=(repo) {
+ (&REPO.hash)
+ }
+ div {
+ (&REPO.date)
+ }
}
a .right.footer__cc-wrap rel="license" href="http://creativecommons.org/licenses/by/4.0/" {
img .footer__cc-stamp alt="Creative Commons License" width="88" height="31" src="/static/svg/by.svg";
diff --git a/src/main.rs b/src/main.rs
index 5ccdf58..e7cfdb2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,7 @@
use std::process::Command;
use std::{collections::HashMap, path::Path};
use std::fs;
-use chrono::Datelike;
+use chrono::{Datelike, Utc};
use grass;
use html::LinkableData;
use hypertext::{Raw, Renderable};
@@ -15,26 +15,49 @@ mod utils;
#[derive(Debug)]
-struct RepoInfo {
+struct BuildInfo {
+ pub year: i32,
+ pub date: String,
pub link: String,
pub hash: String,
}
-static REPO: Lazy = Lazy::new(|| RepoInfo {
- link: "https://github.com/kamoshi/kamoshi.org".into(),
- hash: String::from_utf8(
- Command::new("git")
- .args(["rev-parse", "HEAD"])
- .output()
+static REPO: Lazy = Lazy::new(|| {
+ let time = chrono::Utc::now();
+
+ BuildInfo {
+ year: time.year(),
+ date: time.format("%Y/%m/%d %H:%M").to_string(),
+ link: "https://github.com/kamoshi/kamoshi.org".into(),
+ hash: String::from_utf8(
+ Command::new("git")
+ .args(["rev-parse", "--short", "HEAD"])
+ .output()
+ .unwrap()
+ .stdout
+ )
.unwrap()
- .stdout
- )
- .unwrap()
- .trim()
- .into()
+ .trim()
+ .into()
+ }
});
+/// This struct allows for querying the website hierarchy
+struct Everything<'a> {
+ assets: &'a [&'a gen::Asset],
+}
+
+impl Everything<'_> {
+ fn get_linkable(&self, path: &str) -> Vec {
+ let pattern = glob::Pattern::new(path).unwrap();
+ self.assets.iter()
+ .filter(|f| pattern.matches_path(&f.out))
+ .filter_map(|f| f.link.clone())
+ .collect()
+ }
+}
+
trait Transformable {
fn transform<'f, 'm, 'html, T>(&'f self, content: T) -> impl Renderable + 'html
@@ -157,15 +180,7 @@ fn transform(meta: gen::Source) -> gen::Asset
let (fm, md) = md::preflight::(&data);
let link = T::as_link(&fm, Path::new("/").join(&loc).to_str().unwrap().to_owned());
- let call = move |assets: &[&gen::Asset]| {
- // let lib = assets.iter().filter_map(|&a| match &a.kind {
- // gen::AssetKind::Bib(lib) => Some(lib),
- // _ => None,
- // }).next();
- //
- // println!("{:?}", lib);
-
-
+ let call = move |_: &Everything| {
let data = T::render(&md);
let data = T::transform(&fm, Raw(data)).render().into();
data
@@ -217,8 +232,6 @@ fn transform(meta: gen::Source) -> gen::Asset
}
fn main() {
- println!("{:?}", &*REPO);
-
if fs::metadata("dist").is_ok() {
println!("Cleaning dist");
fs::remove_dir_all("dist").unwrap();
@@ -245,22 +258,12 @@ fn main() {
path: "content/index.md".into()
}
}.into(),
- gen::Virtual("posts/index.html".into(), Box::new(|assets| {
- let pattern = glob::Pattern::new("posts/**/*.html").unwrap();
- let posts = assets.iter()
- .filter(|f| pattern.matches_path(&f.out))
- .filter_map(|f| f.link.clone())
- .collect();
- to_list(posts)
- })).into(),
- gen::Virtual("slides/index.html".into(), Box::new(|assets| {
- let pattern = glob::Pattern::new("slides/**/*.html").unwrap();
- let posts = assets.iter()
- .filter(|f| pattern.matches_path(&f.out))
- .filter_map(|f| f.link.clone())
- .collect();
- to_list(posts)
- })).into(),
+ gen::Virtual("posts/index.html".into(), Box::new(|all|
+ to_list(all.get_linkable("posts/**/*.html"))
+ )).into(),
+ gen::Virtual("slides/index.html".into(), Box::new(|all|
+ to_list(all.get_linkable("slides/**/*.html"))
+ )).into(),
],
gen::gather("content/about.md", &["md"].into())
.into_iter()
diff --git a/src/md/render.rs b/src/md/render.rs
index e9d636a..9875340 100644
--- a/src/md/render.rs
+++ b/src/md/render.rs
@@ -75,5 +75,3 @@ pub fn render(raw: &str) -> String {
String::from_utf8(html).unwrap()
}
-
-
diff --git a/styles/partials/_footer.scss b/styles/partials/_footer.scss
index 94f04d7..f7c8092 100644
--- a/styles/partials/_footer.scss
+++ b/styles/partials/_footer.scss
@@ -3,6 +3,7 @@
grid-template-columns: 1fr auto 1fr;
grid-column-gap: 0.25em;
justify-items: center;
+ align-items: center;
max-height: min-content;
padding: 0.5em;
@@ -18,6 +19,12 @@
margin-right: auto;
}
+ .repo {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ }
+
.right {
margin-left: auto;
}