Hacker News new | ask | show | jobs
by telesoft 1454 days ago
Cool project. I'm currently building something similar to hacker news using only the standard library. How could this project help me?

The way I use the standard library is like a super condensed version of React. Templates are my components. Since templates can be nested, templates can be used to build "components" and those components can be stored in separate files and compiled together at run time with a "model" being fed to the template(s) via a state object passed by the application.

So I may have a few dozen template files in a folder called /components, and another folder called /pages with a few templates that use these components. When a user visits a "page", the template file is "compiled" with the appropriate components.

A page might look like this:

  <html>
    {{template "nav"}}
    {{template "thread" .Thread}}
    {{template "footer"}}
  </html>
And "nav", "thread", and "footer" are all components defined in another file. This allows for re-use across multiple pages.

I want to do a write-up on it but I'm not sure if it's a novel idea.

3 comments

Oh that's fun! In my demo video [1], I build a (minimal) HN clone so hopefully that answers your question in detail.

But the tldr is - you'll need a lot more than just templating for a production ready app. To name a few things - server, storage, migrations, logging, configs. IMO there's a huge benefit in having a batteries included toolkit that stays close to the stdlib - so you can totally keep your templates as is!

[1] https://vimeo.com/723537998

In what sense is this like React? Incremental re-rendering using html/template or text/template was virtually impossible last time I looked into it (for improving performance of some report generation), let alone getting any kind of DOM tree structure out.
Sounds like old school server-side rendering techniques to me: php, coldfusion, classic ASP
You didn't even need a language, plain old shtml in Apache could do SSI from static includes. Classic.