feat: display license information on article page
Added functionality to fetch and display license information for wiki articles. This enhancement provides users with clarity on content usage permissions by showing a link to the article's license in the footer. Fixes #35.
This commit is contained in:
parent
70c40fd979
commit
87a4f07285
3 changed files with 23 additions and 3 deletions
|
@ -387,8 +387,6 @@ def wiki_article(
|
||||||
if parent.attrs.get("data-mw-group", None):
|
if parent.attrs.get("data-mw-group", None):
|
||||||
span["class"] = span.get("class", []) + [parent.attrs["data-mw-group"]]
|
span["class"] = span.get("class", []) + [parent.attrs["data-mw-group"]]
|
||||||
|
|
||||||
processed_html = str(body)
|
|
||||||
|
|
||||||
rtl = bool(soup.find("div", class_="mw-parser-output", dir="rtl"))
|
rtl = bool(soup.find("div", class_="mw-parser-output", dir="rtl"))
|
||||||
|
|
||||||
# Edge case: When passing the `ku-arab` variant, the article is in Arabic
|
# Edge case: When passing the `ku-arab` variant, the article is in Arabic
|
||||||
|
@ -399,6 +397,20 @@ def wiki_article(
|
||||||
|
|
||||||
processed_html = str(body)
|
processed_html = str(body)
|
||||||
|
|
||||||
|
# Get license information from the article
|
||||||
|
mediawiki_api_request = urllib.request.Request(
|
||||||
|
f"{base_url}/w/rest.php/v1/page/{quote(escape(title.replace(' ', '_'), False))}",
|
||||||
|
headers=HEADERS,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(mediawiki_api_request) as response:
|
||||||
|
data = json.loads(response.read().decode())
|
||||||
|
license = data["license"]
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error fetching license information: {e}")
|
||||||
|
license = None
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"article.html",
|
"article.html",
|
||||||
title=title.replace("_", " "),
|
title=title.replace("_", " "),
|
||||||
|
@ -406,6 +418,7 @@ def wiki_article(
|
||||||
lang=lang,
|
lang=lang,
|
||||||
project=project,
|
project=project,
|
||||||
rtl=rtl,
|
rtl=rtl,
|
||||||
|
license=license,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,9 @@
|
||||||
<h1 class="title{% if rtl %} title-rtl{% endif %}">{{ title }}</h1>
|
<h1 class="title{% if rtl %} title-rtl{% endif %}">{{ title }}</h1>
|
||||||
{{ content|safe }}
|
{{ content|safe }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block license %}
|
||||||
|
{% if license %}
|
||||||
|
<p class="license">This content is licensed under the <a href="{{ license.url }}">{{ license.title }}</a>.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
|
{% block license %}{% endblock %}
|
||||||
<p>Brought to you by <a href="https://git.private.coffee/privatecoffee/wikimore">Wikimore</a>, a <a href="https://private.coffee">Private.coffee</a> project</p>
|
<p>Brought to you by <a href="https://git.private.coffee/privatecoffee/wikimore">Wikimore</a>, a <a href="https://private.coffee">Private.coffee</a> project</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue