aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING23
-rw-r--r--readme.md9
-rw-r--r--tools/makefile5
-rw-r--r--tools/src/main.rs45
4 files changed, 78 insertions, 4 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94d171f
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,23 @@
+This project is split in two parts, with a different license.
+
+1. Tools (everything in the `tools` directory)
+
+ metamuffin's blog tools
+ Copyright (C) 2022 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+2. Content (everything in the `content` directory)
+
+ Content is licensed under: Creative Commons Attribution No Derivatives 4.0 International \ No newline at end of file
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..754f043
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,9 @@
+# metamuffin's blog
+
+TODO
+
+## License
+
+- For `tools`: GNU-AGPL-3.0-only
+- For `content`: CC-BY-ND-4.0
+- See `COPYING`
diff --git a/tools/makefile b/tools/makefile
index 15b8a45..5e8d26d 100644
--- a/tools/makefile
+++ b/tools/makefile
@@ -4,7 +4,10 @@ TOOL := ../tools/target/debug/blog-tool
SRC_ARTICLES := $(shell find articles -type f)
OUT_ARTICLES := $(SRC_ARTICLES:articles/%.md=out/%.html)
-all: $(OUT_ARTICLES)
+all: $(OUT_ARTICLES) out/index.html
+
+out/index.html: $(TOOL) $(SRC_ARTICLES)
+ $(TOOL) render-index ./articles > $@
out/%.html: articles/%.md $(TOOL)
mkdir -p out
diff --git a/tools/src/main.rs b/tools/src/main.rs
index 3f3c065..0dc57c0 100644
--- a/tools/src/main.rs
+++ b/tools/src/main.rs
@@ -1,10 +1,11 @@
use std::{
fs::{read_to_string, File},
- io::Write,
+ io::{BufRead, BufReader, Write},
+ path::PathBuf,
};
use clap::{Parser, Subcommand};
-use laby::{html, internal::Buffer, raw, Render};
+use laby::{html, internal::Buffer, iter, li, raw, ul, Render};
use markdown::{Block, Span};
#[derive(Parser)]
@@ -18,6 +19,7 @@ struct Args {
#[derive(Subcommand)]
enum ArgAction {
RenderArticle { input: String },
+ RenderIndex { root: String },
}
fn main() {
@@ -29,6 +31,11 @@ fn main() {
article(md_source).render(&mut out);
write_output(&args.output, out.into_string());
}
+ ArgAction::RenderIndex { root } => {
+ let mut out = Buffer::new();
+ index(root).render(&mut out);
+ write_output(&args.output, out.into_string());
+ }
}
}
@@ -42,7 +49,39 @@ fn write_output(t: &Option<String>, o: String) {
}
fn scaffold(title: String, body: impl Render) -> impl Render {
- html!(head!(title!(title)), body!(body))
+ html!(
+ head!(title!(title)),
+ body!(
+ nav!(h2!("metamuffin's blog"), a!(href = "./index.html", "index")),
+ article!(body)
+ )
+ )
+}
+
+fn index(root: String) -> impl Render {
+ scaffold(
+ "index".to_string(),
+ ul!(iter!(std::fs::read_dir(root)
+ .unwrap()
+ .map(|e| e.unwrap())
+ .map(|e| (
+ e.file_name().to_str().unwrap().to_string(),
+ article_title(e.path())
+ ))
+ .map(|(path, title)| li!(
+ path.as_str()[0..10].to_string(),
+ ": ",
+ a!(href = format!("./{}", path.replace(".md", ".html")), title)
+ )))),
+ )
+}
+
+fn article_title(path: PathBuf) -> String {
+ let f = File::open(path).unwrap();
+ let mut f = BufReader::new(f);
+ let mut buf = String::new();
+ f.read_line(&mut buf).unwrap(); // assume the 1st line has the title
+ String::from(&buf[2..])
}
fn article(md_source: String) -> impl Render {