mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
* update deps * lint fixes * fix * trace-redirectを削除 Co-Authored-By: あわわわとーにゅ <17376330+u1-liquid@users.noreply.github.com> * attempt to fix test * refactor * fix test --------- Co-authored-by: あわわわとーにゅ <17376330+u1-liquid@users.noreply.github.com>
27 lines
548 B
TypeScript
27 lines
548 B
TypeScript
/* eslint-disable no-param-reassign */
|
|
import escapeRegExp from 'escape-regexp';
|
|
|
|
export function cleanupTitle(title: string, siteName?: string | null): string {
|
|
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;
|
|
}
|