diff --git a/README.md b/README.md index 0d236cf..3ae3bd5 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ urlpatterns = ( ### Parameters in file names -You can standard Python string formatting in `distill_file` as well to enable +You can use standard Python string formatting in `distill_file` as well to enable you to change the output file path for a file if you wish. Note this does not update the URL used by Django so if you use this make sure your `path` pattern matches the `distill_file` pattern or your links might not work in Django. An @@ -322,6 +322,11 @@ to update most of them, and you don't care if old files remain on the server. `--parallel-publish [number of threads]`: Publish files in parallel on multiple threads, this can speed up publishing. Defaults to `1` thread. +`--generate-redirects`: Attempt to generate static redirects stored in the +`django.contrib.redirects` app. If you have a redirect from `/old/` to `/new/` using +this flag will create a static HTML `` +style redirect at `/old/index.html` to `/new/`. + **Note** that this means if you use `--force` and `--quiet` that the output directory will have all files not part of the site export deleted without any confirmation. diff --git a/django_distill/management/commands/distill-local.py b/django_distill/management/commands/distill-local.py index 9b51d88..06d1cb2 100644 --- a/django_distill/management/commands/distill-local.py +++ b/django_distill/management/commands/distill-local.py @@ -89,7 +89,7 @@ def handle(self, *args, **options): raise CommandError(str(err)) from err stdout('') if generate_redirects: - stdout('Generating redirects...') + stdout('Generating redirects') render_redirects(output_dir, stdout) stdout('') stdout('Site generation complete.') diff --git a/django_distill/management/commands/distill-publish.py b/django_distill/management/commands/distill-publish.py index f336d9d..f0349bb 100644 --- a/django_distill/management/commands/distill-publish.py +++ b/django_distill/management/commands/distill-publish.py @@ -6,7 +6,7 @@ from django_distill.distill import urls_to_distill from django_distill.errors import DistillError from django_distill.renderer import (run_collectstatic, render_to_dir, - copy_static_and_media_files) + copy_static_and_media_files, render_redirects) from django_distill.publisher import publish_dir @@ -25,6 +25,7 @@ def add_arguments(self, parser): parser.add_argument('--skip-verify', dest='skip_verify', action='store_true') parser.add_argument('--ignore-remote-content', dest='ignore_remote_content', action='store_true') parser.add_argument('--parallel-publish', dest='parallel_publish', type=int, default=1) + parser.add_argument('--generate-redirects', dest='generate_redirects', action='store_true') def _quiet(self, *args, **kwargs): pass @@ -50,6 +51,7 @@ def handle(self, *args, **options): ignore_remote_content = options.get('ignore_remote_content', False) quiet = options.get('quiet') force = options.get('force') + generate_redirects = options.get('generate_redirects') if quiet: stdout = self._quiet else: @@ -93,9 +95,12 @@ def handle(self, *args, **options): except DistillError as err: raise CommandError(str(err)) from err stdout('') + if generate_redirects: + stdout('Generating redirects') + render_redirects(output_dir, stdout) + stdout('') stdout('Publishing site') backend.index_local_files() publish_dir(backend, stdout, not skip_verify, parallel_publish, ignore_remote_content) - stdout('') stdout('Site generation and publishing complete.')