Skip to content

Commit

Permalink
remove opencc #346
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Oct 22, 2023
1 parent 65a2b82 commit a761eac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update \
&& apt-get install -y --no-install-recommends build-essential libpq-dev python3-venv opencc git
&& apt-get install -y --no-install-recommends build-essential libpq-dev python3-venv git

COPY requirements.txt /neodb/
WORKDIR /neodb
Expand All @@ -27,8 +27,7 @@ RUN --mount=type=cache,sharing=locked,target=/var/cache/apt-run apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
busybox \
nginx \
gettext-base \
opencc
gettext-base
RUN busybox --install

COPY . /neodb
Expand All @@ -40,7 +39,6 @@ RUN /neodb-venv/bin/python3 manage.py collectstatic --noinput
RUN mv /neodb/neodb-takahe /takahe
WORKDIR /takahe
COPY --from=build /takahe-venv /takahe-venv
RUN pwd && ls
RUN TAKAHE_DATABASE_SERVER="postgres://x@y/z" TAKAHE_SECRET_KEY="t" TAKAHE_MAIN_DOMAIN="x.y" /takahe-venv/bin/python3 manage.py collectstatic --noinput

WORKDIR /neodb
Expand All @@ -51,5 +49,4 @@ RUN rm -rf /var/lib/apt/lists/*

USER app:app

# invoke check by default
CMD [ "neodb-hello"]
15 changes: 11 additions & 4 deletions common/templatetags/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from opencc import OpenCC

cc = OpenCC("t2s")
register = template.Library()


# opencc is removed for now due to package installation issues
# to re-enable it, add it to Dockerfile/requirements.txt and uncomment the following lines
# from opencc import OpenCC
# cc = OpenCC("t2s")
def _cc(text):
return text
# return cc.convert(text)


@register.filter
@stringfilter
def highlight(text, search):
otext = cc.convert(text.lower())
otext = _cc(text.lower())
l = len(text)
if l != len(otext):
return text # in rare cases, the lowered&converted text has a different length
rtext = ""
words = list(set([w for w in cc.convert(search.strip().lower()).split(" ") if w]))
words = list(set([w for w in _cc(search.strip().lower()).split(" ") if w]))
words.sort(key=len, reverse=True)
i = 0
while i < l:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ loguru
lxml
markdownify
mistune
opencc
openpyxl
podcastparser
psycopg2-binary
Expand Down

0 comments on commit a761eac

Please sign in to comment.