TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Using sed/awk to bulk generate static HTML pages off of a template

1 pointsby arunnandaalmost 3 years ago
Hypothetically, consider a social photo platform - each pic gets its own url, this page contains the image, text about the image, buttons for the user to click, related pics, and some user-specific elements (maybe notifications, etc.).<p>There are different ways of going about the frontend. In each case, elements specific to the logged-in-user and the related images get fetched via api calls and are rendered client side.<p>For rendering the rest of the page -<p>1. Everything is rendered client side - one can use a single page application to handle the routing. The page structure stays the same, and new image uri&#x27;s and the associated content are fetched via api calls.<p>SEO is a priority, so pure client side rendering is suboptimal.<p>2. Server side rendering for each page with NextJS or even Express is another option.<p>3. Another way is to do a static export in something like NextJS - which will generate separate html files for each image.<p>4. Now my thought is to skip all of that and go old school with sed&#x2F;awk. We&#x27;ll have a template file with all the styling elements and placeholders for the image uri and its description, etc. Then a script iterates through a list of values (queried from a database) specific to each image (img source URIs, description text, etc.) and uses sed to replace the placeholders in the template file and output a separate html file.<p>Each file has the same javascript to load the user-specific components.<p>Every time someone adds a new image, the script runs with the uri of the image and the description, etc. as the variables passed to it, and adds a new html file in a flat file structure.<p>These &quot;variables&quot; are stored in a database. So whenever we change the &quot;design&quot; of the page, we repeat the same process again - regenerate each html file.<p>The flat file structure will run into limitations, which is solvable with a directory structure. Nginx remains performant with large numbers of files.<p>Right now, we use NextJS with a mix of server side rendering and static pages, so it is all good. But I have been wondering about achieving something similar with more rudimentary (and performant) tools.<p>There&#x27;s not too much additional work involved - templatizing the html file is straightforward, and this won&#x27;t be difficult to script.<p>What&#x27;s good and bad about this?

no comments

no comments