mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-06-30 23:38:01 +09:00
3.0.1
This commit is contained in:
19
built/utils/cleanup-title.js
Normal file
19
built/utils/cleanup-title.js
Normal file
@ -0,0 +1,19 @@
|
||||
import escapeRegExp from 'escape-regexp';
|
||||
export default function (title, siteName) {
|
||||
title = title.trim();
|
||||
if (siteName) {
|
||||
siteName = siteName.trim();
|
||||
const x = escapeRegExp(siteName);
|
||||
const patterns = [
|
||||
`^(.+?)\\s?[\\-\\|:・]\\s?${x}$`
|
||||
];
|
||||
for (let i = 0; i < patterns.length; i++) {
|
||||
const pattern = new RegExp(patterns[i]);
|
||||
const [, match] = pattern.exec(title) || [null, null];
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
Reference in New Issue
Block a user