fixed issue with incorrect formatted articles stopping rendering

This commit is contained in:
sairaj mote 2021-08-28 19:06:42 +05:30
parent 6b00d15f19
commit 1e4c279add

View File

@ -10925,7 +10925,7 @@
document.getElementById( document.getElementById(
"current_date" "current_date"
).innerText = `${weekday} ${month} ${date}, ${year}`; ).textContent = `${weekday} ${month} ${date}, ${year}`;
} }
updateDate(); updateDate();
@ -10935,42 +10935,44 @@
} }
function parseArticles(articles) { function parseArticles(articles) {
let totalarticles = Object.keys(articles).length;
articlekeys = Object.keys(articles);
let domparser = new DOMParser(); let domparser = new DOMParser();
for (let i = 0; i < totalarticles; i++) { console.table(articles)
let currentarticle = {}; for(const articleKey in articles){
if(articles.hasOwnProperty(articleKey)){
let articlehtml = articles[articlekeys[i]]; let currentarticle = {};
let parsedhtml = domparser.parseFromString(articlehtml, "text/html"); let parsedhtml = domparser.parseFromString(articles[articleKey], "text/html");
if(parsedhtml.getElementById("title")){
currentarticle["title"] = parsedhtml.getElementById("title").innerText; currentarticle["title"] = parsedhtml.getElementById("title").textContent;
currentarticle["subtitle"] = currentarticle["subtitle"] =
parsedhtml.getElementById("subtitle").innerText; parsedhtml.getElementById("subtitle").textContent;
currentarticle["sections"] = {}; currentarticle["sections"] = {};
totalsections = totalsections =
parsedhtml.getElementById("sectionmaster").childElementCount; parsedhtml.getElementById("sectionmaster").childElementCount;
for (let j = 0; j < totalsections; j++) { for (let j = 0; j < totalsections; j++) {
tempobj = {}; tempobj = {};
asection = parsedhtml.getElementById(`section${j + 1}`); asection = parsedhtml.getElementById(`section${j + 1}`);
if (asection) { if (asection) {
sectiontitle = asection.children[0].children[0].innerText; sectiontitle = asection.children[0].children[0].textContent;
sectionpara1 = asection.children[1].innerText; sectionpara1 = asection.children[1].textContent;
tempobj["title"] = sectiontitle; tempobj["title"] = sectiontitle;
tempobj["paragraph"] = sectionpara1; tempobj["paragraph"] = sectionpara1;
currentarticle["sections"][j] = tempobj; currentarticle["sections"][j] = tempobj;
}
/* else{
parsedhtml.getElementById('sectionmaster')
console.log(j+1)
console.error(`current articleKey with issue : ${currentarticle['title']}`)
} */
}
parsedarticles[articleKey] = currentarticle;
}else{
// Article with incorrect format
console.error('Article with incorrect format ' + articleKey)
} }
/* else{
parsedhtml.getElementById('sectionmaster')
console.log(j+1)
console.error(`current article with issue : ${currentarticle['title']}`)
} */
} }
parsedarticles[articlekeys[i]] = currentarticle;
} }
} }
@ -11045,13 +11047,13 @@
element.classList.value = "fa fa-thumbs-up"; element.classList.value = "fa fa-thumbs-up";
if ( if (
document.getElementById(`${columnName}_count`).innerText == "" document.getElementById(`${columnName}_count`).textContent == ""
) { ) {
document.getElementById(`${columnName}_count`).innerText = "1"; document.getElementById(`${columnName}_count`).textContent = "1";
} else { } else {
document.getElementById(`${columnName}_count`).innerText = document.getElementById(`${columnName}_count`).textContent =
parseInt( parseInt(
document.getElementById(`${columnName}_count`).innerText document.getElementById(`${columnName}_count`).textContent
) + 1; ) + 1;
} }
}); });
@ -11087,7 +11089,7 @@
if (articleKeys[i] in articles_votesmapping) { if (articleKeys[i] in articles_votesmapping) {
document.getElementById( document.getElementById(
`${map_articlekey_column[articleKeys[i]]}_count` `${map_articlekey_column[articleKeys[i]]}_count`
).innerText = articles_votesmapping[articleKeys[i]]; ).textContent = articles_votesmapping[articleKeys[i]];
} }
} }
} }