diff options
Diffstat (limited to 'pydis_site')
| -rw-r--r-- | pydis_site/apps/content/templatetags/__init__.py | 0 | ||||
| -rw-r--r-- | pydis_site/apps/content/templatetags/page_src.py | 22 | ||||
| -rw-r--r-- | pydis_site/templates/content/base.html | 1 | 
3 files changed, 23 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..33f24b82 --- /dev/null +++ b/pydis_site/apps/content/templatetags/page_src.py @@ -0,0 +1,22 @@ +from django import template + + +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. + +    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/", +        "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/", +    ) +    src_url = src_url[:-1] + ".md" +    return src_url diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 2fd721a3..8f6fd1d8 100644 --- a/pydis_site/templates/content/base.html +++ b/pydis_site/templates/content/base.html @@ -1,5 +1,6 @@  {% extends 'base/base.html' %}  {% load static %} +{% load page_src %}  {% block title %}{{ page_title }}{% endblock %}  {% block head %} | 
