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

Add static site support #36

Open
radiac opened this issue Oct 1, 2024 · 1 comment
Open

Add static site support #36

radiac opened this issue Oct 1, 2024 · 1 comment

Comments

@radiac
Copy link
Owner

radiac commented Oct 1, 2024

Add a command to build a static site from your script.

I don't want to overload nanodjango with the kitchen sink, but this feels like a very useful feature - I've got several small static sites which I really wanted some of Django's features for, but setting up a full Django project felt overkill. A nanodjango script with a couple of models and some templates would have been perfect.

Probably should depend on #35

Usage: nanodjango <new_command> script.py /path/to/site. Possible command name:

  • staticsite - most descriptive, if a bit long (I know I'll type static-site at some point)
  • static - shorter, but could confuse people with django's static files (ie nanodjango static .. vs nanodjango manage .. collectstatic)
  • build - not specific to building a static file - could conflict with some sort of asset build command, should that ever be needed
  • publish - implies deployment, remote server

Possible libraries to base it on, in order of github star popularity:

  • django-distill (436 stars). Uses paths so should be easy.
  • django-bakery (405 stars, but known use on a big site). Requires class based views, which is fine but complicates things a bit - looks like we can't just dynamically create a view class with a BuildableMixin, seems people would need to explicitly use CBVs, which I'm not wild about
  • django-freeze (93 stars). Looks like a reliable package, if a bit newer. Working with a sitemap or HTML links would give us a lot of options.
  • There are others, but the ones I've used previously seem to be abandoned.

It looks like some of these packages will also deploy to s3 etc. That'd be a pretty handy feature, but I'm not keen on adding two commands for this. If supported, it would be better as eg nanodjango staticsite s3://...

It may also be good to have a --watch option - but only if there's a significant difference to nanodjango run

One other common use case would be to be running nanodjango serve on a private url, and have changes automatically trigger a build to a public one. That would be a nice feature, but I suspect out of scope - probably best handled with a HOWTO in the docs (touch a file, watch a file?)

Unless anyone has further suggestions, this will be pip install nanodjango[staticsite], nanodjango staticsite <script> <path>, and be based on django-distill, or django-freeze if we run into problems with distill

@radiac
Copy link
Owner Author

radiac commented Oct 27, 2024

Thinking about this more, this may make more sense as a separate project. It's definitely something I still want, but it feels like more of an edge case than mainstream, and I'm trying to be mindful of not letting nanodjango get too fat (see #35). It may require an extension of the convert plugin system, or swapping to pluggy.

It could still be installed as a dependency with nanodjango[staticsite], but I'm not sure about it as that would mean installing it with nanodjango[all]. I'm thinking about the learning journey someone's going to go on - once they land on the docs page about creating a static site, it's just as easy to say "now pip install something-else" as it is "I hope you installed with pip install nanodjango[all]"

An additional thought - one of the big problems with this idea is needing to commit the database. Alex Kerney pointed out the yamldl project, which may be a good solution.

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

No branches or pull requests

1 participant