Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unicode characters from search index #151

Merged
merged 3 commits into from
May 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_index():
if not os.path.isdir(config.web_directory):
os.makedirs(config.web_directory)

json.dump(index, open(os.path.join(config.web_directory, "index.json"), mode="w", encoding="utf8"), indent=2)
json.dump(index, open(os.path.join(config.web_directory, "index.json"), mode="w", encoding="utf-8"), indent=2)

if (config.subdirectory):
# update search base url to subdirectory
Expand All @@ -50,9 +50,19 @@ def skipline(line):
if skip in line: return True
return False

def clean_line(line):
"""clean unicode spaces from line"""
# Replace unicode spaces
line = line.replace(u"\u00a0", " ")
line = line.replace(u"\u202f", " ")
line = line.replace(" ", " ")
line = line.replace("&nbsp", " ")

return line

def clean(filepath):
"""clean the file of all HTML tags and unnecessary data"""
f = open(filepath, mode="r", encoding="utf8")
f = open(filepath, mode="r", encoding="utf-8")
lines = f.readlines()
f.close()

Expand All @@ -61,8 +71,8 @@ def clean(filepath):
skipindex = False
indexing = False
for line in lines:
if (not skipline(line)) and indexing:
content += line + "\n"
if (not skipline(line)) and indexing:
content += clean_line(line) + "\n"
if "<!--start-indexing-for-search-->" in line:
indexing = True
if "<!--stop-indexing-for-search-->" in line:
Expand Down