diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-04-14 20:59:17 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-04-14 21:35:13 -0300 |
commit | 7342b35d0da518fa5559dadc3239fd574a105432 (patch) | |
tree | a17ec409c03b6ab1a01c2f4cc2ec8ef2f8f85d4b /src/common-util/wiki-data.js | |
parent | 6d811c36d2b9795ad58fd0bf11f6033d93863fed (diff) |
data: CommentaryEntry
Fully integrated, all in one commit! Wow!
Diffstat (limited to 'src/common-util/wiki-data.js')
-rw-r--r-- | src/common-util/wiki-data.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js index 0aa18ddb..37f5d69e 100644 --- a/src/common-util/wiki-data.js +++ b/src/common-util/wiki-data.js @@ -107,6 +107,35 @@ export const commentaryRegexCaseSensitiveOneShot = export const oldStyleLyricsDetectionRegex = /^<i>.*:<\/i>/m; +export function matchContentEntries(sourceText, caseSensitiveRegex) { + const matchEntries = []; + + let previousMatchEntry = null; + let previousEndIndex = null; + + for (const {0: matchText, index: startIndex, groups: matchEntry} + of sourceText.matchAll(caseSensitiveRegex)) { + if (previousMatchEntry) { + previousMatchEntry.body = sourceText.slice(previousEndIndex, startIndex); + } + + matchEntries.push(matchEntry); + + previousMatchEntry = matchEntry; + previousEndIndex = startIndex + matchText.length; + } + + if (previousMatchEntry) { + previousMatchEntry.body = sourceText.slice(previousEndIndex); + } + + return matchEntries; +} + +export function matchCommentaryEntries(sourceText) { + return matchContentEntries(sourceText, commentaryRegexCaseSensitive) +} + export function filterAlbumsByCommentary(albums) { return albums .filter((album) => [album, ...album.tracks].some((x) => x.commentary)); |