ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

implement a more idiomatic (HTML) templating solution #1133

Open thescientist13 opened 1 year ago

thescientist13 commented 1 year ago

Type of Change

Enhancement

Summary

Coming out of #1126 , it's clear that how Greenwood handles various aspects of its templating, primarily for HTML, is a little too naive / brittle.

For example, Greenwood uses placeholders for injecting content into an HTML template

<html>
  <body>
    <content-outlet><content-outlet>
  </body>
</html>

Would get handled like this in the CLI

body = body.replace(/\<content-outlet>(.*)<\/content-outlet>/s, processedMarkdown.contents);

This issue is that $1 is used for matching when used in conjunction with the String .replace function.

So we have to keep doing things like

body = body.replace(/\<content-outlet>(.*)<\/content-outlet>/s, processedMarkdown.contents.replace(/\$/g, '$$$'));

This should also help us ensure that these are handled the same, just in case

<p>Hello World</p>

<P>Hello World</P>

Details

So rather than keep suffering through these issues...

Since we are already using an HTML parser, I see it supports methods like set_content which could a much more practical way to approach this problem.

So basically any usage of .replace, for HTML at minimum, would be a candidate for refactoring.