diff --git a/README.md b/README.md index 7f76fc1..d5aa845 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ For each command, the option `-h` give u some help. `./manage.py make-widgets` to make a file that groups all jinja2 widgets macros for easier includes. It is automatically called by `runserver` and `distill-local` commands. \ See an example in `EXAMPLE.md` + `./manage.py format-html ` to minify or beautify the html content (`` being `minify` or `beautify`) + ## Others JFM-Engine is a friendly fork of [JSSG](https://github.com/jtremesay/jssg/) made in agreement with the JSSG developer because of different goals. \ diff --git a/content/templates/jinja2/allwidgets.html b/content/templates/jinja2/allwidgets.html index dcc18fc..166ffd4 100644 --- a/content/templates/jinja2/allwidgets.html +++ b/content/templates/jinja2/allwidgets.html @@ -19,7 +19,7 @@ diff --git a/jssg/management/commands/format-html.py b/jssg/management/commands/format-html.py new file mode 100644 index 0000000..28bbe71 --- /dev/null +++ b/jssg/management/commands/format-html.py @@ -0,0 +1,33 @@ +from django.core.management.base import BaseCommand +from pathlib import Path +from bs4 import BeautifulSoup +from django.conf import settings + +class Command(BaseCommand): + help = "Format (beautify or minify) the html files in dist content" + + def add_arguments(self, parser): + parser.add_argument( + "mode", + choices=["beautify", "minify"], + type=str, + help="Beautify or minify the html files" + ), + parser.add_argument( + "distpath", + nargs='?', + type=str, + default=str(settings.DIST_DIR), + help="To specify a particular dist path. Default is: " + str(settings.DIST_DIR) + ) + + def handle(self, *args, **options) : + for path in Path(options["distpath"]).rglob("*.html") : + with open(path, "r+") as file : + soup = BeautifulSoup(file.read(), 'html.parser') + file.seek(0) + if options["mode"] == "minify" : + file.write(str(soup).replace('\n', '')) + else : + file.write(soup.prettify()) + file.truncate() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ec36189..11a21bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ django_vite_plugin==3.0.0 markdown2[all]==2.4.13 whitenoise==6.7.0 Jinja2==3.1.4 +beautifulsoup4==4.12.3 django-jinja-markdown \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 40307d7..b534021 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,12 @@ "@/*": [ "./*" ], + "@s:jssg/*": [ + "./jssg/static/jssg/*" + ], + "@t:jssg/*": [ + "./jssg/templates/jssg/*" + ], "@s:django_jinja_markdown/*": [ "./env/lib/python3.9/site-packages/django_jinja_markdown/static/django_jinja_markdown/*" ], @@ -35,12 +41,6 @@ ], "@t:django_distill/*": [ "./env/lib/python3.9/site-packages/django_distill/templates/django_distill/*" - ], - "@s:jssg/*": [ - "./jssg/static/jssg/*" - ], - "@t:jssg/*": [ - "./jssg/templates/jssg/*" ] } },