From bd113f9f8d62c8479906cdbc891167e15c1b3a4c Mon Sep 17 00:00:00 2001 From: ClmntBcqt <129279765+ClmntBcqt@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:56:40 +0200 Subject: [PATCH 1/3] Allow markdown content (#35) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add django-jinja-markdown extension * Add examples for markdown in page1 --------- Co-authored-by: Clément --- content/pages/a_page.md | 25 ++++++++++++++++++++++++- jssg/jinja2.py | 3 ++- jssg/settings.py | 4 +++- requirements.txt | 3 ++- tsconfig.json | 25 ++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/content/pages/a_page.md b/content/pages/a_page.md index f37368f..e8f4205 100644 --- a/content/pages/a_page.md +++ b/content/pages/a_page.md @@ -8,7 +8,30 @@ template_engine jinja2 } --- +{% from "widgets/page_header.html" import page_header %} +

Page 1

-

Go to page 2

\ No newline at end of file +

Go to page 2

+ + +
+{% markdown %} +``` +This is markdown : +``` +test +**test** +`test` +{% endmarkdown %} +
+ + +{{ page_header( + markdown(' +test +**test** +`test` + ') +) }} diff --git a/jssg/jinja2.py b/jssg/jinja2.py index dcbbf73..8c87f1b 100644 --- a/jssg/jinja2.py +++ b/jssg/jinja2.py @@ -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 @@ -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 } diff --git a/jssg/settings.py b/jssg/settings.py index a0ce03b..71e6f44 100644 --- a/jssg/settings.py +++ b/jssg/settings.py @@ -59,6 +59,7 @@ INSTALLED_APPS = [ "jssg", + "django_jinja_markdown", "django.contrib.contenttypes", "whitenoise.runserver_nostatic", "django.contrib.staticfiles", @@ -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"] }, }, { diff --git a/requirements.txt b/requirements.txt index c196e9e..ec36189 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -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 +django-jinja-markdown \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 984c649..40307d7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,30 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "paths": { + "@/*": [ + "./*" + ], + "@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/*" + ], + "@s:jssg/*": [ + "./jssg/static/jssg/*" + ], + "@t:jssg/*": [ + "./jssg/templates/jssg/*" + ] + } }, "include": [ "content/front/" From 1042e9dded867089e5773cfaa546e20241ccf61a Mon Sep 17 00:00:00 2001 From: ClmntBcqt <129279765+ClmntBcqt@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:46:41 +0200 Subject: [PATCH 2/3] Add format-html command (#42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add format-html command * Add format-html command in doc --------- Co-authored-by: Clément --- README.md | 2 ++ content/templates/jinja2/allwidgets.html | 2 +- jssg/management/commands/format-html.py | 33 ++++++++++++++++++++++++ requirements.txt | 1 + tsconfig.json | 12 ++++----- 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 jssg/management/commands/format-html.py 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/*" ] } }, From d262481853dcb732df71e6d531457422d12bb131 Mon Sep 17 00:00:00 2001 From: ClmntBcqt <129279765+ClmntBcqt@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:52:01 +0200 Subject: [PATCH 3/3] Add a check-metadata command (#36) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add a check-metadata command * add check-metadata in doc --------- Co-authored-by: Clément --- content/pages/a_page.md | 1 + jssg/management/commands/check-metadata.py | 63 ++++++++++++++++++++++ jssg/settings.py | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 jssg/management/commands/check-metadata.py diff --git a/content/pages/a_page.md b/content/pages/a_page.md index e8f4205..2db42a2 100644 --- a/content/pages/a_page.md +++ b/content/pages/a_page.md @@ -2,6 +2,7 @@ title Page1 slug page1 template_engine jinja2 +description --- { diff --git a/jssg/management/commands/check-metadata.py b/jssg/management/commands/check-metadata.py new file mode 100644 index 0000000..be037f8 --- /dev/null +++ b/jssg/management/commands/check-metadata.py @@ -0,0 +1,63 @@ +from django.core.management.base import BaseCommand +from django.conf import settings +from jssg.models import Page +from pathlib import Path + +class MetadataStatus : + + @classmethod + def get_metadata_status_for(cls, page) : + metadata_status = MetadataStatus() + metadata_status.missing = [] + metadata_status.empty = [] + for required_metadata in settings.JFME_CONTENT_REQUIRED_METADATA : + if required_metadata not in page.metadata : + metadata_status.missing.append(required_metadata) + elif page.metadata[required_metadata] == "" : + metadata_status.empty.append(required_metadata) + metadata_status.complete = (metadata_status.missing == []) and (metadata_status.empty == []) + if len(settings.JFME_CONTENT_REQUIRED_METADATA) > 0 : + metadata_status.progression = (len(settings.JFME_CONTENT_REQUIRED_METADATA) - len(metadata_status.missing) - len(metadata_status.empty)) * 100 / len(settings.JFME_CONTENT_REQUIRED_METADATA) + else : + metadata_status.progression = 100 + return metadata_status + +class Command(BaseCommand): + help = "Check if metadata in JFME_CONTENT_REQUIRED_METADATA setting are specified in pages." + + def add_arguments(self, parser): + parser.add_argument( + "--verbose", + action = "store_true", + help="Show missing or empty metadata in each page." + ) + parser.add_argument( + "content path", + nargs = "*", + type=str, + default=settings.JFME_PAGES_DIRS, + help="The paths where search the pages. Set to JFME_PAGES_DIRS by default." + ) + + def handle(self, *args, **options) : + + if settings.JFME_CONTENT_REQUIRED_METADATA == [] : + self.stdout.write(self.style.WARNING( + "Warning : no metadata specified in JFME_CONTENT_REQUIRED_METADATA setting." + )) + + for page in Page.load_glob(path = list(map(lambda p : Path(p).absolute(), options["content path"])), all = True) : + + metadata_status = MetadataStatus.get_metadata_status_for(page) + + self.stdout.write("{:3.0f}% : {}".format( + metadata_status.progression, + page.path.relative_to(page.content_page_dir)) + ) + + if options["verbosity"] > 1 or options["verbose"] : + if not metadata_status.complete : + for missing in metadata_status.missing : + self.stdout.write("\t- '%s' is missing" % missing) + for empty in metadata_status.empty : + self.stdout.write("\t- '%s' is empty" % empty) \ No newline at end of file diff --git a/jssg/settings.py b/jssg/settings.py index 71e6f44..c03e8a1 100644 --- a/jssg/settings.py +++ b/jssg/settings.py @@ -52,7 +52,7 @@ JFME_POSTS_DIRS = [path / "posts" for path in JFME_CONTENT_DIRS] JFME_TEMPLATES_DIRS = [path / "templates" for path in JFME_CONTENT_DIRS] JFME_STATIC_DIRS = [path / "static" for path in JFME_CONTENT_DIRS] - +JFME_CONTENT_REQUIRED_METADATA = ["title", "slug", "lang", "description"] # Application definition