Browse Source

Initial commit

Christoph Stelz 1 year ago
commit
d23d8f8e04
4 changed files with 68 additions and 0 deletions
  1. 31 0
      README.md
  2. 9 0
      kiwix.service
  3. 13 0
      stackoverflow.sh
  4. 15 0
      wikipedia.sh

+ 31 - 0
README.md

@@ -0,0 +1,31 @@
+# Kiwix W3M
+
+Access StackOverflow or Wikipedia from the console.
+You can read more about the motivation in my [blog article](https://ch-st.de/offline-first-programming/)
+
+Requirements:
+* `kiwix-tools`
+* `python3`
+* `w3m`
+* [stackoverflow.com_en_all_2022-05.zim](https://download.kiwix.org/zim/stackoverflow.com_en_all.zim.torrent) and [wikipedia_en_all_maxi_2022-05.zim](https://download.kiwix.org/zim/wikipedia_en_all_maxi.zim.torrent)
+
+Serve up your downloaded ZIM files:
+`kiwix-serve -p 8081 ~/Downloads/*.zim`
+
+You can also use the provided systemd service file (`mv kiwix.service ~/.config/systemd/user && systemctl --user daemon-reload && systemctl --user enable --now kiwix.service`).
+
+## Usage
+#### Start page
+`wikipedia.sh`
+
+`stackoverflow.sh`
+
+
+#### Search
+
+`wikipedia.sh kattegat`
+
+`stackoverflow.sh reverse linked list haskell`
+
+Wikipedia articles with article slug:
+`wikipedia.sh --exact 'Haskell_(programming_language)'`

+ 9 - 0
kiwix.service

@@ -0,0 +1,9 @@
+[Unit]
+Description=Serve ZIM files on local network
+
+[Service]
+ExecStart=/bin/bash -c "/usr/bin/kiwix-serve -p 8081 $HOME/Downloads/*.zim"
+Restart=always
+
+[Install]
+WantedBy=default.target

+ 13 - 0
stackoverflow.sh

@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+query="$*"
+zim_file="stackoverflow.com_en_all_2022-05"
+zim_url="http://localhost:8081"
+
+if [[ -z $query ]]; then
+    w3m "$zim_url/$zim_file/questions"
+else
+    urlencoded_query=$(python3 -c "import urllib.parse;print(urllib.parse.urlencode({'pattern': '$query'}))")
+    url="$zim_url/search?content=$zim_file&$urlencoded_query"
+    w3m $url
+fi

+ 15 - 0
wikipedia.sh

@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+query="$*"
+zim_file="wikipedia_en_all_maxi_2022-05"
+zim_url="http://localhost:8081"
+
+if [[ -z $query ]]; then
+    w3m "$zim_url/$zim_file/A/User:The_other_Kiwix_guy/Landing"
+elif [[ "$1" = "--exact" ]]; then
+    w3m "$zim_url/$zim_file/A/$2"
+else
+    urlencoded_query=$(python3 -c "import urllib.parse;print(urllib.parse.urlencode({'pattern': '$query'}))")
+    url="$zim_url/search?content=$zim_file&$urlencoded_query"
+    w3m $url
+fi