Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Hot-wiring the Lisp machine (scheatkode.com)
47 points by spudlyo 1 day ago | hide | past | favorite | 8 comments
 help



> "I'll just read a file, swap out some variables, and write some HTML." – Famous last words

I'm actually living the dream. The key: directly author html. I.e. the above file contains html.

https://git.sr.ht/~akkartik/gen_site


Cool! Also, carrying forward the post author's tongue-in-cheek humour... I see your lua and raise you ~350 lines of Bash (excludes HTML templates). Take a good hard look at this shite [0]. Have you seen anything that is more obviously HTML-about-to-be-expanded-into-a-full-page?

    shite_template_standard_page_wrapper() {
        cat <<EOF
    <!DOCTYPE html>
    <html lang="en" prefix="og: https://ogp.me/ns#">
      $(shite_template_common_head)
      <body>
        <div id="the-very-top" class="stack center box">
          $(cat -)
          $(shite_template_common_footer)
        </div>
      </body>
    </html>
    EOF
    }
And, unlike PHP or whatever... have you ever seen more composable templating, as in functional programming?

    cat ./sample/hello.html |
      shite_template_common_default_page

    # Or..

    cat ./sample/hello.org |
      pandoc -f org -t html |
      shite_template_common_default_page
Just imagine all the pipelined pre/post-processor possibilities.

[0] project codename `shite`, literally, renders my site https://github.com/adityaathalye/shite


How about one line of POSIX sh with cpp? Though it uses the different approach of SSI instead of templating:

  $ cat <<EOF | sed -E 's/^[\t ]*<!--(#.*)-->$/\1/; t; s/^/\a/' | cpp -traditional -nostdinc -P -C | sed -E 's/^\a//'
  <!DOCTYPE html>
  <html>
    <head><title>My site</title></head>
    <body>
      <!--#include "navbar.inc.html"-->
      <p>Foo</p>
    </body>
  </html>
  EOF
  <!DOCTYPE html>
  <html>
    <head><title>My site</title></head>
    <body>
  <header>
    <a href="/">My cool site</a>
    <nav>
      <ul>
        <li><a href="/blog.html">Blog</a></li>
        <li><a href="/about.html">About</a></li>
      </ul>
    </nav>
  </header>
      <p>Foo</p>
    </body>
  </html>
With a little elbow grease, you even get incremental rebuild: https://git.sr.ht/~q3cpma/html-cpp

That is... a cool trick! I don't know C, so it would have never occurred to me. (Let's be honest; it would have not occurred to me even if I knew C :))

What I like about the Bash + Heredocs + substitutions approach is that it looks and feels declarative to me. Template "expansion" is just in-place substitutions (parameter expansion, shell substitution, process substitution); no string munging needed to "place" or "inject" content in the HTML tree.

Anyway, I spent way too much time figuring that out, and it works well for me, so I'm going to just roll with the sunk costs :D

Thanks for sharing your approach!



  > Within that machine lies Org-mode.
  > ...
  > Absolute maniacs run their finances, their spreadsheets, 
  > and their fragile grip on reality out of it.
I feel seen... who else is with me?

Also...

  > I have to address the elephant in the room: 
  > hot-rebuilding isn't true hot-reloading. 
  > To get the browser to magically inject CSS without 
  > a refresh requires WebSockets, background Node
  > processes, and a lot of external baggage.
OR... you could just use inotify again... Behold this abomination (that works so well (on my machine) I can't believe it):

  __shite_hot_cmd_browser_refresh() {
      local window_id=${1:?"Fail. We expect window ID to be set in scope."}
  
      printf "%s\n" \
             "key --window ${window_id} --clearmodifiers 'F5'"
  }
  
  __shite_hot_cmd_goto_url() {
      local window_id=${1}
      local url=${2}
  
      printf "%s\n" \
             "key --window ${window_id} --clearmodifiers 'ctrl+l'" \
             "type --window ${window_id} --clearmodifiers --delay 1 ${url}" \
             "key --window ${window_id} --clearmodifiers 'Return'"
  }
... and a few functions later ...

  __shite_hot_cmd_exec() {
      # In debug mode, only show the actions, don't do them.
      if [[ ${SHITE_BUILD} == "hot" ]]
      then stdbuf -oL grep -v '^$' | __tap_stream | xdotool -
      else cat -
      fi
  }
  
  shite_hot_browser_reload() {
      local browser_window_id=${1:?"Fail. Window ID not set."}
      local base_url=${base_url:?"Fail. Base URL not set."}
      __shite_hot_cmd_public_events ${browser_window_id} ${base_url} |
          __shite_hot_cmd_exec
  }
... and finally ...

    # RUN PIPELINE
    shite_hot_watch_file_events ${watch_dir} |
        __shite_events_dedupe |
        __tap_stream |
        tee >(shite_hot_build ${base_url}) |
        # Perform hot-reload actions only against changes to public files
        tee >(shite_hot_browser_reload ${window_id} ${base_url})

I really enjoyed reading this, the descent into madness sure did make for a fun ride. Lisp + rabbit holes gotta be one of my favourite literary genres. :D



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: