Skip to content

Commit

Permalink
Merge branch 'main' into feat__15_check_metadata_command
Browse files Browse the repository at this point in the history
  • Loading branch information
ClmntBcqt authored Jul 24, 2024
2 parents c186f93 + 1042e9d commit 3ebdb19
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ 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 check-metadata` to check if metadata specified in `JFME_CONTENT_REQUIRED_METADATA` are set in pages.
`./manage.py format-html <action>` to minify or beautify the html content (`<action>` being `minify` or `beautify`)

## Others

Expand Down
25 changes: 24 additions & 1 deletion content/pages/a_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ description
}

---
{% from "widgets/page_header.html" import page_header %}


<h2>Page 1</h2>

<p>Go to <a href="{{ url_for_slug('page2') }}">page 2</a> </p>
<p>Go to <a href="{{ url('page', args=['page2']) }}">page 2</a> </p>


<article>
{% markdown %}
```
This is markdown :
```
test
**test**
`test`
{% endmarkdown %}
</article>


{{ page_header(
markdown('
test
**test**
`test`
')
) }}
3 changes: 2 additions & 1 deletion jssg/jinja2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.templatetags.static import static
from django.urls import reverse

from django_jinja_markdown.templatetags.md import markdown
from jinja2 import Environment

from jssg.templatetags.filter_opengraph_metadata import filter_opengraph_metadata
Expand Down Expand Up @@ -91,6 +91,7 @@ def environment(**options):
{
"static": static,
"url": reverse,
"markdown": markdown,
"url_for_slug": url_for_slug,
"url_for_slug_path" : url_for_slug_path
}
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. 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()
4 changes: 3 additions & 1 deletion jssg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

INSTALLED_APPS = [
"jssg",
"django_jinja_markdown",
"django.contrib.contenttypes",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
Expand All @@ -80,7 +81,8 @@
"DIRS": [path / "jinja2" for path in JFME_TEMPLATES_DIRS],
"APP_DIRS": True,
"OPTIONS": {
"environment": "jssg.jinja2.environment"
"environment": "jssg.jinja2.environment",
"extensions": ["django_jinja_markdown.extensions.MarkdownExtension"]
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Django==5.0.6
Django==4.2.9
django-distill
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
25 changes: 24 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,30 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"paths": {
"@/*": [
"./*"
],
"@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/*"
],
"@t:django_jinja_markdown/*": [
"./env/lib/python3.9/site-packages/django_jinja_markdown/templates/django_jinja_markdown/*"
],
"@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 3ebdb19

Please sign in to comment.