GithubHelp home page GithubHelp logo

halo-dev / plugin-search-widget Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 10.0 6.7 MB

Halo 搜索组件的插件

Home Page: https://halo.run/store/apps/app-DlacW

License: GNU General Public License v3.0

JavaScript 63.95% TypeScript 27.51% Java 3.76% HTML 1.59% CSS 3.19%
halo halo-plugin

plugin-search-widget's Introduction

plugin-search-widget

Halo 2.0 的通用搜索组件插件。

使用方式

  1. 下载,目前提供以下两个下载方式:
  2. 安装,插件安装和更新方式可参考:https://docs.halo.run/user-guide/plugins

需要注意的是,此插件需要主题进行适配,不会主动显示搜索入口。

开发环境

git clone [email protected]:halo-dev/plugin-search-widget.git

# 或者当你 fork 之后

git clone [email protected]:{your_github_id}/plugin-search-widget.git
cd path/to/plugin-search-widget
./gradlew pnpmInstall

./gradlew build

修改 Halo 配置文件:

halo:
  plugin:
    runtime-mode: development
    classes-directories:
      - "build/classes"
      - "build/resources"
    lib-directories:
      - "libs"
    fixedPluginPath:
      - "/path/to/plugin-search-widget"

主题适配

调用搜索弹框

此插件是一个通用的搜索框插件,主题需要做的只是通过 JS API 唤起搜索框即可,以下是代码示例:

<li th:if="${pluginFinder.available('PluginSearchWidget')}">
  <a href="javascript:SearchWidget.open()" title="搜索">
    搜索
  </a>
</li>

其中,pluginFinder.available('PluginSearchWidget') 的作用是判断使用者是否安装和启用了此插件,如果没有安装或者没有启用,那么就不会显示搜索入口。

自定义样式

虽然目前不能直接为搜索组件编写额外的样式,但可以通过一系列的 CSS 变量来自定义部分样式,开发者可以根据需求自行在主题中添加这些 CSS 变量,让搜索组件和主题更好地融合。

目前已提供的 CSS 变量:

变量名 描述
--halo-search-widget-base-font-size 基础字体大小
--halo-search-widget-base-border-radius 基础元素的圆角
--halo-search-widget-base-font-family 基础字体族
--halo-search-widget-color-modal-layer 模态层颜色
--halo-search-widget-color-modal-content-bg 模态内容背景颜色
--halo-search-widget-color-form-input-bg 表单输入背景颜色
--halo-search-widget-color-form-input 表单输入文字颜色
--halo-search-widget-color-form-input-placeholder 表单输入占位符颜色
--halo-search-widget-color-form-divider 表单分隔线颜色
--halo-search-widget-color-result-empty 无结果提示颜色
--halo-search-widget-color-result-item-bg 结果项背景颜色
--halo-search-widget-color-result-item-hover-bg 结果项悬停背景颜色
--halo-search-widget-color-result-item-title 结果项标题颜色
--halo-search-widget-color-result-item-content 结果项内容颜色
--halo-search-widget-color-command-kbd-item 命令键盘项颜色
--halo-search-widget-color-command-kbd-border 命令键盘边框颜色
点击查看 CSS 代码模板
:root {
   --halo-search-widget-base-font-size: ;
   --halo-search-widget-base-border-radius: ;
   --halo-search-widget-base-font-family: ;
   --halo-search-widget-color-modal-layer: ;
   --halo-search-widget-color-modal-content-bg: ;
   --halo-search-widget-color-form-input-bg: ;
   --halo-search-widget-color-form-input: ;
   --halo-search-widget-color-form-input-placeholder: ;
   --halo-search-widget-color-form-divider: ;
   --halo-search-widget-color-result-empty: ;
   --halo-search-widget-color-result-item-bg: ;
   --halo-search-widget-color-result-item-hover-bg: ;
   --halo-search-widget-color-result-item-title: ;
   --halo-search-widget-color-result-item-content: ;
   --halo-search-widget-color-command-kbd-item: ;
   --halo-search-widget-color-command-kbd-border: ;
}

配色切换方案

根据上面提供的 CSS 变量,也可以通过定义 CSS 变量的方式为搜索组件提供动态切换配色的功能。

以下是实现示例,你可以根据需求自行修改选择器或者媒体查询。

@media (prefers-color-scheme: dark) {
  .color-scheme-auto {
    color-scheme: dark;
    --halo-search-widget-color-modal-layer: rgba(0, 0, 0, 0.8);
    --halo-search-widget-color-modal-content-bg: rgb(15 23 42);
    --halo-search-widget-color-form-input: rgb(255, 255, 255);
    --halo-search-widget-color-form-input-placeholder: rgb(148 163 184);
    --halo-search-widget-color-form-input-bg: rgb(15 23 42);
    --halo-search-widget-color-form-divider: rgb(30 41 59);
    --halo-search-widget-color-result-item-bg: rgb(30 41 59);
    --halo-search-widget-color-result-item-hover-bg: rgb(51 65 85);
    --halo-search-widget-color-result-item-title: rgb(255 255 255);
    --halo-search-widget-color-result-item-content: rgb(148 163 184);
    --halo-search-widget-color-command-kbd-item: rgb(148 163 184);
    --halo-search-widget-color-command-kbd-border: rgb(30 41 59);
    --halo-search-widget-color-result-empty: rgb(148 163 184);
  }
}

.color-scheme-dark {
  color-scheme: dark;
  --halo-search-widget-color-modal-layer: rgba(0, 0, 0, 0.8);
  --halo-search-widget-color-modal-content-bg: rgb(15 23 42);
  --halo-search-widget-color-form-input: rgb(255, 255, 255);
  --halo-search-widget-color-form-input-placeholder: rgb(148 163 184);
  --halo-search-widget-color-form-input-bg: rgb(15 23 42);
  --halo-search-widget-color-form-divider: rgb(30 41 59);
  --halo-search-widget-color-result-item-bg: rgb(30 41 59);
  --halo-search-widget-color-result-item-hover-bg: rgb(51 65 85);
  --halo-search-widget-color-result-item-title: rgb(255 255 255);
  --halo-search-widget-color-result-item-content: rgb(148 163 184);
  --halo-search-widget-color-command-kbd-item: rgb(148 163 184);
  --halo-search-widget-color-command-kbd-border: rgb(30 41 59);
  --halo-search-widget-color-result-empty: rgb(148 163 184);
}

此外,为了让主题可以更加方便的适配暗黑模式,此插件也提供了一套暗黑模式的配色方案,主题可以直接使用此方案,而不需要自己去适配暗黑模式,适配方式如下:

  1. 在 html 或者 body 标签添加 class:
    1. color-scheme-auto:自动模式,根据系统的暗黑模式自动切换。
    2. color-scheme-dark / dark:强制暗黑模式。
    3. color-scheme-light / light:强制明亮模式。
  2. 在 html 或者 body 标签添加 data-color-scheme 属性:
    1. auto:自动模式,根据系统的暗黑模式自动切换。
    2. dark:强制暗黑模式。
    3. light:强制明亮模式。

plugin-search-widget's People

Contributors

ruibaby avatar guqing avatar jiewenhuang avatar

Stargazers

icanfly520 avatar zjw57 avatar Liao Spacefan avatar emirage.niallchen avatar tlbcc avatar Gary avatar zzudongxiang avatar Ralph avatar 404 Not Found 小孟 avatar Joydevelop avatar

Watchers

John Niang avatar  avatar  avatar

plugin-search-widget's Issues

搜索插件不精确,不好用

搜索是博客的一个重要功能,帮助我们通过关键字快读找到自己想要的内容。
经过尝试,个人感觉,halo2 的搜索插件及其难用。 试了一下 wordpress/hexo 的搜索还不错,经过对比,从以下几个方面陈述下我个人认为不如意的地方。
整体来说,对于英文还行,对于中文太弱了。

  1. 搜索不到问题
    我有一篇文章,title 为 "java 安全管理器", 直接搜 title 竟然搜索不到!
    搜索关键字 "安全",也搜索不到。 搜索 "java" 能搜到。 halo 中文用户这么多,希望支持一下。

  2. 搜索不全问题
    英文情况下,因为中文根本搜不到。
    比如我搜索 "java", 仅仅给我列出了一下文章,搜索内容不全

image

  1. 权重问题
    还是这个例子

image

title 中含有 java 的是否应该在前面? 这个搜寻结果的排序不符合预期,简单说,就是"相关性低的" 在 "相关性高的" 前面。
  1. 支持 or
    希望可以同时多个关键字定位一篇文章,比如 我输入 "java springboot", 希望可以搜索出三类文章
    a. 同时和 "java" "springboot" 相关的,排在最前面
    b. 只和 "java" 相关的排在后面
    c. 只和 "springboot" 相关的排在后面。

最后,halo2 问世时间还短,作者能做成现在规模已经很棒了,尤其还是开源的,各位作者辛苦了。
但从产品角度出发,halo2 甚至不满足我对于博客的基本需求,它不是一个好的选择,任重而道远。

我进行搜索时报错了,搜索不了结果

{
"type": "about:blank",
"title": "服务器内部错误",
"status": 500,
"detail": "服务器内部发生错误,请稍候再试。",
"instance": "http://www.qiushaocloud.top:8091/apis/api.halo.run/v1alpha1/indices/post?keyword=Mac&highlightPreTag=%3Cmark%3E&highlightPostTag=%3C/mark%3E",
"requestId": "37cfb519-70",
"timestamp": "2024-04-21T12:34:10.962438010Z"
}

