tomk79/px2-site-search

0.2.2 2024-09-10 11:16 UTC

This package is auto-updated.

Last update: 2024-09-10 11:17:25 UTC


README

Pickles 2 添加站点内搜索功能。

设置 - 设置步骤

设置 Pickles 2 项目

1. 在 composer.json 中添加包信息

$ composer require tomk79/px2-site-search

2. 打开 px-files/config.php 并设置插件

$conf->funcs->before_content = array(
    // PX=site_search
    picklesFramework2\px2SiteSearch\register::before_content(array(
        // 検索エンジンの種類
        // - 'client' = ブラウザ上で静的に動作する検索インデックス
        // - 'paprika' = Paprikaフレームワークを用いてサーバー上で動作する検索インデックス
        // 省略時: 'client'
        'engine_type' => 'client',

        // クライアント用アセットを書き出す先のディレクトリ
        // 省略時: '/common/site_search_index/'
        'path_client_assets_dir' => '/common/site_search_index/',

        // 非公開データの書き出し先ディレクトリ
        // 省略時: '/_sys/site_search_index/'
        'path_private_data_dir' => '/_sys/site_search_index/',

        // インデックスから除外するパス
        // 複数のパス(完全一致)、または正規表現で定義します。
        // 省略時: 除外しない
        'paths_ignore' => array(
            '/perfect_match_ignored/ignored.html', // 完全一致 による設定例
            '/^\/ignored\/.*$/i', // 正規表現による設定例
        ),

        // コンテンツエリアを抽出するセレクタ
        // 省略時: 'body'
        'contents_area_selector' => '.contents',

        // コンテンツから除外する要素のセレクタ
        // 省略時: 除外しない
        'ignored_contents_selector' => array(
            '.contents-ignored',
        ),
    )),
);

3. 在内容或主题中添加搜索UI

<!--
アセットをロードする
先頭の `/common/site_search_index/` の部分は、 `path_client_assets_dir` で設定したパスを参照するように書き換えてください。

オプション:
- `data-path-controot`: Pickles 2 の `$conf->path_controot` の設定値 (省略可)
- `data-lang`: Pickles 2 の `$px->lang()` の値 (省略可)
- `data-local-storage-key`: px2-site-search に専有を許可する localStorage のキー
- `data-allow-client-cache`: index.json をキャッシュするか? (true: キャッシュする, false: キャッシュしない)
-->
<script src="<?= $px->href('/common/site_search_index/assets/px2-site-search.js') ?>"
    data-path-controot="<?= $px->conf()->path_controot ?>"
    data-lang="<?= $px->lang() ?>"
    data-local-storage-key="px2-site-search"
    data-allow-client-cache="true"></script>
<link rel="stylesheet" href="<?= $px->href('/common/site_search_index/assets/px2-site-search.css') ?>" />

<!--
検索UIをページに埋め込む場合
-->
<h2>検索</h2>
<div id="cont-search-result-block"></div>
<script>
	px2sitesearch.createSearchForm('#cont-search-result-block');
</script>

<!--
検索ボタンから検索ダイアログを開く場合
-->
<h2>検索ボタン</h2>
<p><button class="px2-btn px2-btn--primary cont-search-button">検索ダイアログを開く</button></p>
<script>
	$('.cont-search-button').on('click', function(){
		px2sitesearch.openSearchDialog();
	});
</script>

4. 生成索引文件

$ php ./src_px2/.px_execute.php "/?PX=site_search.create_index"

管理界面扩展

config.php 中添加以下设置。

$conf->plugins->px2dt->custom_console_extensions = array(
    'px2-site-search' => array(
        'class_name' => 'picklesFramework2\px2SiteSearch\cce\main()',
    ),
);

PX命令 - PX Commands

PX=site_search.create_index

生成索引文件。

变更日志 - Change Log

tomk79/px2-site-search v0.2.2 (2024年9月10日)

  • 改进了搜索对话框的UI。

tomk79/px2-site-search v0.2.1 (2024年7月21日)

  • 改进了管理界面扩展功能。

tomk79/px2-site-search v0.2.0 (2024年4月30日)

  • 现在可以在服务器端执行搜索。
  • 添加了 engine_type 选项。
  • 添加了 paths_ignore 选项。
  • contents_area_selector 选项的默认值更改为 body
  • 添加了 path_private_data_dir 选项。
  • 可以省略 data-path-controot 选项。
  • 添加了 data-lang 选项。
  • 修复了 data-allow-client-cache 选项不能省略的错误。
  • 通过 X-PXFW-RELATEDLINK 添加的新路径现在被添加到队列数组的开头。
  • 修复了处理搜索目标字符串中的HTML特殊字符的错误。

tomk79/px2-site-search v0.1.0 (2024年3月20日)

  • 首次发布。

许可 - License

MIT许可

作者 - Author