diff options
author | 2023-05-06 18:01:37 +0100 | |
---|---|---|
committer | 2023-05-06 18:01:37 +0100 | |
commit | 748a170be5f576b6e0e6b72cead0cafc0c32190e (patch) | |
tree | 469fddd7078a92bc5fd5f0cce8029f358153e66e | |
parent | Merge pull request #961 from python-discord/dependabot/pip/django-4.2.1 (diff) | |
parent | Fix extra whitespace from button (diff) |
Merge pull request #949 from python-discord/hedyhli-edit-on-github
Edit on GitHub feature for content
-rw-r--r-- | pydis_site/apps/content/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | pydis_site/apps/content/templatetags/page_src.py | 25 | ||||
-rw-r--r-- | pydis_site/settings.py | 5 | ||||
-rw-r--r-- | pydis_site/static/css/content/page.css | 10 | ||||
-rw-r--r-- | pydis_site/templates/content/base.html | 12 | ||||
-rw-r--r-- | pydis_site/templates/content/dropdown.html | 2 |
6 files changed, 53 insertions, 1 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 diff --git a/pydis_site/settings.py b/pydis_site/settings.py index e9e0ba67..9da9a156 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -332,3 +332,8 @@ REDIRECTIONS_PATH = Path(BASE_DIR, "pydis_site", "apps", "redirect", "redirects. # How long to wait for synchronous requests before timing out TIMEOUT_PERIOD = env("TIMEOUT_PERIOD") + +# Source files url for 'Edit on GitHub' link on content articles +CONTENT_SRC_URL = ( + "https://github.com/python-discord/site/tree/main/pydis_site/apps/content/resources/" +) diff --git a/pydis_site/static/css/content/page.css b/pydis_site/static/css/content/page.css index d831f86d..cabf6962 100644 --- a/pydis_site/static/css/content/page.css +++ b/pydis_site/static/css/content/page.css @@ -2,6 +2,16 @@ padding: 1rem; } +#edit-on-github { + margin-left: 1rem; +} + +@media (max-width: 600px) { + #edit-on-github { + display: none; + } +} + i.has-icon-padding { padding: 0 10px 25px 0; } diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html index 2fd721a3..b04c7efa 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 %} @@ -29,10 +30,21 @@ <li class="is-active"><a href="#">{{ page_title }}</a></li> </ul> </nav> + </div> + <div class="is-flex is-pulled-right is-right"> {# Sub-Article dropdown for category pages #} {% if subarticles %} {% include "content/dropdown.html" %} {% endif %} + {# Edit on GitHub for content articles #} + {% if page %} + <div id="edit-on-github"> + <a href="{{ request.path | page_src_url }}"> + <i class="fa-solid fa-pencil"></i> + Edit on GitHub + </a> + </div> + {% endif %} </div> </section> diff --git a/pydis_site/templates/content/dropdown.html b/pydis_site/templates/content/dropdown.html index 13c89c68..60560547 100644 --- a/pydis_site/templates/content/dropdown.html +++ b/pydis_site/templates/content/dropdown.html @@ -1,4 +1,4 @@ -<div class="dropdown is-pulled-right is-right" id="dropdown" style="z-index: 1"> +<div class="dropdown" id="dropdown" style="z-index: 1"> <div class="dropdown-trigger"> <a aria-haspopup="true" aria-controls="subarticle-menu"> <span>Sub-Articles</span> |