{% if query %}
- -

搜索:{{ query }}

+ {% if suggestion %} +

+ 已显示 “{{ suggestion }}” 的搜索结果。   + 仍然搜索:{{ query }}
+

+ {% else %} +

+ 搜索:{{ query }}    +

+ {% endif %}
{% endif %} {% if query and page.object_list %} From 3b778cd84669e54110b21f3f8e094e7d4141b007 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:25:02 +0000 Subject: [PATCH 041/166] Bump django from 4.0.6 to 4.0.7 Bumps [django](https://github.com/django/django) from 4.0.6 to 4.0.7. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/4.0.6...4.0.7) --- updated-dependencies: - dependency-name: django dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index dc13859c1..7bc2c9554 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ coverage==6.4 bleach==5.0.0 -Django==4.0.6 +Django==4.0.7 django-compressor==4.0 django-haystack==3.2.1 django-ipware==4.0.2 From 86029562c5a2ebb5cb593a0a66f7b731dc8c1181 Mon Sep 17 00:00:00 2001 From: ch3nnn Date: Wed, 17 Aug 2022 23:57:05 +0800 Subject: [PATCH 042/166] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20suggest=5F?= =?UTF-8?q?search=20=E6=8E=A8=E8=8D=90=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- djangoblog/elasticsearch_backend.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/djangoblog/elasticsearch_backend.py b/djangoblog/elasticsearch_backend.py index eb7fea263..4afe4981f 100644 --- a/djangoblog/elasticsearch_backend.py +++ b/djangoblog/elasticsearch_backend.py @@ -54,19 +54,22 @@ def clear(self, models=None, commit=True): self.remove(None) @staticmethod - def get_suggestion(body: str): - """获取建议 keyword """ + def get_suggestion(query: str) -> str: + """获取推荐词, 如果没有找到添加原搜索词""" + search = ArticleDocument.search() \ - .query("match", body=body) \ - .suggest('suggest_search', body, term={'field': 'body'}) \ + .query("match", body=query) \ + .suggest('suggest_search', query, term={'field': 'body'}) \ .execute() keywords = [] for suggest in search.suggest.suggest_search: if suggest["options"]: keywords.append(suggest["options"][0]["text"]) - - return ' '.join(keywords) if keywords else body + else: + keywords.append(suggest["text"]) + + return ' '.join(keywords) @log_query def search(self, query_string, **kwargs): @@ -75,9 +78,8 @@ def search(self, query_string, **kwargs): start_offset = kwargs.get('start_offset') end_offset = kwargs.get('end_offset') - # 搜索建议 - is_suggest = getattr(self, "is_suggest", None) - if is_suggest is not False: + # 推荐词搜索 + if getattr(self, "is_suggest", None): suggestion = self.get_suggestion(query_string) else: suggestion = query_string @@ -171,10 +173,7 @@ class ElasticSearchModelSearchForm(ModelSearchForm): def search(self): # 是否建议搜索 - self.searchqueryset.query.backend.is_suggest = True - if self.data.get("is_suggest") == "no": - self.searchqueryset.query.backend.is_suggest = False - + self.searchqueryset.query.backend.is_suggest = self.data.get("is_suggest") != "no" sqs = super().search() return sqs From c8e9d2fe28e876246f98f742256d352db4b2f325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= Date: Thu, 18 Aug 2022 14:21:17 +0800 Subject: [PATCH 043/166] Update docker.yml --- .github/workflows/docker.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index efa540932..03f94aeac 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,24 +7,27 @@ on: - '**/*.yml' branches: - 'master' + - 'dev' jobs: docker: runs-on: ubuntu-latest steps: + - name: Set env to staging + if: endsWith(github.ref, '/dev') + run: | + echo "DOCKER_TAG=test" >> $GITHUB_ENV + - name: Set env to production + if: endsWith(github.ref, '/master') + run: | + echo "DOCKER_TAG=latest" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v2 - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- + - name: Login to DockerHub uses: docker/login-action@v1 with: @@ -35,12 +38,6 @@ jobs: with: context: . push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:latest - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache + tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:${{DOCKER_TAG}} From 9e202aa1ee65280108ca58f3a835cdf883ae9a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= Date: Thu, 18 Aug 2022 14:25:18 +0800 Subject: [PATCH 044/166] Update docker.yml --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 03f94aeac..34446eac5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -38,6 +38,6 @@ jobs: with: context: . push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:${{DOCKER_TAG}} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:${{env.DOCKER_TAG}} From 5aa41ce952e384bfe0884638158f23054fa7ceb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= Date: Thu, 18 Aug 2022 14:27:02 +0800 Subject: [PATCH 045/166] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7bc2c9554..d4e15c513 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ coverage==6.4 bleach==5.0.0 -Django==4.0.7 +Django==4.1 django-compressor==4.0 django-haystack==3.2.1 django-ipware==4.0.2 From 3ec5ab662b1cebe67419a2462cf5901cf0ad9ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= Date: Thu, 18 Aug 2022 14:29:58 +0800 Subject: [PATCH 046/166] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d4e15c513..b9672707b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ coverage==6.4 bleach==5.0.0 Django==4.1 -django-compressor==4.0 +django-compressor==4.1 django-haystack==3.2.1 django-ipware==4.0.2 django-mdeditor==0.1.20 From 38a2d4273b2fa861ec7fc2fc2e0f6dca6c255cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=94=E5=90=AC=E9=A3=8E=E5=90=9F?= Date: Thu, 18 Aug 2022 14:34:41 +0800 Subject: [PATCH 047/166] Update docker.yml --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 34446eac5..5e76a0dc1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,11 +13,11 @@ jobs: docker: runs-on: ubuntu-latest steps: - - name: Set env to staging + - name: Set env to docker dev tag if: endsWith(github.ref, '/dev') run: | echo "DOCKER_TAG=test" >> $GITHUB_ENV - - name: Set env to production + - name: Set env to docker latest tag if: endsWith(github.ref, '/master') run: | echo "DOCKER_TAG=latest" >> $GITHUB_ENV From 0111d69da3f3045428a1d5a2c1acb0cc898a995b Mon Sep 17 00:00:00 2001 From: liangliangyy Date: Sun, 11 Sep 2022 13:16:13 +0800 Subject: [PATCH 048/166] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index b9672707b..d6ce3d127 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -coverage==6.4 -bleach==5.0.0 -Django==4.1 +coverage==6.4.4 +bleach==5.0.1 +Django==4.1.1 django-compressor==4.1 django-haystack==3.2.1 django-ipware==4.0.2 @@ -10,17 +10,17 @@ elasticsearch==7.16.1 elasticsearch-dsl==7.4.0 gevent==21.12.0 jieba==0.42.1 -jsonpickle==2.1.0 -Markdown==3.3.7 +jsonpickle==2.2.0 +Markdown==3.4.1 mysqlclient==2.1.1 -Pillow==9.1.1 -Pygments==2.12.0 -python-logstash==0.4.6 +Pillow==9.2.0 +Pygments==2.13.0 +python-logstash==0.4.8 python-slugify==6.1.2 -pytz==2022.1 +pytz==2022.2.1 raven==6.10.0 -requests==2.28.0 -urllib3==1.26.9 +requests==2.28.1 +urllib3==1.26.12 WeRoBot==1.13.1 Whoosh==2.7.4 user-agents==2.2.0 From 7366807582b367513d5508b393e479ce9f6e5aa8 Mon Sep 17 00:00:00 2001 From: ch3nnn Date: Wed, 14 Sep 2022 17:47:24 +0800 Subject: [PATCH 049/166] =?UTF-8?q?fix:=20#541=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E3=80=81=E8=AF=A6=E6=83=85=E9=A1=B5=E3=80=81?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=8C=BA=E6=95=B0=E5=AD=A6=E5=85=AC=E5=BC=8F?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog/static/mathjax/js/mathjax-config.js | 21 +++++++++++++++++++++ templates/share_layout/base.html | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 blog/static/mathjax/js/mathjax-config.js diff --git a/blog/static/mathjax/js/mathjax-config.js b/blog/static/mathjax/js/mathjax-config.js new file mode 100644 index 000000000..158ba65a4 --- /dev/null +++ b/blog/static/mathjax/js/mathjax-config.js @@ -0,0 +1,21 @@ +$(function () { + MathJax.Hub.Config({ + showProcessingMessages: false, //关闭js加载过程信息 + messageStyle: "none", //不显示信息 + extensions: ["tex2jax.js"], jax: ["input/TeX", "output/HTML-CSS"], displayAlign: "left", tex2jax: { + inlineMath: [["$", "$"]], //行内公式选择$ + displayMath: [["$$", "$$"]], //段内公式选择$$ + skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'a'], //避开某些标签 + }, "HTML-CSS": { + availableFonts: ["STIX", "TeX"], //可选字体 + showMathMenu: false //关闭右击菜单显示 + } + }); + // 识别范围 => 文章内容、评论内容标签 + const contentId = document.getElementById("content"); + const commentId = document.getElementById("comments"); + MathJax.Hub.Queue(["Typeset", MathJax.Hub, contentId, commentId]); +}) + + + diff --git a/templates/share_layout/base.html b/templates/share_layout/base.html index d04469e93..51f02c551 100644 --- a/templates/share_layout/base.html +++ b/templates/share_layout/base.html @@ -29,6 +29,7 @@ + {% compress css %} {{ SITE_DESCRIPTION }}