mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
feat: added max age support to newsfeed
Hardcoded to 91 days (~3 months).
This commit is contained in:
parent
220ec14d83
commit
ce1e7bb21d
@ -4,6 +4,7 @@ const newsfeed = {
|
|||||||
lsKey: 'newsfeed',
|
lsKey: 'newsfeed',
|
||||||
feedUrl: 'https://blog.fiery.me/rss-newsfeed.xml',
|
feedUrl: 'https://blog.fiery.me/rss-newsfeed.xml',
|
||||||
maxItems: 3,
|
maxItems: 3,
|
||||||
|
maxAge: 91 * 24 * 60 * 60, // 91 days (~3 months)
|
||||||
dismissed: {},
|
dismissed: {},
|
||||||
done: false
|
done: false
|
||||||
}
|
}
|
||||||
@ -58,10 +59,7 @@ newsfeed.formatRelativeDate = delta => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newsfeed.formatNotification = item => {
|
newsfeed.formatNotification = item => {
|
||||||
const parsedDate = newsfeed.simpleParseDate(item.pubDate)
|
const isRecentWeek = item.dateDelta <= (7 * 24 * 60 * 60) // 7 days (1 week)
|
||||||
const dateDelta = Math.round((+new Date() - parsedDate) / 1000)
|
|
||||||
const isRecentWeek = dateDelta <= 604800
|
|
||||||
|
|
||||||
const element = document.createElement('a')
|
const element = document.createElement('a')
|
||||||
element.dataset.identifier = item.identifier
|
element.dataset.identifier = item.identifier
|
||||||
element.className = 'notification is-info'
|
element.className = 'notification is-info'
|
||||||
@ -79,7 +77,7 @@ newsfeed.formatNotification = item => {
|
|||||||
: 'N/A'}
|
: 'N/A'}
|
||||||
</div>
|
</div>
|
||||||
<div class="news-date${isRecentWeek ? ' is-recent-week' : ''}">
|
<div class="news-date${isRecentWeek ? ' is-recent-week' : ''}">
|
||||||
<span title="${parsedDate.toLocaleString()}">${newsfeed.formatRelativeDate(dateDelta)}</span>
|
<span title="${item.parsedDate.toLocaleString()}">${newsfeed.formatRelativeDate(item.dateDelta)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
`
|
`
|
||||||
@ -141,19 +139,24 @@ newsfeed.do = () => {
|
|||||||
const identifier = title + '|' + description + '|' + pubDate + '|' + link
|
const identifier = title + '|' + description + '|' + pubDate + '|' + link
|
||||||
|
|
||||||
if (!newsfeed.dismissed[identifier]) {
|
if (!newsfeed.dismissed[identifier]) {
|
||||||
const notificationElement = newsfeed.formatNotification({
|
const parsedDate = newsfeed.simpleParseDate(pubDate)
|
||||||
title, description, pubDate, link, identifier
|
const dateDelta = Math.round((+new Date() - parsedDate) / 1000)
|
||||||
})
|
|
||||||
|
|
||||||
const dismissTrigger = notificationElement.querySelector('.delete')
|
if (typeof newsfeed.maxAge === 'number' && dateDelta <= newsfeed.maxAge) {
|
||||||
if (dismissTrigger) {
|
const notificationElement = newsfeed.formatNotification({
|
||||||
dismissTrigger.addEventListener('click', function () {
|
title, description, pubDate, link, identifier, parsedDate, dateDelta
|
||||||
event.preventDefault()
|
|
||||||
newsfeed.dismissNotification(event.target.parentNode)
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
column.appendChild(notificationElement)
|
const dismissTrigger = notificationElement.querySelector('.delete')
|
||||||
|
if (dismissTrigger) {
|
||||||
|
dismissTrigger.addEventListener('click', function () {
|
||||||
|
event.preventDefault()
|
||||||
|
newsfeed.dismissNotification(event.target.parentNode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
column.appendChild(notificationElement)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user