icyphox / legit

web frontend for git
https://git.icyphox.sh
MIT License
376 stars 25 forks source link

Embed the templates into the binary #10

Open DeluxeOwl opened 1 year ago

DeluxeOwl commented 1 year ago

Hey, after building the binary and moving it in ~/.local/bin it didn't work, since you need the templates.

I would be cool if the default templates were used when you don't specify a templates directory by embedding them using embed.FS

...
2022/12/22 20:24:39 http: panic serving 127.0.0.1:50144: html/template: pattern matches no files: `templates/*`
...
icyphox commented 1 year ago

That would be great yeah—if you'd like to give it a go, patches welcome.

quaintdev commented 1 year ago

I have implemented this change in https://github.com/icyphox/legit/pull/18. But I just realized that we don't need template path in config.yaml now that it's embedded. Also I embedded static files in binary which I think are better left outside.

I will fix this tomorrow evening, it's quite late here.

prologic commented 1 year ago

I have implemented this change in #18. But I just realized that we don't need template path in config.yaml now that it's embedded. Also I embedded static files in binary which I think are better left outside.

I will fix this tomorrow evening, it's quite late here.

You should embed the static resources in the binary too IMO 👌

daenney commented 1 year ago

I have implemented this change in #18. But I just realized that we don't need template path in config.yaml now that it's embedded. Also I embedded static files in binary which I think are better left outside.

I will fix this tomorrow evening, it's quite late here.

We should keep the static and template directories configurable and loadable from the filesystem, if they exist. That would make the initial deployment easy, but if anyone wants to customise the templates or the assets they still can by creating files at the expected paths instead of having to maintain a fork.

quaintdev commented 1 year ago

We should keep the static and template directories configurable and loadable from the filesystem, if they exist.

I was thinking if the path for static and/or template is not set in config then we load respective files from binary. If they are set then we load from file system.

daenney commented 1 year ago

We should keep the static and template directories configurable and loadable from the filesystem, if they exist.

I was thinking if the path for static and/or template is not set in config then we load respective files from binary. If they are set then we load from file system.

Ah yeah, that would be a nice way to do it.

quaintdev commented 1 year ago

Implementation for embed of templates and static is complete. Please review #18 If you have any feedback let me know.

prologic commented 1 year ago

We should keep the static and template directories configurable and loadable from the filesystem, if they exist. That would make the initial deployment easy, but if anyone wants to customise the templates or the assets they still can by creating files at the expected paths instead of having to maintain a fork.

Normally for most of my projects, I support using/loading templating / static resources from disk by "debug mode", production builds setups always use the embedded versions, unless an option like -t/--theme /path/to/theme is supplied.

Maybe leggit can adopt a similar pattern? 🤔

daenney commented 1 year ago

I've proposed something to that end in the PR, #18. It's relatively straightforward nowadays to do a real filesystem with fallback to embedded assets thanks to the fs.FS interface.

quaintdev commented 1 year ago

This was actually my initial approach but there were some issues so I decided to go with current implementation. I will take another look at it when I have some free time.