aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2023-05-06 18:01:37 +0100
committerGravatar GitHub <[email protected]>2023-05-06 18:01:37 +0100
commit748a170be5f576b6e0e6b72cead0cafc0c32190e (patch)
tree469fddd7078a92bc5fd5f0cce8029f358153e66e /pydis_site/apps/content
parentMerge pull request #961 from python-discord/dependabot/pip/django-4.2.1 (diff)
parentFix extra whitespace from button (diff)
Merge pull request #949 from python-discord/hedyhli-edit-on-github
Edit on GitHub feature for content
Diffstat (limited to 'pydis_site/apps/content')
-rw-r--r--pydis_site/apps/content/templatetags/__init__.py0
-rw-r--r--pydis_site/apps/content/templatetags/page_src.py25
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