77
| <![CDATA[<script type="module">
import {Paginator} from './public/js/paginator.js';
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let busca;
if(urlParams.has('busca')){
busca = urlParams.get('busca');
//busca = busca.replace(/[^a-zA-Z0-9 ]/g, '');
busca = busca
.toString()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.trim()
.replace(/[^a-z0-9 \/-]/g, '')
.replace(/\s+/g, ' ');
busca = '&busca=' + busca;
}
const goToPage = (page) =>{
fetchData('news/?page=' + page + '&perpage=18' + busca).then(response => {
let {current, next, prev, pages} = response.pagination;
let el = document.querySelector('.pagination');
const pagin = new Paginator(el, next, prev, pages, 11, goToPage);
pagin.mount(current);
const boxNews = document.querySelector('.list-news');
let news = '';
response.data.forEach(obj => {
let {idNoticia, nomeCategoria, tituloNoticia, fotoPrincipal} = obj;
let img = fotoPrincipal && fotoPrincipal.toLowerCase() != 'x' ? `<img src="${env.URL_TMP}arquivosNoticiasInterna/${fotoPrincipal}" alt="${tituloNoticia}">` : '';
news += `<article class="box-news">
<a href="${env.URL + 'noticia/' + idNoticia + '/' + slugify(tituloNoticia)}">
${img}
<span class="title">${tituloNoticia}</span>
</a>
</article>`;
});
boxNews.innerHTML = news;
});
}
goToPage(1);
/*
news += `<article class="box-news">
<a href="${env.URL + 'noticia/' + idNoticia + '/' + slugify(tituloNoticia)}">
<img src="${env.URL_TMP}arquivosNoticiasInterna/${fotoPrincipal}" alt="${tituloNoticia}">
<span class="category">${nomeCategoria}</span>
<span class="title">${tituloNoticia}</span>
</a>
</article>`;
*/
</script>]]>
|