6 ms·
Adding a pinch of m4 [1] can give you a bit more of flexibility while sticking with the same barebones approach. I used to maintain a small website built like
by m000 3y ago
Adding a pinch of m4 [1] can give you a bit more of flexibility while sticking with the same barebones approach.
I used to maintain a small website built like that some 20 years back. But I can't see the model working today, personal websites excluded. The problem is that the approach essentially enforces Web 1.0 roles: You either need every contributing user to be html-proficient, or someone willing to assume the drudgery of being the "webmaster".
[1] https://en.wikipedia.org/wiki/M4_(computer_language) https://en.wikipedia.org/wiki/M4_(computer_language)
- q3k 3y ago> a pinch of m4 nononononononononono for the love of everything please no m4 isn't even a good esolang!
- Tomte 3y agoYou need to combine it with Perl and a collection of other special passes, of course: https://web.archive.org/web/20180309134414/http://thewml.org/about/ https://web.archive.org/web/20180309134414/http://thewml.org...
- PaulHoule 3y agoAt the dawn of the age of PHP, I created a user management system (registration, verification, admin interface, …) that was based on well-established ideas (how login worked at Yahoo, Amazon, and every other process major site) but got no traction at all as a open source project. In any language that wasn’t PHP it would be necessary to write an “authentication module” which as about 50lines of cookie handling code. Multiple times I managed to out several existing apps together and make an advanced web site. About 10 years ago the idea suddenly got traction once it was legitimized by the SAAS fad, I would tell people “don’t you know they’re going to end the free tier or go out of business or both?” and sure enough they did. Anyhow, I bring it up because the system used M4 to interpolate variables into PHP, other languages, shell scripts, SQL scripts, etc.
- gabereiser 3y agoUgh, I know exactly how this feels. You resist the urge so hard to say “I told you so” and instead relish in the fact that you saw it. “The Way”, so to speak. I remember having to write cgi cookie handling code. I remember having to write session-cookie sync code. PHP was a small slice of heaven in the cgi world. Until it wasn’t. Still, being able to import libraries of script functions without having to recompile was wizardry. The problem with php now is they let a certain product somewhat dictate their direction. Class namespaces with slashes is the ugliest design choice. What was your oss project that couldn’t get traction?
- PaulHoule 3y agoIt was called Tapir User Manager but the web site was down for some time. It was an open source failure but a career success because I used it around 8 projects including the arXiv preprint service, a voice chat service that got 400,000+ users, and the web site for our county green party (which had national impact.)
- envsubst 3y agoInstead of `m4` or `sed` find and replace, the author should try `envsubst`. It's a program that replaces bash style variable references (for example `$TITLE`) with their value in the environment. export CURRENT="..." cat page.html | envsubt
- teo_zero 3y agoThe problem is that the $SOMETHING syntax is just too common if your site is a technical one, and you'll end up substituting too much.
- envsubst 3y agoYou can specify which variable names are valid, reducing the likelihood of a collision.
- karl42 3y agoI agree that `envsubst` is a good choice for this. Unfortunately, it is not part of posix, so you can't rely on it being present everywhere. But as part of gettext, it is still very common.
- gizmo686 3y agoThere is no such thing as a "pinch of m4". You start a clean project promising that you won't touch m4 this time. Then you add a small m4 invocation to save yourself from some boilerplate. A year later, when you are trying to figure out why all instances of the word "cat" are silently disapearing from your website, you dig through 5 layers of macro expansions to discover that a junior dev tried implementing a for loop instead of copying it from the manual and messed up the quotation marks. Having solved the immediate issue, you decide that debbuging your DSL is too hard, so you import M4 macro file you have been copying between projects. You then spend a day replacinf all usages of 'define' with your macro-creating-macro that adds comments to the output enabling your stacktrace generation script to work. Next project, I am putting down a hard rule: no m4! (Except for maybe that one instance)
- JoelMcCracken 3y agoPlease write more to this story
- gizmo686 3y agoNot "this" story. Everything above has happened on several projects. The cat thing comes up because it is tricky to expand two macros next to each other without whitespace. So if you do: define(`foo',`hello') define(`bar',`world') foo bar foobar You will get: hello world foobar Working around this gets tricky, so someone inevitably ends up writing a cat-like macro such that you can do cat(foo,bar) To get helloworld. A side effect of this is that now "cat" is really "cat()" which expands to "". You can work around this by doing `cat'. However, if `cat' is used as an argument to another macro (such as a for loop), the quotation only prevents escaping the first time. When the for macro is expanded, the quotation marks are stripped, giving you just "cat", which gets expanded again. A correctly written for macro would add new quotes as needed, but I have never seen someone correctly write such a macro without just copying it. Not sure if I have seen this interaction specifically with for and cat, but I have seen an interaction like it on almost every project that used m4.
- 3y ago
- gjvc 3y agoI did that once. Never again. Just because it worked for sendmail is not sufficient justification for anything.
- SoftTalker 3y agoA lot of older unix software config is complicated and cryptic. sendmail, bind, apache, older X11, sudo are examples that come to mind.
- gjvc 3y agono shit. not everything is yaml and emoji status lines. but that's got nothing to do my mistake of using M4 when better tools existed.
- tannhaeuser 3y agoRather than relying on generic text substitution using m4 or perl or whatever, I suggest using SGML, the basis and common superset of HTML and XML, which comes with easy type checked text macro (entity) expansion for free or even type-aware parametric macro expansion. Where "type" refers to the regular content type of a markup element (ie. its allowed child elements and their expected order) but also considers expansion and escaping into attributes or other context such CDATA or RCDATA. Only SGML can extend to the case of properly expanding/escaping potentially malicious user comments with custom rules such as eg. allowing span-level markup but disallowing script elements, does markdown or other Wiki syntax expansion into HTML, can import external/syndicated HTML content, produce RSS and outlines for navigation, etc. Works well for nontrivial static site preparation tasks on the command-line; cf. linked tutorial and command line reference. [1]: https://sgmljs.net/docs/producing-html-tutorial/producing-html-tutorial.html https://sgmljs.net/docs/producing-html-tutorial/producing-ht... [2]: https://sgmljs.net/docs/sgmlproc-manual.html https://sgmljs.net/docs/sgmlproc-manual.html
- layer8 3y agoWhat is sgmljs? There doesn’t seem to be any explanation on the site.
- tannhaeuser 3y agoA comprehensive package for processing, converting, and serving SGML on the command line, on the server side, or in the browser; see [1]. Also features SGML DTDs (grammars) for W3C HTML 5, 5.1, 5.2, and Review Drafts January 2020 and 2023, which are the latest non-volatile W3C and WHATWG HTML recommendations/spec versions. [1]: https://www.npmjs.com/package/sgml https://www.npmjs.com/package/sgml Edit: your comment is a welcome reminder to improve the site, which isn't an easy thing to do however due to sheer volume of the material, even though it's using SGML for shared boilerplate inclusion, ToC/site nav and page nav generation, etc. (in fact, by calling sgmlproc from a Makefile)
- tkb 3y agoI too had a small web site with M4 around 1999/2000. Why M4? Because I'd learned enough of it to be useful/dangerous when wrestling with Sendmail, and it seemed to do the trick (at least when the trick was simply "be easier than manually editing lots of HTML files every time there's a site-wide change"). I suspect I was never doing anything complicated enough to encounter the gotchas mentioned by other commenters...
- mstef 3y agohaha, utterson also uses m4 for templating: https://github.com/stef/utterson/tree/master https://github.com/stef/utterson/tree/master