From 2b164fc51d26e81ecda6800aae80a8ad6d06fae8 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch <p.jentsch@uni-bielefeld.de> Date: Mon, 6 Feb 2023 15:50:07 +0100 Subject: [PATCH] remove new news system as it needs more work --- app/templates/main/news.html.j2 | 141 -------------------------------- 1 file changed, 141 deletions(-) diff --git a/app/templates/main/news.html.j2 b/app/templates/main/news.html.j2 index d3e2f9b6..b8961b02 100644 --- a/app/templates/main/news.html.j2 +++ b/app/templates/main/news.html.j2 @@ -9,7 +9,6 @@ </div> <div class="col s12"> - <div id="aggregated-news"></div> <div class="card" id="april-2022-update"> <div class="card-content"> <span class="card-title">April 2022 update</span> @@ -127,143 +126,3 @@ </div> </div> {% endblock page_content %} - -{% block scripts %} -{{ super() }} -<script> - function getMastodonStatuses() { - return new Promise((resolve, reject) => { - fetch(`https://fedihum.org/api/v1/accounts/109386364241901080/statuses`, {method: 'GET', headers: {Accept: 'application/json'}}) - .then((response) => { - if (!response.ok) {reject(response);} - return response.json(); - }) - .then((statuses) => {resolve(statuses);}) - }); - } - function getBisBlogsEntries() { - return new Promise((resolve, reject) => { - fetch(`https://blogs.uni-bielefeld.de/blog/uniintern/feed/entries/atom?cat=%2FAllgemein`, {method: 'GET', headers: {Accept: 'application/xml'}}) - .then((response) => { - if (!response.ok) {reject(response);} - return response.text(); - }) - .then((responseText) => {return new DOMParser().parseFromString(responseText, 'application/xml');}) - .then((xmlDocument) => {return xmlDocument.toObject();}) - .then((feed) => {resolve(feed);}); - }); - } - function sortAggregatedNews(a, b) { - let aDate; - let bDate; - - switch (a.source) { - case 'mastodon': - aDate = new Date(a.created_at); - break; - case 'big-blogs': - aDate = new Date(a.published); - break; - default: - throw new Error('Unknown source'); - } - switch (b.source) { - case 'mastodon': - bDate = new Date(b.created_at); - break; - case 'big-blogs': - bDate = new Date(b.published); - break; - default: - throw new Error('Unknown source'); - } - return bDate - aDate; - } - function aggregateNews() { - return new Promise((resolve, reject) => { - Promise.all([getMastodonStatuses(), getBisBlogsEntries()]) - .then( - (responses) => { - console.log(responses[1]); - let mastodonStatuses = responses[0].map((obj) => {return { ...obj, source: 'mastodon'}}); - let bisBlogsEntries = responses[1].feed.entry.map((obj) => {return { ...obj, source: 'big-blogs'};}); - let aggregatedNews = [...mastodonStatuses, ...bisBlogsEntries]; - aggregatedNews.sort(sortAggregatedNews); - resolve(aggregatedNews); - }, - (error) => {reject(error);} - ); - }); - } - - function mastodonStatusToElement(status) { - let date = new Date(status.created_at).toLocaleString('en-US'); - let newsElement = Utils.HTMLToElement( - ` - <div class="row"> - <div class="col s11"> - <div class="card white-text" style="background-color:#5D50E7; border-radius:10px;"> - <div class="card-content"> - <span class="card-title">New Actitvity on Mastodon</span> - <p><i>Published on ${date}</i></p> - <br> - <p>${status.content}</p> - </div> - </div> - </div> - <div class="col s1"> - <img src="https://joinmastodon.org/logos/logo-purple.svg" alt="Mastodon" class="responsive-img hide-on-small-only" style="width:70%; margin-top:30px;"> - </div> - </div> - ` - ); - return newsElement; - } - - function bisBlogsEntryToElement(entry) { - let date = new Date(entry.published).toLocaleString('en-US'); - let newsElement = Utils.HTMLToElement( - ` - <div class="row"> - <div class="col s1"> - <img src="https://blogs.uni-bielefeld.de/blog/uniintern/resource/themabilder/unilogo-square.svg" alt="Bielefeld University Blogs" class="responsive-img hide-on-small-only" style="width:70%; margin-top:40px;"> - </div> - <div class="col s11"> - <div class="card" style="background-color: #A5BDCC; border-radius:10px;"> - <div class="card-content"> - <span class="card-title">${entry.title['#text']}</span> - <p><i>Published on ${date}</i></p> - <br> - <p>${entry.content['#text']}</p> - </div> - </div> - </div> - </div> - ` - ); - let newsImageElements = newsElement.querySelectorAll('img'); - for (let newsImageElement of newsImageElements) { - newsImageElement.classList.add('responsive-img'); - } - return newsElement; - } - - let aggregatedNewsElement = document.querySelector('#aggregated-news'); - aggregateNews().then((aggregatedNews) => { - for (let item of aggregatedNews) { - let newsElement; - switch (item.source) { - case 'mastodon': - newsElement = mastodonStatusToElement(item); - break; - case 'big-blogs': - newsElement = bisBlogsEntryToElement(item); - break; - default: - throw new Error('Unknown source'); - } - aggregatedNewsElement.appendChild(newsElement); - } - }); -</script> -{% endblock scripts %} -- GitLab