Paste: board.cgi

Author: Ristretto
Mode: factor
Date: Thu, 12 Feb 2026 16:42:28
Plain Text |
#!/usr/bin/env cgi-factor
USING: assocs environment formatting io kernel sequences
splitting xml xml.syntax xml.writer multiline ;
IN: board-cgi

: parse-cgi ( string -- assoc )
   "&" split [ "=" split ] map ;

: ?thread ( -- thread/f )
   "QUERY_STRING" os-env parse-cgi "thread" of ;

: ?board ( -- board/f )
   "QUERY_STRING" os-env parse-cgi "board" of ;

: favi-safe-comet ( src container -- )
! "Avoiding Javascript, by using even more Javascript!"
   [[
   <script> window.addEventListener('load', () => {
   const iframe = document.createElement('iframe');
   iframe.src = '%s'; 
   iframe.style.width = '100%%'; iframe.style.height = '100%%'; 
   document.getElementById('%s').appendChild(iframe); 
   }); </script> 
   ]] printf ;

:: view-thread ( thread reply -- )
   <XML 
   <body id="board"><div id="main">
   <div id="thread-wrapper">
      <noscript>
      <iframe id="thread-frame" src=<-thread-> width="100%" ></iframe>
      </noscript>
   </div> 
   <div id="reply-wrapper">
      <noscript>
      <iframe id="reply-frame" src=<-reply-> width="100%" ></iframe>
      </noscript>
   </div> <!--
      <img id="qt-image" src="/static/qt.png" alt="An Orange Heart" 
         width="300px" height="auto"/> -->
   </div></body> XML> pprint-xml
   thread "thread-wrapper" favi-safe-comet 
     reply "reply-wrapper" favi-safe-comet ;

: html-head ( -- xml )
   <XML <head>  
      <link rel="stylesheet" href="/static/style.css"/>
   </head> XML> ;

: board-index ( -- )
   <XML <div class="board-index">
      <p><a href="/cgi-bin/board.cgi?board=roman">/roman/</a> - Romance Works</p>
      <p><a href="/cgi-bin/board.cgi?board=meta">/meta/</a> - Site Discussion</p>
   </div> XML> pprint-xml ;

: board-return ( -- )
   ?board "/cgi-bin/board.cgi?board=" prepend
   <XML <a href=<-> class="return">
      Return?
   </a> XML> pprint-xml ;

: index-return ( -- )
   <XML <a href="/cgi-bin/board.cgi" class="return">
     Return to Index
   </a> XML> pprint-xml ;

! == Script:
   "Content-type: text/html; charset=utf8\r\n"
print
   html-head pprint-xml
?board
   [ "thread.cgi" "reply.cgi"
     [ "/cgi-bin/" "QUERY_STRING" os-env "?" prepend surround ]
     bi@ view-thread
   ] [ board-index ] if
?thread
   [ board-return ] [ index-return ] if

New Annotation

Summary:
Author:
Mode:
Body: