diff options
Diffstat (limited to 'pydis_site/apps/content')
-rw-r--r-- | pydis_site/apps/content/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/content/templatetags/page_src.py | 25 |
2 files changed, 25 insertions, 0 deletions
diff --git a/pydis_site/apps/content/templatetags/__init__.py b/pydis_site/apps/content/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pydis_site/apps/content/templatetags/__init__.py diff --git a/pydis_site/apps/content/templatetags/page_src.py b/pydis_site/apps/content/templatetags/page_src.py new file mode 100644 index 00000000..143c420c --- /dev/null +++ b/pydis_site/apps/content/templatetags/page_src.py @@ -0,0 +1,25 @@ +from django import template +from django.conf import settings + + +register = template.Library() + + +def page_src_url(request_path: str) -> str: + """ + Return the corresponding GitHub source URL for the current content article. + + request_path is the relative path of an article, as returned by `request.path` in templates. + + GitHub source URL is set in settings.py as CONTENT_SRC_URL, prefix for the + url which the request path would be appended to. + + Assumes '.md' file extension for the page source files. + + For example: /pages/rules/ would return: + https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/rules.md + """ + src_url = request_path.replace("/pages/", settings.CONTENT_SRC_URL) + src_url = src_url[:-1] + ".md" + return src_url |