Skip to content

Commit

Permalink
Merge pull request #234 from honeylogic-io/add-rst-parsing-move-links…
Browse files Browse the repository at this point in the history
…-to-detail

feat: Add rst document parsing; move links to detail
  • Loading branch information
adinhodovic authored May 31, 2024
2 parents 9da97e1 + c327ff4 commit 6c1ece4
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 111 deletions.
19 changes: 16 additions & 3 deletions django_wtf/core/github_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import date

import markdown
import pypandoc
import superrequests
from constance import config
from django.db.utils import DataError
Expand Down Expand Up @@ -112,14 +113,26 @@ def index_repository_readme(repo_full_name):
res = http.get(
f"https://api.github.com/repos/{repo_full_name}/contents/README.md"
)
markdown_text = b64decode(res.json()["content"]).decode("utf-8")
except HTTPError as ex:
if ex.response.status_code == 404:
logging.info(f"{repo_full_name} has no README.md file")
return
logging.info("Trying README.rst")

try:
res = http.get(
f"https://api.github.com/repos/{repo_full_name}/contents/README.rst"
)
rst_text = b64decode(res.json()["content"]).decode("utf-8")
markdown_text = pypandoc.convert_text(rst_text, "md", format="rst")
return
except HTTPError as rst_ex:
if ex.response.status_code == 404:
logging.info(f"{repo_full_name} has no README.rst file")
return
raise rst_ex
raise ex

markdown_text = b64decode(res.json()["content"]).decode("utf-8")

repo = Repository.objects.get(full_name=repo_full_name)
repo.readme_html = markdown.markdown(
markdown_text, extensions=["extra", "codehilite"]
Expand Down
45 changes: 22 additions & 23 deletions django_wtf/templates/core/category_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,28 @@
<tbody>
{% for repo in page_obj %}
<tr class="hover">
{% with url=repo.github_url %}
<td class="hidden xl:table-cell">
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:30 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<div class="tooltip tooltip-primary before:content-[attr(data-tip)] before:max-w-[50rem]"
data-tip="{{ repo.truncated_description }}">
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:60 }}</a>
</div>
</td>
<td>
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
</td>
{% endwith %}
{% url 'core:repo-detail' full_name=repo.full_name as url %}
<td class="hidden xl:table-cell">
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:30 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<div class="tooltip tooltip-primary before:content-[attr(data-tip)] before:max-w-[50rem]"
data-tip="{{ repo.truncated_description }}">
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:60 }}</a>
</div>
</td>
<td>
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 4 additions & 4 deletions django_wtf/templates/core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ <h3 class="text-lg font-bold">Trending Packages</h3>
{% for repo in trending_apps %}
<tr>
<td>
<a class="flex justify-between hover:brightness-125"
href="{{ repo.github_url }}">
{% url 'core:repo-detail' full_name=repo.full_name as url %}
<a class="flex justify-between hover:brightness-125" href="{{ url }}">
<p>{{ repo.full_name }}</p>
<p>
{{ repo.stars_lately }}
Expand Down Expand Up @@ -117,8 +117,8 @@ <h3 class="text-lg font-bold">Top Packages</h3>
{% for repo in top_apps %}
<tr>
<td>
<a class="flex justify-between hover:brightness-125"
href="{{ repo.github_url }}">
{% url 'core:repo-detail' full_name=repo.full_name as url %}
<a class="flex justify-between hover:brightness-125" href="{{ url }}">
<p>{{ repo.full_name }}</p>
<p>
{{ repo.stars }}
Expand Down
78 changes: 40 additions & 38 deletions django_wtf/templates/core/search_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,49 @@ <h2 class="flex justify-between card-title">
</div>
</div>
{% endfor %}
<div class="flex w-100 justify-center mt-10 mb-5">
<div class="join">
{% if page_obj.has_previous %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
hx-push-url="true"
hx-target="#search_table">
<<
</button>
{% if page_obj.number > 2 %}
<button class="join-item btn btn-neutral mr-3"
{% if blog_pages.paginator.num_pages > 1 %}
<div class="flex w-100 justify-center mt-10 mb-5">
<div class="join">
{% if page_obj.has_previous %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page=1"
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
hx-push-url="true"
hx-target="#search_table">1</button>
hx-target="#search_table">
<<
</button>
{% if page_obj.number > 2 %}
<button class="join-item btn btn-neutral mr-3"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page=1"
hx-push-url="true"
hx-target="#search_table">1</button>
{% endif %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
hx-push-url="true"
hx-target="#search_table">{{ page_obj.previous_page_number }}</button>
{% endif %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.previous_page_number }}"
hx-push-url="true"
hx-target="#search_table">{{ page_obj.previous_page_number }}</button>
{% endif %}
<button class="join-item btn btn-neutral btn-active">{{ page_obj.number }}</button>
{% if page_obj.has_next %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
hx-push-url="true"
hx-target="#search_table">{{ page_obj.next_page_number }}</button>
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
hx-push-url="true"
hx-target="#search_table">>></button>
{% endif %}
<button class="join-item btn btn-neutral btn-active">{{ page_obj.number }}</button>
{% if page_obj.has_next %}
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
hx-push-url="true"
hx-target="#search_table">{{ page_obj.next_page_number }}</button>
<button class="join-item btn btn-neutral"
hx-trigger="click"
hx-include="[name='q'],[name='category']"
hx-get="{% url 'core:search' %}?page={{ page_obj.next_page_number }}"
hx-push-url="true"
hx-target="#search_table">>></button>
{% endif %}
</div>
</div>
</div>
{% endif %}
{% endif %}
39 changes: 19 additions & 20 deletions django_wtf/templates/core/top_repositories.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@
<tbody>
{% for repo in page_obj %}
<tr class="hover">
{% with url=repo.github_url %}
<td class="hidden xl:table-cell">
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:25 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:50 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
</td>
{% endwith %}
{% url 'core:repo-detail' full_name=repo.full_name as url %}
<td class="hidden xl:table-cell">
<a class="font-bold" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:25 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<a href="{{ url }}" target="_blank">{{ repo.truncated_description|truncatechars:50 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">{{ repo.stars }}</a>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
43 changes: 21 additions & 22 deletions django_wtf/templates/core/trending_repositories.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,27 @@
<tbody>
{% for repo in page_obj %}
<tr class="hover">
{% with url=repo.github_url %}
<td class="hidden xl:table-cell">
<a class="font-bold whitespace-normal" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:25 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<a href="{{ url }}" target="_blank" class="whitespace-normal">{{ repo.truncated_description|truncatechars:50 }}</a>
</td>
<td class="text-right">
<a href="{{ url }}" target="_blank">
<strong>{{ repo.percentage_increase | to_percent }}</strong> ({{ repo.stars_gained }})
</a>
</td>
{% endwith %}
{% url 'core:repo-detail' full_name=repo.full_name as url %}
<td class="hidden xl:table-cell">
<a class="font-bold whitespace-normal" href="{{ url }}" target="_blank">{{ page_obj.start_index|add:forloop.counter0 }}</a>
</td>
<td>
<a href="{{ url }}" target="_blank">
{% if request|is_mobile or request|is_tablet %}
{{ repo.full_name|truncatechars:25 }}
{% else %}
{{ repo.full_name }}
{% endif %}
</a>
</td>
<td class="hidden xl:table-cell">
<a href="{{ url }}" target="_blank" class="whitespace-normal">{{ repo.truncated_description|truncatechars:50 }}</a>
</td>
<td class="text-right">
<a href="{{ url }}" target="_blank">
<strong>{{ repo.percentage_increase | to_percent }}</strong> ({{ repo.stars_gained }})
</a>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ django-admin-shellx = "0.2.6"
channels-redis = "^4.2.0"
django-htmx = "^1.17.3"
pygments = "^2.18.0"
pypandoc-binary = "^1.13"

[tool.poetry.group.dev.dependencies]
pudb = "^2022.1.3"
Expand Down

0 comments on commit 6c1ece4

Please sign in to comment.