Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.44 KB

File metadata and controls

49 lines (37 loc) · 1.44 KB

@nitpicker/core

.nitpicker アーカイブ内のページに対して analyze プラグインを実行する内部パッケージです。

プラグインの読み込み、実行、結果の書き戻しを担当します。通常は @nitpicker/clianalyze コマンドから利用します。

プラグイン作者向けAPI

analyze プラグインは definePlugin() で定義します。

import { definePlugin } from '@nitpicker/core';

type Options = {
	keywords: string[];
};

export default definePlugin((options: Options) => {
	return {
		label: 'キーワード検索',
		// 並列度を宣言できる。省略時は os.cpus().length
		// 重いプラグインは小さく設定する
		concurrency: 4,
		headers: {
			found: 'Keywords Found',
		},
		async eachPage({ window }) {
			const text = window.document.body.textContent ?? '';
			const count = options.keywords.filter((keyword) => text.includes(keyword)).length;
			return {
				page: { found: { value: count } },
			};
		},
	};
});

concurrency を省略するとCPUコア数が使われます。ChromeやPuppeteerなど重いプロセスを起動するプラグインでは、2〜4程度に絞ることを推奨します。

関連リンク

ライセンス

Apache-2.0