Skip to content

Commit 20f264c

Browse files
committed
feat: Add rst document parsing; move links to detail
1 parent 9da97e1 commit 20f264c

File tree

8 files changed

+140
-109
lines changed

8 files changed

+140
-109
lines changed

django_wtf/core/github_tasks.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import date
44

55
import markdown
6+
import pypandoc
67
import superrequests
78
from constance import config
89
from django.db.utils import DataError
@@ -112,14 +113,26 @@ def index_repository_readme(repo_full_name):
112113
res = http.get(
113114
f"https://api.github.com/repos/{repo_full_name}/contents/README.md"
114115
)
116+
markdown_text = b64decode(res.json()["content"]).decode("utf-8")
115117
except HTTPError as ex:
116118
if ex.response.status_code == 404:
117119
logging.info(f"{repo_full_name} has no README.md file")
118-
return
120+
logging.info("Trying README.rst")
121+
122+
try:
123+
res = http.get(
124+
f"https://api.github.com/repos/{repo_full_name}/contents/README.rst"
125+
)
126+
rst_text = b64decode(res.json()["content"]).decode("utf-8")
127+
markdown_text = pypandoc.convert_text(rst_text, "md", format="rst")
128+
return
129+
except HTTPError as rst_ex:
130+
if ex.response.status_code == 404:
131+
logging.info(f"{repo_full_name} has no README.rst file")
132+
return
133+
raise rst_ex
119134
raise ex
120135

121-
markdown_text = b64decode(res.json()["content"]).decode("utf-8")
122-
123136
repo = Repository.objects.get(full_name=repo_full_name)
124137
repo.readme_html = markdown.markdown(
125138
markdown_text, extensions=["extra", "codehilite"]

django_wtf/templates/core/category_detail.html

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,28 @@
2323
<tbody>
2424
{% for repo in page_obj %}
2525
<tr class="hover">
26-
{% with url=repo.github_url %}
27-
<td class="hidden xl:table-cell">
28-
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
29-
</td>
30-
<td>
31-
<a href="{{ url }}" target="_blank">
32-
{% if request|is_mobile or request|is_tablet %}
33-
{{ repo.full_name|truncatechars:30 }}
34-
{% else %}
35-
{{ repo.full_name }}
36-
{% endif %}
37-
</a>
38-
</td>
39-
<td class="hidden xl:table-cell">
40-
<div class="tooltip tooltip-primary before:content-[attr(data-tip)] before:max-w-[50rem]"
41-
data-tip="{{ repo.truncated_description }}">
42-
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:60 }}</a>
43-
</div>
44-
</td>
45-
<td>
46-
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
47-
</td>
48-
{% endwith %}
26+
{% url 'core:repo-detail' full_name=repo.full_name as url %}
27+
<td class="hidden xl:table-cell">
28+
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
29+
</td>
30+
<td>
31+
<a href="{{ url }}" target="_blank">
32+
{% if request|is_mobile or request|is_tablet %}
33+
{{ repo.full_name|truncatechars:30 }}
34+
{% else %}
35+
{{ repo.full_name }}
36+
{% endif %}
37+
</a>
38+
</td>
39+
<td class="hidden xl:table-cell">
40+
<div class="tooltip tooltip-primary before:content-[attr(data-tip)] before:max-w-[50rem]"
41+
data-tip="{{ repo.truncated_description }}">
42+
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:60 }}</a>
43+
</div>
44+
</td>
45+
<td>
46+
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
47+
</td>
4948
</tr>
5049
{% endfor %}
5150
</tbody>

