You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
413 B
TypeScript
18 lines
413 B
TypeScript
import nodejieba from 'nodejieba';
|
|
import * as bus from 'hydrooj/dist/service/bus';
|
|
|
|
declare module 'hydrooj' {
|
|
interface Pdoc {
|
|
search?: string
|
|
}
|
|
}
|
|
|
|
const jiebaHook = async (pdoc) => {
|
|
if (!pdoc.title) return;
|
|
const segments = nodejieba.cutForSearch(pdoc.title);
|
|
pdoc.search = segments.join(' ');
|
|
};
|
|
|
|
bus.on('problem/before-add', jiebaHook);
|
|
bus.on('problem/before-edit', jiebaHook);
|