Fix title on deleting query

This commit is contained in:
Daoud Clarke 2023-11-08 08:56:58 +00:00
parent ae39eb98e9
commit 6263e65bb9
6 changed files with 44 additions and 48 deletions

View file

@ -1,5 +1,28 @@
{% extends 'base.html' %}
{% block content %}
<h2>Welcome, {{ user.username }}!</h2>
{% endblock %}
{% load result_filters %}
{% include "title.html" %}
{% if results %}
{% for result in results %}
<li class="result" is="mwmbl-result">
<div class="result-container">
<div class="curation-buttons">
<button class="curation-button curate-delete" is="mwmbl-delete-button"></button>
<button class="curation-button curate-approve" is="mwmbl-validate-button"></button>
<button class="curation-button curate-add" is="mwmbl-add-button"></button>
</div>
<div class="result-link">
<a href="{{result.url}}">
<p class='link'>{{result.url}}</p>
<p class='title'>{{result.title|strengthen}}</p>
<p class='extract'>{{result.extract|strengthen}}</p>
</a>
</div>
</div>
</li>
{% endfor %}
{% else %}
<li class="home">
<h1>
Welcome to Mwmbl, the free, open-source and non-profit search engine.
</h1>
</li>
{% endif %}

View file

@ -8,12 +8,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Page title -->
{% if query %}
<title>Mwmbl - {{ query }}</title>
{% else %}
<title>Mwmbl - Search</title>
{% endif %}
{% include "title.html" %}
<meta name="description" content="The free, open-source and non-profit search engine.">
<!-- Favicons -->
@ -69,7 +64,7 @@
placeholder='Search on Mwmbl...'
title='Use "CTRL+K" or "/" to focus.'
autocomplete='off'
hx-get="/app/search/"
hx-get="/app/home/"
hx-trigger="keyup changed delay:100ms"
hx-target=".results"
>
@ -86,7 +81,7 @@
<main>
<mwmbl-results>
<ul class='results'>
{% include "results.html" %}
{% include "home.html" %}
</ul>
</mwmbl-results>
</main>

View file

@ -1,28 +0,0 @@
{% load result_filters %}
<title>Mwmbl - {{ query }}</title>
{% if results %}
{% for result in results %}
<li class="result" is="mwmbl-result">
<div class="result-container">
<div class="curation-buttons">
<button class="curation-button curate-delete" is="mwmbl-delete-button"></button>
<button class="curation-button curate-approve" is="mwmbl-validate-button"></button>
<button class="curation-button curate-add" is="mwmbl-add-button"></button>
</div>
<div class="result-link">
<a href="{{result.url}}">
<p class='link'>{{result.url}}</p>
<p class='title'>{{result.title|strengthen}}</p>
<p class='extract'>{{result.extract|strengthen}}</p>
</a>
</div>
</div>
</li>
{% endfor %}
{% else %}
<li class="home">
<h1>
Welcome to Mwmbl, the free, open-source and non-profit search engine.
</h1>
</li>
{% endif %}

View file

@ -0,0 +1,6 @@
<!-- Page title -->
{% if query %}
<title>Mwmbl - {{ query }}</title>
{% else %}
<title>Mwmbl - Search</title>
{% endif %}

View file

@ -18,14 +18,14 @@ from django.contrib import admin
from django.urls import path, include
from mwmbl.api import api_v1
from mwmbl.views import search_results, fetch_url, home
from mwmbl.views import home_fragment, fetch_url, index
urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/', api_v1.urls),
path('accounts/', include('allauth.urls')),
path('', home, name="home"),
path('app/search/', search_results, name="search_results"),
path('', index, name="home"),
path('app/home/', home_fragment, name="home"),
path('app/fetch/', fetch_url, name="fetch_url")
]

View file

@ -41,7 +41,7 @@ def justext_with_dom(html_text, stoplist, length_low=LENGTH_LOW_DEFAULT,
return paragraphs, title
def home(request):
def index(request):
query = request.GET.get("q")
results = ranker.search(query) if query else None
return render(request, "index.html", {
@ -51,10 +51,10 @@ def home(request):
})
def search_results(request):
def home_fragment(request):
query = request.GET["q"]
results = ranker.search(query)
response = render(request, "results.html", {"results": results, "query": query})
response = render(request, "home.html", {"results": results, "query": query})
current_url = request.htmx.current_url
# Replace query string with new query
stripped_url = current_url[:current_url.index("?")] if "?" in current_url else current_url
@ -77,7 +77,7 @@ def fetch_url(request):
extract = extract[:NUM_EXTRACT_CHARS - 1] + ''
result = Document(title=title, url=url, extract=extract, score=0.0)
return render(request, "results.html", {
return render(request, "home.html", {
"results": [format_result(result, query)],
"query": query,
})