Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
2b164fc5
Commit
2b164fc5
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
remove new news system as it needs more work
parent
ea48e479
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/templates/main/news.html.j2
+0
-141
0 additions, 141 deletions
app/templates/main/news.html.j2
with
0 additions
and
141 deletions
app/templates/main/news.html.j2
+
0
−
141
View file @
2b164fc5
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
</div>
</div>
<div class="col s12">
<div class="col s12">
<div id="aggregated-news"></div>
<div class="card" id="april-2022-update">
<div class="card" id="april-2022-update">
<div class="card-content">
<div class="card-content">
<span class="card-title">April 2022 update</span>
<span class="card-title">April 2022 update</span>
...
@@ -127,143 +126,3 @@
...
@@ -127,143 +126,3 @@
</div>
</div>
</div>
</div>
{% endblock page_content %}
{% 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 %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment