mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
20 lines
571 B
JavaScript
20 lines
571 B
JavaScript
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;
|
|
}
|