67381f122e37be5968f7710c97b54f73d2fbed59 — Phil Hagelberg 8 months ago a8fee51
Add wiki script that just redirects to github.
5 files changed, 85 insertions(+), 0 deletions(-)

A wiki/.gitignore
A wiki/.htaccess
A wiki/404.html
A wiki/Makefile
A wiki/index.fnl
A wiki/.gitignore => wiki/.gitignore +1 -0
@@ 0,0 1,1 @@

A wiki/.htaccess => wiki/.htaccess +10 -0
@@ 0,0 1,10 @@
Options +ExecCGI
php_flag engine off

Header set Strict-Transport-Security "max-age=31536000"
Header set X-Frame-Options "DENY"
Header set X-XSS-Protection "1; mode=block"

RewriteRule "^([A-Za-z]*)$" "/index.cgi?page=$1"

ErrorDocument 404 /404.html

A wiki/404.html => wiki/404.html +15 -0
@@ 0,0 1,15 @@
<html lang="en">
    <meta charset="utf-8" />
    <link href="https://fennel-lang.org/fennel.css" rel="stylesheet">
    <link href="https://code.cdn.mozilla.net/fonts/fira.css" rel="stylesheet">
    <title>Fennel wiki: 404</title>
    <h1>Not Found</h1>
    <p>Whatever you're looking for, it's not here. Unless you're
      looking for the 404 error page. If that's what you want,
      congratulations. You found it.</p>

A wiki/Makefile => wiki/Makefile +9 -0
@@ 0,0 1,9 @@
index.cgi: index.fnl
	echo "#!/usr/bin/env lua" > $@
	../fennel/fennel --compile $< >> $@
	chmod 755 index.cgi

# this isn't tied into CI at this point since it changes so rarely; just
# do a manual upload when needed.
upload: index.cgi .htaccess 404.html
	rsync -rAv $^ fenneler@fennel-lang.org:wiki.fennel-lang.org/

A wiki/index.fnl => wiki/index.fnl +50 -0
@@ 0,0 1,50 @@
;; we don't have a great solution for the wiki right now; currently it's still
;; left on github because sourcehut doesn't let you grant write access to their
;; wikis. for now we can just proxy the content from github and allow edits
;; to be done over git+SSH.

(local head
       "<!DOCTYPE html>
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"\" xml:lang=\"\">
  <meta charset=\"utf-8\" />
  <link rel=\"stylesheet\" href=\"https://fennel-lang.org/fennel.css\"></link>
  <link rel=\"stylesheet\" href=\"https://code.cdn.mozilla.net/fonts/fira.css\"/>
  <title>Fennel wiki: %s</title>

(local foot
       "<hr />
  <p>To edit this wiki, clone the repo from
  <tt>git@github.com:bakpakin/Fennel.wiki.git</tt> and push your
  changes there.</p>

(fn url-for [page]
  (let [url (.. "https://github.com/bakpakin/Fennel/wiki/" page)]
    ;; we REALLY don't want to let arbitrary input thru here when we shell out
    (assert (not (page:match "[ %.]")) "Illegal page; can't shell out to curl!")

(fn get-body [page]
  (let [curl (assert (io.popen (.. "curl --silent " (url-for page))))
        body (curl:read :*all)]
    (assert (curl:close))

(fn query-string []
  (or (: (or (os.getenv "QUERY_STRING") "") :match "page=([-a-zA-Z]+)") ""))

(let [page (match (query-string) "" "Home" p p)
      body (get-body (query-string))
      out [(head:format page)
           (string.format "<h1>Fennel wiki: %s</h1>" page)
           ;; this leaves a ton of unmatched closing divs but who cares
           (body:match "<div id=\"wiki%-body\".*</turbo%-frame>")
  (print "content-encoding: utf8")
  (print "content-type: text/html")
  (print "")
  (print (table.concat out "\n")))