django_wtf/templates/core/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ <h3 class="text-lg font-bold">Trending Packages</h3>
3636
{% for repo in trending_apps %}
3737
<tr>
3838
<td>
39+
{% url 'core:repo-detail' full_name=repo.full_name as url %}
3940
<a class="flex justify-between hover:brightness-125"
40-
href="{{ repo.github_url }}">
41+
href="{{ url }}">
4142
<p>{{ repo.full_name }}</p>
4243
<p>
4344
{{ repo.stars_lately }}
@@ -117,8 +118,9 @@ <h3 class="text-lg font-bold">Top Packages</h3>
117118
{% for repo in top_apps %}
118119
<tr>
119120
<td>
121+
{% url 'core:repo-detail' full_name=repo.full_name as url %}
120122
<a class="flex justify-between hover:brightness-125"
121-
href="{{ repo.github_url }}">
123+
href="{{ url }}">
122124
<p>{{ repo.full_name }}</p>
123125
<p>
124126
{{ repo.stars }}

django_wtf/templates/core/search_table.html

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,49 @@ <h2 class="flex justify-between card-title">
2323
</div>
2424
</div>
2525
{% endfor %}
26-
<div class="flex w-100 justify-center mt-10 mb-5">
27-
<div class="join">
28-
{% if page_obj.has_previous %}
29-
<button class="join-item btn btn-neutral"
30-
hx-trigger="click"
31-
hx-include="[name='q'],[name='category']"
32-
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
33-
hx-push-url="true"
34-
hx-target="#search_table">
35-
<<
36-
</button>
37-
{% if page_obj.number > 2 %}
38-
<button class="join-item btn btn-neutral mr-3"
26+
{% if blog_pages.paginator.num_pages > 1 %}
27+
<div class="flex w-100 justify-center mt-10 mb-5">
28+
<div class="join">
29+
{% if page_obj.has_previous %}
30+
<button class="join-item btn btn-neutral"
3931
hx-trigger="click"
4032
hx-include="[name='q'],[name='category']"
41-
hx-get="{% url 'core:search' %}?page=1"
33+
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
4234
hx-push-url="true"
43-
hx-target="#search_table">1</button>
35+
hx-target="#search_table">
36+
<<
37+
</button>
38+
{% if page_obj.number > 2 %}
39+
<button class="join-item btn btn-neutral mr-3"
40+
hx-trigger="click"
41+
hx-include="[name='q'],[name='category']"
42+
hx-get="{% url 'core:search' %}?page=1"
43+
hx-push-url="true"
44+
hx-target="#search_table">1</button>
45+
{% endif %}
46+
<button class="join-item btn btn-neutral"
47+
hx-trigger="click"
48+
hx-include="[name='q'],[name='category']"
49+
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
50+
hx-push-url="true"
51+
hx-target="#search_table">{{ page_obj.previous_page_number }}</button>
4452
{% endif %}
45-
<button class="join-item btn btn-neutral"
46-
hx-trigger="click"
47-
hx-include="[name='q'],[name='category']"
48-
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
49-
hx-push-url="true"
50-
hx-target="#search_table">{{ page_obj.previous_page_number }}</button>
51-
{% endif %}
52-
<button class="join-item btn btn-neutral btn-active">{{ page_obj.number }}</button>
53-
{% if page_obj.has_next %}
54-
<button class="join-item btn btn-neutral"
55-
hx-trigger="click"
56-
hx-include="[name='q'],[name='category']"
57-
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
58-
hx-push-url="true"
59-
hx-target="#search_table">{{ page_obj.next_page_number }}</button>
60-
<button class="join-item btn btn-neutral"
61-
hx-trigger="click"
62-
hx-include="[name='q'],[name='category']"
63-
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
64-
hx-push-url="true"
65-
hx-target="#search_table">>></button>
66-
{% endif %}
53+
<button class="join-item btn btn-neutral btn-active">{{ page_obj.number }}</button>
54+
{% if page_obj.has_next %}
55+
<button class="join-item btn btn-neutral"
56+
hx-trigger="click"
57+
hx-include="[name='q'],[name='category']"
58+
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
59+
hx-push-url="true"
60+
hx-target="#search_table">{{ page_obj.next_page_number }}</button>
61+
<button class="join-item btn btn-neutral"
62+
hx-trigger="click"
63+
hx-include="[name='q'],[name='category']"
64+
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
65+
hx-push-url="true"
66+
hx-target="#search_table">>></button>
67+
{% endif %}
68+
</div>
6769
</div>
68-
</div>
70+
{% endif %}
6971
{% endif %}

