Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings for index page slug and to add jinja2 filters and functions #50

Closed
ClmntBcqt opened this issue Aug 2, 2024 · 3 comments
Closed

Comments

@ClmntBcqt
Copy link
Contributor

1. Index page configuration

Currently we need to configure the index page (page at URL "/") in views.py, in IndexView class by changing the lines :

self.kwargs["slug"] = "accueil"
self.kwargs["dir"] = "fr/index"

Expected :
It would be clearer and easier if we could configure the slug and folder of index page as a setting in settings.py.
For instance to configure the index view with the page content/pages/fr/index/home.md that has the slug accueil :

JFME_INDEX_PAGE = "fr/index/accueil" # <folder>/<slug>

2. Add jinja2 filters and functions

Currently the users can't add Jinja2 filters or functions unless modify the file jinja2.py.
Expected :
It could be useful to add settings JFME_ADDITIONAL_JINJA2_FILTERS and JFME_ADDITIONAL_JINJA2_FUNCTIONS
For instance in settings.py:

import base64, readtime

def base64encode(value):
    return base64.b64encode(value.encode('utf-8')).decode('utf-8')

def readtime_markdown(s):
    result = readtime.of_markdown(s).minutes
    if result == 0:
        return 1
    return result

JFME_ADDITIONAL_JINJA2_FILTERS = {"encode_base_64" : base64encode, "readtime_markdown": readtime_markdown}
JFME_ADDITIONAL_JINJA2_FUNCTIONS = {"encode_base_64" : base64encode, "readtime_markdown": readtime_markdown}

Then in templates :

{{ "foo" | encode_base_64 }}
{{ read_time_markdown("##title **text** blabla") }}
@lebouquetin
Copy link
Member

Also, it would be interesting to put all standard filters in a unique place

@ClmntBcqt
Copy link
Contributor Author

To avoid to import files in settings.py, we give the string of module to import :

JFME_ADDITIONAL_JINJA2_FILTERS = {"encode_base_64" : "jssg.templatetags.base_64.base64encode", "readtime_markdown": "readtime.of_markdown"}
JFME_ADDITIONAL_JINJA2_FILTERS = {"encode_base_64" : "jssg.templatetags.base_64.base64encode", "readtime_markdown": "readtime.of_markdown"}

jfmengine/jssg/templatetags/ is the standard directory to put filters and functions.

@ClmntBcqt
Copy link
Contributor Author

Merged in #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants