From cce198c06ee9a011040365b2c58916438e66cff4 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 1 Dec 2020 22:58:57 +0530 Subject: [PATCH] configuration on par with python --- real-time/config.json | 48 ++++++++++++++++----------------- real-time/index.html | 62 ++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 58 deletions(-) diff --git a/real-time/config.json b/real-time/config.json index 02459da..28873c1 100644 --- a/real-time/config.json +++ b/real-time/config.json @@ -1,40 +1,38 @@ config = { - "r/DankMemes": { - "link":"https://reddit.com/r/dankmemes/.rss?sort=hot", - "limit": 5 - }, - "BuzzFeed - India": { - "link":"https://www.buzzfeed.com/in.xml", - "limit": 5 - }, - "New Yorker":{ - "link":"http://www.newyorker.com/feed/news", - "limit": 5 + "TIFU": { + "link": "https://reddit.com/r/TIFU/.rss?sort=hot" + }, + "BuzzFeed - India": { + "link":"https://www.buzzfeed.com/in.xml", + "summary":true, + "limit":2 + }, + "New Yorker": { + "link":"https://www.newyorker.com/feed/news", + }, + "The Hindu: Sports":{ + "link":"https://www.thehindu.com/sport/feeder/default.rss", + }, + "The Hindu: National News":{ + "link":"https://www.thehindu.com/news/national/feeder/default.rss", + }, + "r/Jokes":{ + "link":"https://reddit.com/r/Jokes/hot/.rss?sort=hot", + "ignore": ["repost","discord"] }, "Vox":{ "link":"https://www.vox.com/rss/index.xml", "limit": 3 - }, - "The Hindu: Sports":{ - "link":"https://www.thehindu.com/sport/feeder/default.rss", - "limit":5 - }, - "The Hindu: National News":{ - "link":"https://www.thehindu.com/news/national/feeder/default.rss", - "limit": 5 - }, - "r/Jokes":{ - "link":"https://reddit.com/r/Jokes/hot/.rss?sort=hot", - "limit":5 } } config_extra = { "Responsive-Images": true, - "direct-link": true, + "direct-link": false, "show-date":true, "left-column":true, "defaults": { - "limit": 5 + "limit": 5, + "summary": true } } \ No newline at end of file diff --git a/real-time/index.html b/real-time/index.html index d6938a2..eb243e8 100644 --- a/real-time/index.html +++ b/real-time/index.html @@ -19,16 +19,6 @@
-
@@ -37,17 +27,24 @@ const feeds = config // Edit config.json -// Note: some RSS feeds can't be loaded in the browser due to CORS security. -// To get around this, you can use a proxy -const CORS_PROXY = "https://cors-anywhere.herokuapp.com/" -//let parser = new RSSParser(); +const CORS_PROXY = "https://cors-anywhere.herokuapp.com/" var contents_title = document.createElement("h2") contents_title.textContent = "Contents" contents_title.classList.add("pb-1") document.getElementById("contents").appendChild(contents_title) async function myfunc(key){ + + var count_lim = feeds[key]["limit"] + var count_lim = (count_lim === undefined) ? config_extra["defaults"]["limit"] : count_lim + + var show_summary = feeds[key]["summary"] + var show_summary = (show_summary === undefined) ? config_extra["defaults"]["summary"] : show_summary + + var ignore_tags = feeds[key]["ignore"] + var ignore_tags = (ignore_tags === undefined) ? [] : ignore_tags + var contents = document.createElement("a") contents.href = "#" + key contents.classList.add("list-group-item","list-group-item-action") @@ -66,7 +63,19 @@ async function myfunc(key){ parser.parseURL(CORS_PROXY + feeds[key]["link"], function(err, feed) { if (err) throw err; feed.items.forEach(function(entry) { - if (countPosts < feeds[key]["limit"]) { + if (countPosts < count_lim) { + + var skip = false + for(var i = 0; i < ignore_tags.length; i++) { + if (entry.title.includes(ignore_tags[i])){ + var skip = true + } else if (entry.content.includes(ignore_tags[i])){ + var skip = true + } + } + + if (!skip) { + var node = document.createElement("div"); node.classList.add("card","mb-3"); var row = document.createElement("div") @@ -92,7 +101,10 @@ async function myfunc(key){ node_body.classList.add("card-body") node_content = document.createElement("p") - node_content.innerHTML = entry.content + + if (show_summary){ + node_content.innerHTML = entry.content + } node_content.classList.add("card-text") if (config_extra["direct-link"]){ @@ -132,22 +144,15 @@ async function myfunc(key){ row.appendChild(right_col) node.appendChild(row) - //node_body.appendChild(node_date) - //node.appendChild(node_body) document.getElementById(key).appendChild(node) - /*console.log(entry.title + ':' + entry.link); - console.log(entry.pubDate)*/ - //console.log(entry.author) - - countPosts+=1 } + } }) if (config_extra["Responsive-Images"]){ var inputs = document.getElementsByTagName('img') - console.log(inputs) for(var i = 0; i < inputs.length; i++) { inputs[i].classList.add("img-fluid") } @@ -160,17 +165,8 @@ async function myfunc(key){ (async () => { for(var key in feeds) { let result = await myfunc(key); - console.log(result) }})(); -/* -var inputs = document.getElementsByTagName('img'); - for(var i = 0; i < inputs.length; i++) { - inputs[i].classList.add("img-fluid") - -} -*/ - \ No newline at end of file