iushaocloud-halo2-server | 2024-04-21T20:34:10.958+08:00 INFO 6 --- [tor-tcp-epoll-2] c.r.h.p.m.s.MeilisearchPostService : search keyword: Mac
qiushaocloud-halo2-server | 2024-04-21T20:34:10.962+08:00 ERROR 6 --- [tor-tcp-epoll-2] a.w.r.e.AbstractErrorWebExceptionHandler : [37cfb519-70] 500 Server Error for HTTP GET "/apis/api.halo.run/v1alpha1/indices/post?keyword=Mac&highlightPreTag=%3Cmark%3E&highlightPostTag=%3C/mark%3E"
qiushaocloud-halo2-server |
qiushaocloud-halo2-server | com.meilisearch.sdk.exceptions.MeilisearchCommunicationException: java.net.UnknownHostException: meilisearch
qiushaocloud-halo2-server | at com.meilisearch.sdk.http.CustomOkHttpClient.execute(CustomOkHttpClient.java:45) ~[na:na]
qiushaocloud-halo2-server | Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
qiushaocloud-halo2-server | Error has been observed at the following site(s):
qiushaocloud-halo2-server | *__checkpoint ⇢ run.halo.app.security.InitializeRedirectionWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ AuthorizationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ ExceptionTranslationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ LogoutWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ ServerRequestCacheWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ SecurityContextServerWebExchangeWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ LogoutPageGeneratingWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ AnonymousAuthenticationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ SecurityWebFilterChainProxy [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ TotpAuthenticationFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ AuthenticationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ SecurityWebFilterChainProxy [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ SecurityWebFilterChainProxy [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ AuthenticationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ AuthenticationWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ ReactorContextWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ CsrfWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ CorsWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ HttpHeaderWriterWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ io.github.guqing.cloudinary.ImageOptimizerWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ run.halo.oauth.Oauth2Authenticator [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ run.halo.oauth.Oauth2AuthorizationRequestRedirectWebFilter [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ run.halo.app.webfilter.AdditionalWebFilterChainProxy [DefaultWebFilterChain]
qiushaocloud-halo2-server | *__checkpoint ⇢ HTTP GET "/apis/api.halo.run/v1alpha1/indices/post?keyword=Mac&highlightPreTag=%3Cmark%3E&highlightPostTag=%3C/mark%3E" [ExceptionHandlingWebHandler]
qiushaocloud-halo2-server | Original Stack Trace:
qiushaocloud-halo2-server | at com.meilisearch.sdk.http.CustomOkHttpClient.execute(CustomOkHttpClient.java:45) ~[na:na]
qiushaocloud-halo2-server | at com.meilisearch.sdk.http.CustomOkHttpClient.post(CustomOkHttpClient.java:112) ~[na:na]
qiushaocloud-halo2-server | at com.meilisearch.sdk.HttpClient.post(HttpClient.java:95) ~[na:na]
qiushaocloud-halo2-server | at com.meilisearch.sdk.Search.rawSearch(Search.java:49) ~[na:na]
qiushaocloud-halo2-server | at com.meilisearch.sdk.Search.search(Search.java:76) ~[na:na]
qiushaocloud-halo2-server | at com.meilisearch.sdk.Index.search(Index.java:375) ~[na:na]
qiushaocloud-halo2-server | at com.rs.halo.plugin.meilisearch.service.MeilisearchPostService.search(MeilisearchPostService.java:51) ~[na:na]
qiushaocloud-halo2-server | at run.halo.app.search.post.PostSearchEndpoint.lambda$search$4(PostSearchEndpoint.java:57) ~[classes/:2.14.0]
qiushaocloud-halo2-server | at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:129) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2571) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2367) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:2241) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:55) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.Mono.subscribe(Mono.java:4568) ~[reactor-core-3.6.4.jar:3.6.4]
qiushaocloud-halo2-server | at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:82) ~[reactor-core-3.6.4.jar:3.6.4]

可否开放或者增加搜索提示的英文版

可否开放或者增加搜索提示的英文版? 这个其实也包括了评论插件。这两个插件目前无法通过前端修改中文为英文,请酌情考虑。目前在改一个英文版的主题,发现插件设计到的语言都没办法修改。

使用 Lit Element 重构搜索组件

原因:使用 Lit 构建 Web Component 可以获得更小的体积,目前的方式是将一个完整的 Vue 实例挂载到一个 ShadowDom,本身搜索组件的业务并不大,但最终构建产物在 gzip 之后还有接近 100k。使用 Lit 重构可以尽可能让组件更加存粹,并且封装之后的组件可以应用于各种 JS 框架,甚至不使用框架。

https://lit.dev/

初步验证:

图片

当前版本:

图片

查询后带上了端口号

你好,我安装了此插件后查询会带上端口号,请问下如何解决
比如会带上默认端口号8090

添加暗黑模式

计划在组件内部直接提供暗黑模式,一些实现细节:

  1. 提供色彩模式参数:auto / dark / light
  2. 提取必要的 css 变量,用于让主题自定义。

使用评论插件和搜索插件之后,网页打开很慢

使用评论插件和搜索插件之后
KQOC1}5293~MX3XV{TB6LMT
关闭插件之后
image
使用过腾讯云和又拍云的全站加速,效果并不是很好,(也有可能是我方法不对)想问问有什么解决办法吗?
打开网站要20多秒实在是受不了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.