statik icon indicating copy to clipboard operation
statik copied to clipboard

Is it possible to use environment variables in context?

Open siddhantgoel opened this issue 7 years ago • 4 comments

Is it possible to use environment variables (or some other type of configuration) in context variables?

The use case is the following - I have a static site with an external analytics service enabled. I'd like statik to include the analytics JS snippet only when building for deployment, not in development. If statik had the concept of development/production modes, this would be possible. Alternatively, some form of templating in the YAML config files would also help.

Is this currently possible somehow? If not, what should the ideal interface here look like? If the change is not too big, I could think about submitting a PR.

Statik is very cool btw. Thanks for writing it. I feel this is a static site generator that's done "right".

siddhantgoel avatar Sep 23 '18 07:09 siddhantgoel

You could probably write a simple template tag that looked at os.environ['DEBUG'] or similar and returned either the JS snippet or null.

https://github.com/thanethomson/statik/wiki/Custom-template-tags-and-filters

pztrick avatar Sep 26 '18 10:09 pztrick

Oh that's a good idea. I'll look into it.

siddhantgoel avatar Sep 26 '18 16:09 siddhantgoel

So in general this works, but the flow is not that smooth. Some native support would still be nice. Maybe just a command line switch to specify which config file to pick instead of defaulting to config.yml in the current dir.

siddhantgoel avatar Sep 28 '18 19:09 siddhantgoel

You can already specify a different config file from the command line just using the -p or --project switch. For example:

> statik -p my-custom-config.yml

thanethomson avatar Nov 14 '18 18:11 thanethomson