Skip to content

Commit

Permalink
Merge branch 'main' into feat__37_posts_categories_and_pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ClmntBcqt authored Jul 24, 2024
2 parents 4d50f9a + d262481 commit d9fc522
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <action>` to minify or beautify the html content (`<action>` 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. \
Expand Down
6 changes: 5 additions & 1 deletion content/pages/a_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title Page1
slug page1
template_engine jinja2
description
---
{

Expand All @@ -18,8 +19,11 @@ template_engine jinja2
<article>
{% markdown %}
```
This is markdown.
This is markdown :
```
test
**test**
`test`
{% endmarkdown %}
</article>

Expand Down
63 changes: 63 additions & 0 deletions jssg/management/commands/check-metadata.py
Original file line number Diff line number Diff line change
@@ -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)
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()
2 changes: 1 addition & 1 deletion jssg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
JFME_TEMPLATES_DIRS = [path / "templates" for path in JFME_CONTENT_DIRS]
JFME_STATIC_DIRS = [path / "static" for path in JFME_CONTENT_DIRS]
JFME_NUMBER_OF_POSTS_BY_PAGE = 3

JFME_CONTENT_REQUIRED_METADATA = ["title", "slug", "lang", "description"]


# Application definition
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d9fc522

Please sign in to comment.