Skip to content

Commit

Permalink
Add format-html command
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Jul 18, 2024
1 parent 1b67b84 commit 4a05a4b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion content/templates/jinja2/allwidgets.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="navbar__container__right">
<a class="btn btn-sm btn-primary" href="{{ CTA_URL }}"
target="{{ CTA_TARGET }}">{{ CTA_LABEL }}</a>
<a href="{{ url('page', args=[CHANGE_LANG_URL]) }}">
<a href="{{ url_for_slug_path(CHANGE_LANG_URL) }}">
<img class="languageFlag" src="{{ static(CHANGE_LANG_FLAG_URL)}}" alt="{{ CHANGE_LANG_ALT }}"/>
</a>
</div>
Expand Down
33 changes: 33 additions & 0 deletions jssg/management/commands/format-html.py
Original file line number Diff line number Diff line change
@@ -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"
)

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()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ django_vite_plugin==3.0.0
markdown2[all]==2.4.13
whitenoise==6.7.0
Jinja2==3.1.4
beautifulsoup4==4.12.3
19 changes: 18 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": [
"./*"
],
"@s:jssg/*": [
"./jssg/static/jssg/*"
],
"@t:jssg/*": [
"./jssg/templates/jssg/*"
],
"@s:django_distill/*": [
"./env/lib/python3.9/site-packages/django_distill/static/django_distill/*"
],
"@t:django_distill/*": [
"./env/lib/python3.9/site-packages/django_distill/templates/django_distill/*"
]
}
},
"include": [
"content/front/"
Expand Down

0 comments on commit 4a05a4b

Please sign in to comment.