mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-06 06:07:19 +09:00
23 lines
454 B
TypeScript
23 lines
454 B
TypeScript
const escapeRegExp = require('escape-regexp');
|
|
|
|
export default function(title: string, siteName?: string): string {
|
|
title = title.trim();
|
|
|
|
if (siteName) {
|
|
siteName = siteName.trim();
|
|
|
|
const x = escapeRegExp(siteName);
|
|
|
|
const patterns = [
|
|
`^(.+?)\s?[\-\|:・]\s?${x}$`
|
|
].map(p => new RegExp(p));
|
|
|
|
for (let i = 0; i < patterns.length; i++) {
|
|
const [, match] = patterns[i].exec(title);
|
|
if (match) return match;
|
|
}
|
|
}
|
|
|
|
return title;
|
|
}
|