-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from YDX-2147483647/YDX-2147483647/issue42
- Loading branch information
Showing
9 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { hook, update_notices } from '../core/index.js' | ||
import { add_hook } from '../plugin/cli/index.js' | ||
import add_normalize_hook from '../plugin/normalize/index.js' | ||
|
||
add_hook.verbose(hook) | ||
add_hook.preview_output(hook) | ||
add_hook.progress_bar(hook) | ||
add_hook.recent_filter(hook, 90) | ||
add_normalize_hook(hook) | ||
|
||
await update_notices() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { hook, update_notices } from '../core/index.js' | ||
import { add_hook } from '../plugin/cli/index.js' | ||
import add_proxy_hook from '../plugin/proxy/index.js' | ||
import add_normalize_hook from '../plugin/normalize/index.js' | ||
|
||
add_hook.verbose(hook) | ||
add_hook.preview_output(hook) | ||
add_hook.progress_bar(hook) | ||
add_proxy_hook(hook) | ||
add_normalize_hook(hook) | ||
|
||
await update_notices() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { hook, update_notices } from '../core/index.js' | ||
import { add_hook } from '../plugin/cli/index.js' | ||
import add_normalize_hook from '../plugin/normalize/index.js' | ||
import add_rss_hook from '../plugin/rss/index.js' | ||
|
||
add_hook.verbose(hook) | ||
add_hook.progress_bar(hook) | ||
add_hook.recent_filter(hook, 90) | ||
add_normalize_hook(hook) | ||
add_rss_hook(hook) | ||
|
||
await update_notices() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* 重整不完整的标题 | ||
* @module | ||
*/ | ||
|
||
import { type HookCollectionType } from '../../core/index.js' | ||
import { normalize } from './normalize.js' | ||
|
||
/** | ||
* `fetch_each`后重整不完整的标题 | ||
*/ | ||
export default function add_normalize_hook (hook: HookCollectionType) { | ||
hook.after('fetch_each', async ({ notices }) => { | ||
notices.forEach(n => { n.title = normalize(n.title) }) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { assert } from 'chai' | ||
import { describe, it } from 'mocha' | ||
|
||
import { normalize } from './normalize.js' | ||
|
||
function assert_normalize (raw: string, expected: string) { | ||
assert.equal(normalize(raw), expected) | ||
} | ||
|
||
describe('重整标题', () => { | ||
it('保持完整标题', () => { | ||
assert_normalize( | ||
'2023年北京市成人高校招生录取信息与分数线查询', | ||
'2023年北京市成人高校招生录取信息与分数线查询', | ||
) | ||
}) | ||
it('修正截断标题的省略号', () => { | ||
assert_normalize( | ||
'【通知】明德书院关于2023年社会捐助类奖助学金(部分)评选工...', | ||
'【通知】明德书院关于2023年社会捐助类奖助学金(部分)评选工……', | ||
) | ||
}) | ||
it('重整残余特殊字符的标题', () => { | ||
assert_normalize( | ||
'北理工宇航学院2024年接收优秀应届本科毕业生推荐免试研究生&#...', | ||
'北理工宇航学院2024年接收优秀应届本科毕业生推荐免试研究生……', | ||
) | ||
assert_normalize( | ||
'光电学院2024年接收优秀应届本科毕业生推荐免试研究生(含本直博生ÿ...', | ||
'光电学院2024年接收优秀应届本科毕业生推荐免试研究生(含本直博生……', | ||
) | ||
assert_normalize( | ||
'北京理工大学管理与经济学院2024年接收优秀应届本科毕业生推荐免试攻读研究生(含本直博生\u000f...', | ||
'北京理工大学管理与经济学院2024年接收优秀应届本科毕业生推荐免试攻读研究生(含本直博生……', | ||
) | ||
assert_normalize( | ||
'关于2023年社会捐助类奖助学金(部分...', | ||
'关于2023年社会捐助类奖助学金(部分……', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 重整不完整的文字 | ||
* @param text 原始文字 | ||
* @returns 重整化的文字 | ||
*/ | ||
export function normalize (text: string) { | ||
// 保留完整标题 | ||
if (!text.endsWith('...')) { | ||
return text | ||
} | ||
|
||
return text.replace(/[^A-Za-z\u4E00-\u9FFF]*\.{3}$/, '……') | ||
} |