From 4cf449d81eef449882418dfd87a581449b292121 Mon Sep 17 00:00:00 2001 From: Izidorio Date: Tue, 28 Jul 2020 21:01:31 -0300 Subject: [PATCH] fix bug scrape tag title, description --- src/App.vue | 2 +- src/components/FormNews.vue | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8984659..e08a6d5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -72,7 +72,7 @@ export default { this.$refs.form.show() }, onDelete(id){ - Alert.warning('Confgiirma a remoção da notícia?', 'Remover') + Alert.warning('Confirma a remoção da notícia?', 'Remover') .then( result => { if(result.value){ this.$store.dispatch('clipping/destroyNews', id) diff --git a/src/components/FormNews.vue b/src/components/FormNews.vue index 49abea6..7a4f3e1 100644 --- a/src/components/FormNews.vue +++ b/src/components/FormNews.vue @@ -167,14 +167,25 @@ .then( result => { //hack para resolver html minificados - const html = result.data.replace(/">|"\/>|" \/>/g,'">\n'); + let html = result.data.replace(/'/g,'"'); + html = html.replace(/">|"\/>|" \/>/g,'">\n'); - const rgxTitle = /"og:title" content="(.*)"/; - const rgxDesc = /"og:description" content="(.*)"/; + let rgxTitle = /"og:title"(.*)content="(.*)"/; + let rgxDesc = /"og:description"(.*)content="(.*)"/; + + let title = rgxTitle.exec(html); + let desc = rgxDesc.exec(html); + + if(title && desc){ + this.form.description = convertHTMLEntity(`${title[2]} ${desc[2]}`) + } else { + rgxTitle = /content="(.*)" (.*)og:title/; + rgxDesc = /content="(.*)" (.*)og:description/; + title = rgxTitle.exec(html); + desc = rgxDesc.exec(html); + this.form.description = convertHTMLEntity(`${title[1]} ${desc[1]}`) + } - const title = rgxTitle.exec(html); - const desc = rgxDesc.exec(html); - this.form.description = convertHTMLEntity(`${title[1]} ${desc[1]}`) }) .catch( ()=> { this.$bvToast.toast('É possível que tenha atingido a quantidade de requisições por minuto. Aguarde ou insira o resumo manualmente. Acesse o github do desenvolvedor e saiba como criar um servidor Proxy CORS', {