tipue_search: add authorUrl
This commit is contained in:
parent
63440b53b8
commit
c4c03e563a
@ -13,6 +13,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import json
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from codecs import open
|
||||
try:
|
||||
@ -36,6 +37,23 @@ class Tipue_Search_JSON_Generator(object):
|
||||
self.output_path = output_path
|
||||
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):
|
||||
|
||||
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 = ' '.join(video_text.split())
|
||||
|
||||
# base url
|
||||
if self.relative_urls:
|
||||
image_url = '.'
|
||||
base_url = '.'
|
||||
else:
|
||||
image_url = self.siteurl
|
||||
base_url = self.siteurl
|
||||
|
||||
# thumbnail
|
||||
video_image = article.image if getattr(
|
||||
article, 'image', 'None') != 'None' else ''
|
||||
|
||||
url_image = "%s/%s/../wp-content/uploads/article/poster/%s" % (
|
||||
image_url, self.tstatic, video_image
|
||||
base_url, self.tstatic, video_image
|
||||
)
|
||||
|
||||
# publish
|
||||
@ -69,6 +88,11 @@ class Tipue_Search_JSON_Generator(object):
|
||||
video_author = str(article.author) if getattr(
|
||||
article, 'author', 'None') != 'None' else ''
|
||||
|
||||
# author url
|
||||
video_author_url = "%s/author/%s/" % (
|
||||
base_url, self.normalize(video_author)
|
||||
)
|
||||
|
||||
# time
|
||||
video_time = article.time if getattr(
|
||||
article, 'time', 'None') != 'None' else ''
|
||||
@ -91,6 +115,7 @@ class Tipue_Search_JSON_Generator(object):
|
||||
'url': video_src,
|
||||
},
|
||||
'author': video_author,
|
||||
'authorUrl': video_author_url,
|
||||
'publishedText': video_publish,
|
||||
'time': video_time,
|
||||
'tags': video_category,
|
||||
|
Loading…
x
Reference in New Issue
Block a user