From 14f9c99b13e499068b36ca67142fc20c3b3732a2 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 14 Apr 2025 20:59:17 -0300 Subject: data: CommentaryEntry Fully integrated, all in one commit! Wow! --- src/common-util/wiki-data.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/common-util') 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>/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)); -- cgit 1.3.0-6-gf8a5