lemmyBB icon indicating copy to clipboard operation
lemmyBB copied to clipboard

Formatting template files

Open Nutomic opened this issue 3 years ago • 3 comments

The HTML in template files is currently rather messy, It would be good if it could be formatted nicely with an automated formatter, similar to cargo fmt. So far i found two possible tools, but neither of them really works for our usecase:

  • Tidy with tidy -mi -w 100 --drop-empty-elements no templates/viewtopic.html.hbs: only works on complete html files, so when called on partials, it adds head and tries to close all divs, so those changes have to be reverted manually. Even then, the html ends up broken in some unknown way, and the site only returns error 500.
  • Prettier: has support for both html and handlebars, which is ideal for our usecase. Unfortunately it throws errors and fails to run at all, because partials are not supported (https://github.com/prettier/prettier/issues/11834, https://github.com/glimmerjs/glimmer-vm/issues/1367)

Nutomic avatar Jul 13 '22 13:07 Nutomic

If you used yew.rs, you could move all the template html to rust, as well as get rid of the rocket back-end entirely.

dessalines avatar Sep 25 '22 13:09 dessalines

Sounds like it wouldnt work without js in that case, which i want to avoid. I also dont want to translate templates to another language, tried that before and its a ton of work for very little benefit. Right now i can simply copy-paste most of the html and use it directly.

Nutomic avatar Sep 26 '22 20:09 Nutomic

Yew uses an html! macro but ya it would probably still be a lot of work... only worth it if you had very few templates.

Yew also has SSR(renderToString()) and isomorphic app support tho, so if the site doesn't need javascript, its still usable. I'm considering using it for future web apps even tho its slower than inferno and solidjs, just because working in rust is so much nicer.

dessalines avatar Sep 26 '22 23:09 dessalines