« get me outta code hell

crlf hell pt. II - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2021-12-20 22:40:52 -0400
committer(quasar) nebula <qznebula@protonmail.com>2021-12-20 22:40:52 -0400
commit61ebd2b91809d372253c1005552a9012c519b361 (patch)
treebee2c8091898b5c98bd8b721b66283326c363fe6
parent75bbc85952031514d510d9f8bd4307ede58d2e35 (diff)
crlf hell pt. II
-rwxr-xr-xsrc/upd8.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 2319c13..6a0ff08 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -271,9 +271,13 @@ async function findFiles(dataPath, filter = f => true) {
         .filter(file => filter(file));
 }
 
+function splitLines(text) {
+    return text.split(/\r|\n|\r\n/);
+}
+
 function* getSections(lines) {
     // ::::)
-    const isSeparatorLine = line => /^-{8,}$/.test(line);
+    const isSeparatorLine = line => /^-{8,}/.test(line);
     yield* splitArray(lines, isSeparatorLine);
 }
 
@@ -594,7 +598,7 @@ function transformMultiline(text, {
     // interested in doing lol. sorry!!!
     let inBlockquote = false;
 
-    for (let line of text.split(/\r|\n|\r\n/)) {
+    for (let line of splitLines(text)) {
         const imageLine = line.startsWith('<img');
         line = line.replace(/<img (.*?)>/g, (match, attributes) => img({
             lazy: true,
@@ -1016,7 +1020,7 @@ async function processArtistDataFile(file) {
         return {error: `Could not read ${file} (${error.code}).`};
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     return sections.filter(s => s.filter(Boolean).length).map(section => {
@@ -1051,7 +1055,7 @@ async function processFlashDataFile(file) {
         return {error: `Could not read ${file} (${error.code}).`};
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     let act, color;
@@ -1111,7 +1115,7 @@ async function processNewsDataFile(file) {
         return {error: `Could not read ${file} (${error.code}).`};
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     return sections.map(section => {
@@ -1165,7 +1169,7 @@ async function processTagDataFile(file) {
         }
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     return sections.map(section => {
@@ -1211,7 +1215,7 @@ async function processGroupDataFile(file) {
         }
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     let category, color;
@@ -1266,7 +1270,7 @@ async function processStaticPageDataFile(file) {
         }
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     return sections.map(section => {
@@ -1313,7 +1317,7 @@ async function processWikiInfoFile(file) {
     // Unlike other data files, the site info data file isn't 8roken up into
     // more than one entry. So we operate on the plain old contentLines array,
     // rather than dividing into sections like we usually do!
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
 
     const name = getBasicField(contentLines, 'Name');
     if (!name) {
@@ -1376,7 +1380,7 @@ async function processHomepageInfoFile(file) {
         return {error: `Could not read ${file} (${error.code}).`};
     }
 
-    const contentLines = contents.split('\n');
+    const contentLines = splitLines(contents);
     const sections = Array.from(getSections(contentLines));
 
     const [ firstSection, ...rowSections ] = sections;