aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING15
-rw-r--r--Cargo.lock22
-rw-r--r--Cargo.toml2
-rw-r--r--readme.md25
-rw-r--r--src/main.rs57
5 files changed, 96 insertions, 25 deletions
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 <https://www.gnu.org/licenses/>.
diff --git a/Cargo.lock b/Cargo.lock
index 5c578d1..a091df4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -325,6 +325,17 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -392,17 +403,6 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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!(
+ "<a href=\"https://codeberg.org/metamuffin/staticwiki\">staticwiki</a>; {}",
+ 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>{footer}</footer>").unwrap();
write!(&mut html, "</body></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(&params[1].value, refs)).unwrap(),
+ "lang" => write!(
+ html,
+ "{}",
+ render_nodes_to_string(&params.get(1)?.value, refs)
+ )
+ .unwrap(),
"IPA" => write!(
html,
"<code>{}</code>",
- render_nodes_to_string(&params[0].value, refs)
+ render_nodes_to_string(&params.get(0)?.value, refs)
)
.unwrap(),
"Internetquelle" | "Literatur" => {
write!(html, "{}: <ul>", escape(name)).unwrap();
for p in params {
- write!(
- html,
- "<li>{}: {}</li>",
- p.name
- .as_ref()
- .map(|n| render_nodes_to_string(n, &mut vec![]))
- .unwrap_or(String::from("??")),
- render_nodes_to_string(&p.value, &mut vec![])
- )
- .unwrap();
+ let key = p
+ .name
+ .as_ref()
+ .map(|n| render_nodes_to_string(n, &mut vec![]))
+ .unwrap_or(String::from("??"));
+ let value = render_nodes_to_string(&p.value, &mut vec![]);
+ if let "url" | "archiv-url" | "Online" = key.as_str() {
+ write!(
+ html,
+ "<li>{}: <a href=\"{}\">{}</a></li>",
+ key, value, value
+ )
+ } else {
+ write!(html, "<li>{}: {}</li>", key, value)
+ }
+ .unwrap()
}
write!(html, "</ul>").unwrap();
}
+ "Siehe auch" | "Hauptartikel" => {
+ let k = text_node(params.get(0)?.value.get(0)?);
+ write!(
+ html,
+ "<i>{}: <a href=\"{}\">{}</a></i>",
+ escape(name),
+ urlencode(&k),
+ escape(&k)
+ )
+ .unwrap();
+ }
_ => {
- write!(html, "[todo: {name:?} template <pre>{params:#?}</pre>]").unwrap();
+ write!(html, "[todo: {name:?} template]").unwrap();
+ // write!(html, "[todo: {name:?} template <pre>{params:#?}</pre>]").unwrap();
// eprintln!("unsupported template {name:?}");
// eprintln!("{params:?}");
}