tipue_search: add authorUrl

This commit is contained in:
Jesús 2020-06-11 09:57:27 -05:00
parent 63440b53b8
commit c4c03e563a
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -13,6 +13,7 @@ from __future__ import unicode_literals
import os.path import os.path
import json import json
import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from codecs import open from codecs import open
try: try:
@ -36,6 +37,23 @@ class Tipue_Search_JSON_Generator(object):
self.output_path = output_path self.output_path = output_path
self.json_nodes = [] self.json_nodes = []
def normalize(self, s):
replacements = (
("á", "a"),
("é", "e"),
("í", "i"),
("ó", "o"),
("ú", "u"),
(".", ""),
)
s = s.lower()
for a, b in replacements:
s = s.replace(a, b).replace(a.lower(), b.lower())
s = re.sub(r"([a-z]) ([a-z])", r"\1-\2", s, 0,
re.IGNORECASE | re.DOTALL)
return s
def create_json_node(self, article): def create_json_node(self, article):
if getattr(article, 'status', 'published') != 'published': if getattr(article, 'status', 'published') != 'published':
@ -48,17 +66,18 @@ class Tipue_Search_JSON_Generator(object):
video_text = soup_text.get_text(' ', strip=True).replace('', '"').replace('', '"').replace('', "'").replace('', ' ').replace('^', '^') video_text = soup_text.get_text(' ', strip=True).replace('', '"').replace('', '"').replace('', "'").replace('', ' ').replace('^', '^')
video_text = ' '.join(video_text.split()) video_text = ' '.join(video_text.split())
# base url
if self.relative_urls: if self.relative_urls:
image_url = '.' base_url = '.'
else: else:
image_url = self.siteurl base_url = self.siteurl
# thumbnail # thumbnail
video_image = article.image if getattr( video_image = article.image if getattr(
article, 'image', 'None') != 'None' else '' article, 'image', 'None') != 'None' else ''
url_image = "%s/%s/../wp-content/uploads/article/poster/%s" % ( url_image = "%s/%s/../wp-content/uploads/article/poster/%s" % (
image_url, self.tstatic, video_image base_url, self.tstatic, video_image
) )
# publish # publish
@ -69,6 +88,11 @@ class Tipue_Search_JSON_Generator(object):
video_author = str(article.author) if getattr( video_author = str(article.author) if getattr(
article, 'author', 'None') != 'None' else '' article, 'author', 'None') != 'None' else ''
# author url
video_author_url = "%s/author/%s/" % (
base_url, self.normalize(video_author)
)
# time # time
video_time = article.time if getattr( video_time = article.time if getattr(
article, 'time', 'None') != 'None' else '' article, 'time', 'None') != 'None' else ''
@ -91,6 +115,7 @@ class Tipue_Search_JSON_Generator(object):
'url': video_src, 'url': video_src,
}, },
'author': video_author, 'author': video_author,
'authorUrl': video_author_url,
'publishedText': video_publish, 'publishedText': video_publish,
'time': video_time, 'time': video_time,
'tags': video_category, 'tags': video_category,