added anime entries from extensions
This commit is contained in:
@@ -12,7 +12,7 @@ searchInput.addEventListener('input', (e) => {
|
||||
return;
|
||||
}
|
||||
searchTimeout = setTimeout(() => {
|
||||
fetchLocalSearch(query);
|
||||
fetchSearh(query);
|
||||
}, 300);
|
||||
});
|
||||
|
||||
@@ -23,14 +23,25 @@ document.addEventListener('click', (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
async function fetchLocalSearch(query) {
|
||||
async function fetchSearh(query) {
|
||||
try {
|
||||
const res = await fetch(`/api/search/local?q=${encodeURIComponent(query)}`);
|
||||
const res = await fetch(`/api/search?q=${encodeURIComponent(query.slice(0, 30))}`);
|
||||
const data = await res.json();
|
||||
renderSearchResults(data.results);
|
||||
} catch (err) { console.error("Search Error:", err); }
|
||||
}
|
||||
|
||||
function createSlug(text) {
|
||||
if (!text) return '';
|
||||
return text
|
||||
.replace(/([a-z])([A-Z])/g, '$1 $2') // separa CamelCase
|
||||
.replace(/([a-z])(\d)/g, '$1 $2') // separa letras de números
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s-]/g, '')
|
||||
.replace(/[\s-]+/g, '-');
|
||||
}
|
||||
|
||||
function renderSearchResults(results) {
|
||||
searchResults.innerHTML = '';
|
||||
if (results.length === 0) {
|
||||
@@ -43,9 +54,24 @@ function renderSearchResults(results) {
|
||||
const year = anime.seasonYear || '';
|
||||
const format = anime.format || 'TV';
|
||||
|
||||
let href;
|
||||
|
||||
if (anime.isExtensionResult) {
|
||||
const titleSlug = createSlug(title);
|
||||
console.log(title);
|
||||
href = `/anime/${anime.extensionName}/${titleSlug}`;
|
||||
} else {
|
||||
href = `/anime/${anime.id}`;
|
||||
}
|
||||
|
||||
const extName = anime.extensionName?.charAt(0).toUpperCase() + anime.extensionName?.slice(1);
|
||||
const extPill = anime.isExtensionResult
|
||||
? `<span>• ${extName}</span>`
|
||||
: '';
|
||||
|
||||
const item = document.createElement('a');
|
||||
item.className = 'search-item';
|
||||
item.href = `/anime/${anime.id}`;
|
||||
item.href = href;
|
||||
item.innerHTML = `
|
||||
<img src="${img}" class="search-poster" alt="${title}">
|
||||
<div class="search-info">
|
||||
@@ -54,6 +80,7 @@ function renderSearchResults(results) {
|
||||
<span class="rating-pill">${rating}</span>
|
||||
<span>• ${year}</span>
|
||||
<span>• ${format}</span>
|
||||
${extPill}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user