Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed the templates into the binary #10

Open
DeluxeOwl opened this issue Dec 22, 2022 · 10 comments
Open

Embed the templates into the binary #10

DeluxeOwl opened this issue Dec 22, 2022 · 10 comments

Comments

@DeluxeOwl
Copy link

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
Copy link
Owner

icyphox commented Dec 26, 2022

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

@quaintdev
Copy link

quaintdev commented Jan 5, 2023

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.

@prologic
Copy link
Contributor

prologic commented Jan 5, 2023

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
Copy link
Contributor

daenney commented Jan 6, 2023

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
Copy link

quaintdev commented Jan 6, 2023

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
Copy link
Contributor

daenney commented Jan 6, 2023

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
Copy link

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

@prologic
Copy link
Contributor

prologic commented Jan 6, 2023

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
Copy link
Contributor

daenney commented Jan 7, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants