Skip to content

Commit

Permalink
Normalize keywords (fixes opengaming#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong authored Dec 16, 2020
1 parent 9eb7b90 commit fed69d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions render.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python3

import html
import os, os.path as op
import shutil
import functools
import argparse
import logging
import re
import unidecode

import jinja2
import _ext
Expand Down Expand Up @@ -66,12 +68,19 @@ def render_all(target):
name = slug(game[0][0])
render_to('game.html', f'{target}/{name}/index.html', site=site, game=game)


def normalize(text):
if not text:
return ''
return html.escape(unidecode.unidecode(text.lower()))


def main():
parser = argparse.ArgumentParser(description='Render OSGC')
parser.add_argument('-d', '--dest', default='_build')
args = parser.parse_args()

env().filters['normalize'] = normalize
render_all(args.dest)


Expand Down
15 changes: 8 additions & 7 deletions templates/games.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@
{% for n in names -%}
{% if n is not string -%}
{% for i in n -%}
{{ i | lower | e -}}{{ ' ' -}}
{{ i | normalize -}}{{ ' ' -}}
{% endfor -%}
{% else -%}
{{ n | lower | e -}}
{{ n | normalize -}}
{% endif -%}
{{ ' ' -}}
{% endfor -%}
{%- endmacro %}

{% macro show_keywords(game, names, meta) -%}
{{ game.name | lower | e -}}{{ ' ' -}}
{{ game.tags | join(' ') -}}{{ ' ' -}}
{{ game.info | lower | e -}}{{ ' ' -}}
{{ game.name | normalize -}}{{ ' ' -}}
{{ game.tags | join(' ') | normalize -}}{{ ' ' -}}
{{ game.info | normalize -}}{{ ' ' -}}

{%- if game.new %}
{{ 'new updated added' }}
{{ 'new updated added ' -}}
{% endif %}

{%- if 'multiplayer' in game -%}
{{ 'multiplayer' }}
{{ 'multiplayer ' }}
{%- endif -%}

{{ show_keywords_names(names) }}
Expand Down

0 comments on commit fed69d2

Please sign in to comment.