search5 0.3.2

search5 - Local File Search Engine
<!DOCTYPE html>
<html lang="zh-TW">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>搜尋結果 - search5</title>
    <script src="https://unpkg.com/htmx.org@1.9.10"></script>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="max-w-4xl mx-auto px-4 py-8">
        <form action="/search" method="get" class="mb-8">
            <div class="flex gap-2">
                <input
                    type="text"
                    name="q"
                    value="{{ query }}"
                    placeholder="輸入關鍵字搜尋..."
                    class="flex-1 px-6 py-4 text-lg border-2 border-gray-300 rounded-lg focus:border-blue-500 focus:outline-none"
                    required
                >
                <button
                    type="submit"
                    class="px-8 py-4 bg-blue-600 text-white text-lg font-semibold rounded-lg hover:bg-blue-700 transition"
                >
                    搜尋
                </button>
            </div>
        </form>

        {% if query %}
        <div class="bg-white rounded-lg shadow p-4 mb-6">
            <p class="text-gray-600">
                {% if results %}
                    找到 <span class="font-bold text-blue-600">{{ total_results }}</span> 個結果
                {% else %}
                    找到 <span class="font-bold text-gray-600">0</span> 個結果
                {% endif %}
            </p>
        </div>

        {% if results %}
        <div class="space-y-4 mb-6">
            {% for result in results %}
            <div class="bg-white rounded-lg shadow p-6 hover:shadow-lg transition">
                <a href="{{ result.url }}" class="text-xl font-semibold text-blue-600 hover:underline block mb-2">
                    {{ result.title }}
                </a>
                <p class="text-gray-600 text-sm mb-2">{{ result.url }}</p>
                <p class="text-gray-700">{{ result.snippet }}</p>
            </div>
            {% endfor %}
        </div>

        {% if total_pages > 1 %}
        <div class="flex justify-center gap-2">
            {% if current_page > 1 %}
            <a href="/search?q={{ query }}&page={{ current_page - 1 }}"
               class="px-4 py-2 bg-white border rounded-lg hover:bg-gray-100">
                上一頁
            </a>
            {% endif %}

            <span class="px-4 py-2">
                {{ current_page }} / {{ total_pages }}
            </span>

            {% if current_page < total_pages %}
            <a href="/search?q={{ query }}&page={{ current_page + 1 }}"
               class="px-4 py-2 bg-white border rounded-lg hover:bg-gray-100">
                下一頁
            </a>
            {% endif %}
        </div>
        {% endif %}

        {% else %}
        <div class="bg-yellow-50 border border-yellow-200 rounded-lg p-6">
            <p class="text-yellow-800">
                沒有找到符合「<strong>{{ query }}</strong>」的結果
            </p>
            <p class="text-yellow-600 text-sm mt-2">
                建議:請檢查關鍵字是否正確,或嘗試不同的關鍵字
            </p>
        </div>
        {% endif %}

        {% else %}
        <div class="bg-blue-50 border border-blue-200 rounded-lg p-6">
            <p class="text-blue-800">
                請輸入關鍵字進行搜尋
            </p>
        </div>
        {% endif %}

        <div class="mt-8 text-center">
            <a href="/" class="text-blue-600 hover:underline">← 返回首頁</a>
        </div>
    </div>
</body>
</html>