-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clément
committed
Jul 18, 2024
1 parent
1b67b84
commit 4a05a4b
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters