diff --git a/django_wtf/core/github_tasks.py b/django_wtf/core/github_tasks.py index 676d0ab..289354d 100644 --- a/django_wtf/core/github_tasks.py +++ b/django_wtf/core/github_tasks.py @@ -3,6 +3,7 @@ from datetime import date import markdown +import pypandoc import superrequests from constance import config from django.db.utils import DataError @@ -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"] diff --git a/django_wtf/templates/core/category_detail.html b/django_wtf/templates/core/category_detail.html index fc22ba1..72c29a5 100644 --- a/django_wtf/templates/core/category_detail.html +++ b/django_wtf/templates/core/category_detail.html @@ -23,29 +23,28 @@ {% for repo in page_obj %} - {% with url=repo.github_url %} - - {{ page_obj.start_index|add:forloop.counter0 }} - - - - {% if request|is_mobile or request|is_tablet %} - {{ repo.full_name|truncatechars:30 }} - {% else %} - {{ repo.full_name }} - {% endif %} - - - -
- {{ repo.truncated_description|truncatechars:60 }} -
- - - {{ repo.stars }} - - {% endwith %} + {% url 'core:repo-detail' full_name=repo.full_name as url %} + + {{ page_obj.start_index|add:forloop.counter0 }} + + + + {% if request|is_mobile or request|is_tablet %} + {{ repo.full_name|truncatechars:30 }} + {% else %} + {{ repo.full_name }} + {% endif %} + + + +
+ {{ repo.truncated_description|truncatechars:60 }} +
+ + + {{ repo.stars }} + {% endfor %} diff --git a/django_wtf/templates/core/index.html b/django_wtf/templates/core/index.html index 25b20b6..6f0bdc2 100644 --- a/django_wtf/templates/core/index.html +++ b/django_wtf/templates/core/index.html @@ -36,8 +36,8 @@

Trending Packages

{% for repo in trending_apps %} - + {% url 'core:repo-detail' full_name=repo.full_name as url %} +

{{ repo.full_name }}

{{ repo.stars_lately }} @@ -117,8 +117,8 @@

Top Packages

{% for repo in top_apps %} -
+ {% url 'core:repo-detail' full_name=repo.full_name as url %} +

{{ repo.full_name }}

{{ repo.stars }} diff --git a/django_wtf/templates/core/search_table.html b/django_wtf/templates/core/search_table.html index 05302e2..638b45e 100644 --- a/django_wtf/templates/core/search_table.html +++ b/django_wtf/templates/core/search_table.html @@ -23,47 +23,49 @@

{% endfor %} -
-
- {% if page_obj.has_previous %} - - {% if page_obj.number > 2 %} - + hx-target="#search_table"> + << + + {% if page_obj.number > 2 %} + + {% endif %} + {% endif %} - - {% endif %} - - {% if page_obj.has_next %} - - - {% endif %} + + {% if page_obj.has_next %} + + + {% endif %} +
- + {% endif %} {% endif %} diff --git a/django_wtf/templates/core/top_repositories.html b/django_wtf/templates/core/top_repositories.html index ac183b6..45bcfa2 100644 --- a/django_wtf/templates/core/top_repositories.html +++ b/django_wtf/templates/core/top_repositories.html @@ -18,26 +18,25 @@ {% for repo in page_obj %} - {% with url=repo.github_url %} - -
{{ page_obj.start_index|add:forloop.counter0 }} - - - - {% if request|is_mobile or request|is_tablet %} - {{ repo.full_name|truncatechars:25 }} - {% else %} - {{ repo.full_name }} - {% endif %} - - - - {{ repo.truncated_description|truncatechars:50 }} - - - {{ repo.stars }} - - {% endwith %} + {% url 'core:repo-detail' full_name=repo.full_name as url %} + + {{ page_obj.start_index|add:forloop.counter0 }} + + + + {% if request|is_mobile or request|is_tablet %} + {{ repo.full_name|truncatechars:25 }} + {% else %} + {{ repo.full_name }} + {% endif %} + + + + {{ repo.truncated_description|truncatechars:50 }} + + + {{ repo.stars }} + {% endfor %} diff --git a/django_wtf/templates/core/trending_repositories.html b/django_wtf/templates/core/trending_repositories.html index eb19132..bab5c6b 100644 --- a/django_wtf/templates/core/trending_repositories.html +++ b/django_wtf/templates/core/trending_repositories.html @@ -39,28 +39,27 @@ {% for repo in page_obj %} - {% with url=repo.github_url %} - - {{ page_obj.start_index|add:forloop.counter0 }} - - - - {% if request|is_mobile or request|is_tablet %} - {{ repo.full_name|truncatechars:25 }} - {% else %} - {{ repo.full_name }} - {% endif %} - - - - {{ repo.truncated_description|truncatechars:50 }} - - - - {{ repo.percentage_increase | to_percent }} ({{ repo.stars_gained }}) - - - {% endwith %} + {% url 'core:repo-detail' full_name=repo.full_name as url %} + + {{ page_obj.start_index|add:forloop.counter0 }} + + + + {% if request|is_mobile or request|is_tablet %} + {{ repo.full_name|truncatechars:25 }} + {% else %} + {{ repo.full_name }} + {% endif %} + + + + {{ repo.truncated_description|truncatechars:50 }} + + + + {{ repo.percentage_increase | to_percent }} ({{ repo.stars_gained }}) + + {% endfor %} diff --git a/poetry.lock b/poetry.lock index 61656eb..8ab6587 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3456,6 +3456,22 @@ cryptography = ">=41.0.5,<43" docs = ["sphinx (!=5.2.0,!=5.2.0.post0,!=7.2.5)", "sphinx-rtd-theme"] test = ["pretend", "pytest (>=3.0.1)", "pytest-rerunfailures"] +[[package]] +name = "pypandoc-binary" +version = "1.13" +description = "Thin wrapper for pandoc." +optional = false +python-versions = ">=3.6" +files = [ + {file = "pypandoc_binary-1.13-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:946666388eb79b307d7f497b3b33045ef807750f8e5ef3440e0ba3bbab698044"}, + {file = "pypandoc_binary-1.13-py3-none-macosx_11_0_arm64.whl", hash = "sha256:21ef0345726d36fc45a50211320614daf2caede684b0d0963ce8738292809746"}, + {file = "pypandoc_binary-1.13-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:67c0c7af811bcf3cd4f3221be756a4975ec35b2d7df89d8de4313a8caa2cd54f"}, + {file = "pypandoc_binary-1.13-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9455fdd9521cbf4b56d79a56b806afa94c8c22f3c8ef878536e58d941a70f6d6"}, + {file = "pypandoc_binary-1.13-py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:2915f52e4632bd2d0a8fcd2f7e7dfc2ea19b4e1a280fcbc2ddcd142713c4ff12"}, + {file = "pypandoc_binary-1.13-py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:11a2497320eb3dccb74de3c67b6df3e5d3f66cdc2a36a67e9a871708f7e48412"}, + {file = "pypandoc_binary-1.13-py3-none-win_amd64.whl", hash = "sha256:3881aa7c84faec2007c0ae4466d3a1cfc93171206b8540f2defa8ea971bf6fd6"}, +] + [[package]] name = "pyquery" version = "2.0.0" @@ -4969,4 +4985,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "daf86638dc3bc2eb1925c5dffb7ea3b15cfa7019555c0ee15d3bb064e85f7c46" +content-hash = "2c73e0a59065b9240b645f3abc59e54180497f0e691fde4abf78664065948f99" diff --git a/pyproject.toml b/pyproject.toml index bcd97f5..4f87a9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"