From b31b6ff2ab5d94e5b6280ba3cb4db7d46267999a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 29 Sep 2022 16:06:55 +0200 Subject: docs --- COPYING | 15 +++++++++++++++ Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- readme.md | 25 +++++++++++++++++++++++++ src/main.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 COPYING create mode 100644 readme.md diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..24d963a --- /dev/null +++ b/COPYING @@ -0,0 +1,15 @@ +staticwiki - renders MediaWiki XML dumps to html +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 . diff --git a/Cargo.lock b/Cargo.lock index 5c578d1..a091df4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,6 +324,17 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "staticwiki" +version = "0.1.0" +dependencies = [ + "bzip2", + "clap", + "parse_mediawiki_dump", + "parse_wiki_text", + "tar", +] + [[package]] name = "strsim" version = "0.10.0" @@ -391,17 +402,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "wikiviewer" -version = "0.1.0" -dependencies = [ - "bzip2", - "clap", - "parse_mediawiki_dump", - "parse_wiki_text", - "tar", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 9e50d9f..137128e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wikiviewer" +name = "staticwiki" version = "0.1.0" edition = "2021" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..9aa43e5 --- /dev/null +++ b/readme.md @@ -0,0 +1,25 @@ +# staticwiki + +Yet another low-effort tool for rendering MediaWiki XML dumps to static html +pages. + +## Features + +- partial wikitext support +- can accept bzip2 compressed streams. +- can output tar stream (could be piped to mksquashfs to recompress without + writing to disk) +- horribly bad code :) + +## Usage + +- clone repo +- obtain rustc (tested with nightly) +- `cargo install --path .` +- Get help: `staticwiki --help` +- Convert to squashfs: + `staticwiki --bzip2 --tar < dump.xml.bz2 | mksquashfs - wiki.sfs -tar -comp zstd` + +## License + +`AGPL-3.0-only` diff --git a/src/main.rs b/src/main.rs index 6af1908..e8c0375 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,8 @@ struct Args { /// Show non-fatal warnings #[arg(short, long)] verbose: bool, + #[arg(short, long, default_value = "")] + footer: String, } fn main() { @@ -34,6 +36,11 @@ fn main() { let input = std::io::BufReader::new(input); let mut archive = tar::Builder::new(stdout()); + let footer = format!( + "staticwiki; {}", + args.footer + ); + for (i, result) in parse_mediawiki_dump::parse(input).enumerate() { match result { Err(error) => { @@ -67,6 +74,7 @@ fn main() { render_toc(&mut html, &ast.nodes); render_nodes(&mut html, &mut refs, &ast.nodes); render_refs(&mut html, &refs); + write!(&mut html, "
{footer}
").unwrap(); write!(&mut html, "").unwrap(); if args.tar { @@ -257,33 +265,56 @@ pub fn render_template( use std::fmt::Write; match name { // TODO this can panic - "lang" => write!(html, "{}", render_nodes_to_string(¶ms[1].value, refs)).unwrap(), + "lang" => write!( + html, + "{}", + render_nodes_to_string(¶ms.get(1)?.value, refs) + ) + .unwrap(), "IPA" => write!( html, "{}", - render_nodes_to_string(¶ms[0].value, refs) + render_nodes_to_string(¶ms.get(0)?.value, refs) ) .unwrap(), "Internetquelle" | "Literatur" => { write!(html, "{}: ").unwrap(); } + "Siehe auch" | "Hauptartikel" => { + let k = text_node(params.get(0)?.value.get(0)?); + write!( + html, + "{}: {}", + escape(name), + urlencode(&k), + escape(&k) + ) + .unwrap(); + } _ => { - write!(html, "[todo: {name:?} template
{params:#?}
]").unwrap(); + write!(html, "[todo: {name:?} template]").unwrap(); + // write!(html, "[todo: {name:?} template
{params:#?}
]").unwrap(); // eprintln!("unsupported template {name:?}"); // eprintln!("{params:?}"); } -- cgit v1.2.3-70-g09d2