django_wtf/templates/core/top_repositories.html

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@
1818
<tbody>
1919
{% for repo in page_obj %}
2020
<tr class="hover">
21-
{% with url=repo.github_url %}
22-
<td class="hidden xl:table-cell">
23-
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
24-
</td>
25-
<td>
26-
<a href="{{ url }}" target="_blank">
27-
{% if request|is_mobile or request|is_tablet %}
28-
{{ repo.full_name|truncatechars:25 }}
29-
{% else %}
30-
{{ repo.full_name }}
31-
{% endif %}
32-
</a>
33-
</td>
34-
<td class="hidden xl:table-cell">
35-
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:50 }}</a>
36-
</td>
37-
<td>
38-
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
39-
</td>
40-
{% endwith %}
21+
{% url 'core:repo-detail' full_name=repo.full_name as url %}
22+
<td class="hidden xl:table-cell">
23+
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
24+
</td>
25+
<td>
26+
<a href="{{ url }}" target="_blank">
27+
{% if request|is_mobile or request|is_tablet %}
28+
{{ repo.full_name|truncatechars:25 }}
29+
{% else %}
30+
{{ repo.full_name }}
31+
{% endif %}
32+
</a>
33+
</td>
34+
<td class="hidden xl:table-cell">
35+
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:50 }}</a>
36+
</td>
37+
<td>
38+
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
39+
</td>
4140
</tr>
4241
{% endfor %}
4342
</tbody>

django_wtf/templates/core/trending_repositories.html

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,27 @@
3939
<tbody>
4040
{% for repo in page_obj %}
4141
<tr class="hover">
42-
{% with url=repo.github_url %}
43-
<td class="hidden xl:table-cell">
44-
<a class="font-bold whitespace-normal" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
45-
</td>
46-
<td>
47-
<a href="{{ url }}" target="_blank">
48-
{% if request|is_mobile or request|is_tablet %}
49-
{{ repo.full_name|truncatechars:25 }}
50-
{% else %}
51-
{{ repo.full_name }}
52-
{% endif %}
53-
</a>
54-
</td>
55-
<td class="hidden xl:table-cell">
56-
<a href="{{ url }}" target="_blank" class="whitespace-normal">{{ repo.truncated_description|truncatechars:50 }}</a>
57-
</td>
58-
<td class="text-right">
59-
<a href="{{ url }}" target="_blank">
60-
<strong>{{ repo.percentage_increase | to_percent }}</strong> ({{ repo.stars_gained }})
61-
</a>
62-
</td>
63-
{% endwith %}
42+
{% url 'core:repo-detail' full_name=repo.full_name as url %}
43+
<td class="hidden xl:table-cell">
44+
<a class="font-bold whitespace-normal" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
45+
</td>
46+
<td>
47+
<a href="{{ url }}" target="_blank">
48+
{% if request|is_mobile or request|is_tablet %}
49+
{{ repo.full_name|truncatechars:25 }}
50+
{% else %}
51+
{{ repo.full_name }}
52+
{% endif %}
53+
</a>
54+
</td>
55+
<td class="hidden xl:table-cell">
56+
<a href="{{ url }}" target="_blank" class="whitespace-normal">{{ repo.truncated_description|truncatechars:50 }}</a>
57+
</td>
58+
<td class="text-right">
59+
<a href="{{ url }}" target="_blank">
60+
<strong>{{ repo.percentage_increase | to_percent }}</strong> ({{ repo.stars_gained }})
61+
</a>
62+
</td>
6463
</tr>
6564
{% endfor %}
6665
</tbody>

poetry.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ django-admin-shellx = "0.2.6"
5555
channels-redis = "^4.2.0"
5656
django-htmx = "^1.17.3"
5757
pygments = "^2.18.0"
58+
pypandoc-binary = "^1.13"
5859

5960
[tool.poetry.group.dev.dependencies]
6061
pudb = "^2022.1.3"

0 commit comments

Comments
 (0)