News for hackers. Stuff that matters.
Re:Lessons from Building a Static Site Generator (2020) by jrm4 on Wednesday June 30, 2021 @10:37AM (#27689081)
Alright, I'm skimming this whole idea of newfangled "static site generators" that involve a lot of Javascript and I'm left with a whole lot of "Isn't this just ____ with extra steps?"

I'm seeing "shortcodes" and I'm like -- as in variables and/or configuration files?

Or, more broadly -- why Javascript for the backend? This looks like a silly level of complexity. I'd start thinking about it in Bash and then probably head over to e.g. Python once databases et al start getting involved. What am I missing here?

Re:Lessons from Building a Static Site Generator (2020) by nickreese on Wednesday June 30, 2021 @11:10AM (#27689494)
Shortcodes as they are implemented in Elder.js (what the article is about) are borrowed from WordPress. Basically they are a placeholder such as [[lastestTweet/]] that let you add dynamic content into otherwise static content.

While Elder.js does allow for full server side rendering making "Javascript the backend" the goal of the static site generator is generate static HTML/CSS/JS that can be hosted from a CDN, S3, or other static host.

That said, one of the biggest pitfalls with building a major site on a static site generator is there is often no upgrade path to server rendering. Elder.js does offer that out of the box.

Re:Lessons from Building a Static Site Generator (2020) by brundolf on Wednesday June 30, 2021 @11:50AM (#27689969)
> why Javascript for the backend?...[I'd] probably head over to e.g. Python once databases et al start getting involved

I could ask the same thing: why Python for the back-end?

Both languages have similar feature-sets and are roughly equally suitable to this task. Given that, a person should use whichever they're most comfortable with. Lots of people are comfortable with JavaScript these days, ergo there's lots of activity in the JavaScript SSG space.

Re:Lessons from Building a Static Site Generator (2020) by jrm4 on Wednesday June 30, 2021 @12:05PM (#27690186)
Fair -- but let me be more precise then. I do like the idea of "use what you learned and are most comfortable in."

That being said, I think what I mean by "e.g. Python" is specifically - "older slash more text oriented slash proven"

If you like Javascript, fine. But I think there's a case to be made that there is a completely unnecessary "bloat" to Javascript -- especially even as the author himself has suggested that at the end of the day it's all string concatenation.

If that's the case, (as it frequently is) it ends up boiling down to "what handles text well and in an established and smooth way," and Javascript does not score high there, I'd suggest.

Re:Lessons from Building a Static Site Generator (2020) by brundolf on Wednesday June 30, 2021 @12:38PM (#27690617)
It doesn't sound like you write much JavaScript :)

> I think there's a case to be made that there is a completely unnecessary "bloat" to Javascript

"Bloat in JS" is something of a trope, and I'm not really even sure what you mean by it here. Typically people mean "too many JS dependencies are often drawn in for web pages", but that's not really relevant. Maybe you mean syntax bloat (method calls instead of list comprehensions)? If so, you're not totally wrong, but it's also not really a big deal in my experience. If you're talking about runtime/performance, well... V8 tends to be faster than CPython in raw compute (excluding native modules) because Google has put so much work into optimizing it (not that that matters much for a SSG either)

> it ends up boiling down to "what handles text well and in an established and smooth way," and Javascript does not score high there

Whenever I need to process some nontrivial text, the first thing I do is open up a Chrome tab for the JS repl. I think the following it pretty smooth:

  const csv = `
  Name,Email,Phone Number,Address
  Bob Smith,[email protected],123-456-7890,123 Fake Street
  Mike Jones,[email protected],098-765-4321,321 Fake Avenue`

  const lines = csv.trim().split('\n').map(line => line.split(','))

  const [headings, ...data] = lines

  const objs = data.map(datum => Object.fromEntries(
    headings.map((heading, index) => [heading, datum[index]])))

  console.log(objs)


  // output:
  [
    {
      "Name": "Bob Smith",
      "Email": "[email protected]",
      "Phone Number": "123-456-7890",
      "Address": "123 Fake Street"
    },
    {
      "Name": "Mike Jones",
      "Email": "[email protected]",
      "Phone Number": "098-765-4321",
      "Address": "321 Fake Avenue"
    }
  ]
Not to mention template-strings, which I use extensively in my own website:

  const header = `
    <h1>Welcome to ${pageTitle}</h1>
  `
Of course it's all subjective and Python does have format strings and some slick dedicated syntaxes. But I don't think it's fair to say "JavaScript does not score high" when it comes to text-shuffling.
Re:Lessons from Building a Static Site Generator (2020) by jrm4 on Thursday July 01, 2021 @10:04AM (#27699147)
When I say bloat, I do mostly mean "human-side," not "computer-side" of things. Again, if it works for you it works, but from my POV the idea of opening up a massive application, a web browser, that's mostly unrelated to the task at hand -- when leaner, older, well-proven approaches exist is super-odd to me. I have actually seen this before, and here's the observation:

Consider someone who starts off text-mangling in Javascript, and then later has a go at a more "classic" approach, e.g. command-line with Bash or Python or even Perl. Then consider the reverse; someone who starts off classic and learns/tries this Javascript approach.

I'd be willing to bet huge sums of money that a decent number of the Javascript people will end up adopting the classic approach, and that very few, possibly zero, of the classic people will adopt the Javascript approach.

Re:Lessons from Building a Static Site Generator (2020) by z3t4 on Wednesday June 30, 2021 @08:09PM (#27694984)
I remember when string concatenations where slow in JavaScript and you used array join. But string concatenation is very optimized now in all major JS engines.
Re:Lessons from Building a Static Site Generator (2020) by frabert on Wednesday June 30, 2021 @11:17AM (#27689591)
Curious you mention bash! I did exactly that some time ago when I thought about starting blogging... And then never started blogging!

https://blog.frabert.me/posts/2018/11/11/blash.html

Re:Lessons from Building a Static Site Generator (2020) by valenterry on Wednesday June 30, 2021 @10:56AM (#27689298)
> What am I missing here?

People usually start their projects with the language they feel most comfortable in, not the one that is best suited for the project.