diff options
| author | Bobby <[email protected]> | 2024-09-04 22:39:12 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-09-04 22:39:12 -0400 |
| commit | d92fd37895e017166c662c12a03db80a4ea5575b (patch) | |
| tree | ad8db9399d41a1a7fcf5df6340478d2e29daab2d | |
| parent | 79d2dd22d7ee345bae15c88487b88a892a508f88 (diff) | |
| download | yugen-d92fd37895e017166c662c12a03db80a4ea5575b.tar.xz yugen-d92fd37895e017166c662c12a03db80a4ea5575b.zip | |
remove trailing slash
| -rw-r--r-- | detail/urls.py | 2 | ||||
| -rw-r--r-- | homepage/urls.py | 3 | ||||
| -rw-r--r-- | homepage/views.py | 5 | ||||
| -rw-r--r-- | middleware/remove_slash.py | 10 | ||||
| -rw-r--r-- | templates/home/search.html | 0 | ||||
| -rw-r--r-- | templates/partials/navbar.html | 30 | ||||
| -rw-r--r-- | yugen/settings.py | 3 |
7 files changed, 43 insertions, 10 deletions
diff --git a/detail/urls.py b/detail/urls.py index ca85152..6bb7829 100644 --- a/detail/urls.py +++ b/detail/urls.py @@ -4,5 +4,5 @@ from . import views app_name = "detail" urlpatterns = [ - path('<int:anime_id>/', views.detail, name='detail'), + path('<int:anime_id>', views.detail, name='detail'), ] diff --git a/homepage/urls.py b/homepage/urls.py index f6000ff..9fab287 100644 --- a/homepage/urls.py +++ b/homepage/urls.py @@ -5,5 +5,6 @@ from . import views app_name = "home" urlpatterns = [ path("", views.index, name="index"), - path("q_search/", views.search_json, name="q_search"), + path("search", views.search, name="search"), + path("q_search", views.search_json, name="q_search"), ] diff --git a/homepage/views.py b/homepage/views.py index 2bca4df..e2ff33d 100644 --- a/homepage/views.py +++ b/homepage/views.py @@ -51,6 +51,11 @@ def index(request): return render(request, "home/index.html", context) + +def search(request): + return render(request, "home/search.html") + + def gather_watch_history(user, limit=None): history = UserHistory.objects.filter(user=user, last_watched=True).order_by("-last_updated") if limit: diff --git a/middleware/remove_slash.py b/middleware/remove_slash.py new file mode 100644 index 0000000..15be769 --- /dev/null +++ b/middleware/remove_slash.py @@ -0,0 +1,10 @@ +from django.http import HttpResponsePermanentRedirect + +class RemoveSlashMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + if request.path != '/' and request.path.endswith('/'): + return HttpResponsePermanentRedirect(request.path[:-1]) + return self.get_response(request)
\ No newline at end of file diff --git a/templates/home/search.html b/templates/home/search.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/templates/home/search.html diff --git a/templates/partials/navbar.html b/templates/partials/navbar.html index 35cb7a1..381980c 100644 --- a/templates/partials/navbar.html +++ b/templates/partials/navbar.html @@ -183,7 +183,7 @@ id="mobile-search" placeholder="Search Anime" class="bg-neutral-900 text-white text-sm w-full outline-none focus:outline-none border border-neutral-800 rounded-lg pl-4 py-3 pr-12" - onkeyup="handleSearchInput('mobile')" + onkeyup="handleSearchInput(event, 'mobile')" onfocus="handleInputFocus('mobile')" onblur="handleBlur('mobile')" /> @@ -216,17 +216,18 @@ type="text" placeholder="Search Anime" class="bg-neutral-900 text-white text-sm lg:w-60 xl:w-96 outline-none focus:outline-none border border-neutral-800 rounded-lg pl-4 py-3 pr-12" - onkeyup="handleSearchInput('desktop')" + onkeyup="handleSearchInput(event, 'desktop')" onfocus="handleInputFocus('desktop')" onblur="handleBlur('desktop')" /> - <svg + <svg id="search-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" - class="size-6 inline-block transform -translate-x-10" + class="size-6 inline-block transform -translate-x-10 cursor-pointer" + onclick="handleSearchIconClick('desktop')" > <path stroke-linecap="round" @@ -455,9 +456,17 @@ }, 200); // Adjust the delay as needed } - function handleSearchInput(platform) { + function handleSearchInput(event, platform) { const searchInput = document.getElementById(platform + "-search"); - const query = searchInput.value; + const query = searchInput.value.trim(); + + // Handle Enter key press immediately + if (event.key === "Enter" && query) { + event.preventDefault(); + window.location.href = "{% url 'home:search' %}?q=" + encodeURIComponent(query); + return; + } + if (query) { debounce(async () => { const results = await getAnimeSearchResult(query); @@ -472,6 +481,14 @@ toggleDropdown(false, platform); } } + + function handleSearchIconClick(platform) { + const searchInput = document.getElementById(platform + "-search"); + const query = searchInput.value.trim(); + if (query) { + window.location.href = "{% url 'home:search' %}?q=" + encodeURIComponent(query); + } + } function handleInputFocus(platform) { const searchInput = document.getElementById(platform + "-search"); @@ -517,7 +534,6 @@ } function toggleDropdown(show, platform) { - console.log("Toggling dropdown:", show, platform); const dropdownId = platform === "mobile" ? "mobile-dropdown" : "desktop-dropdown"; document.getElementById(dropdownId).classList.toggle("hidden", !show); diff --git a/yugen/settings.py b/yugen/settings.py index 07052b9..445c2fb 100644 --- a/yugen/settings.py +++ b/yugen/settings.py @@ -33,7 +33,7 @@ ALLOWED_HOSTS = ["127.0.0.1", "localhost", ".vercel.app", ".rize.moe"] AUTH_USER_MODEL = "authentication.User" X_FRAME_OPTIONS = "SAMEORIGIN" - +APPEND_SLASH = False CORS_ALLOWED_ORIGINS = [ "https://www.youtube.com", ] @@ -63,6 +63,7 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.gzip.GZipMiddleware", + "middleware.remove_slash.RemoveSlashMiddleware", "middleware.authentication.AuthMiddleware", "middleware.preferences.PreferencesMiddleware", ] |
