Merge pull request #2580 from r3wald/feature/newsfeed-show-as-list

feature: show newsfeed as list
This commit is contained in:
Michael Teeuw 2021-06-15 11:14:15 +02:00 committed by GitHub
commit 8be4604c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 24 deletions

View File

@ -21,6 +21,7 @@ Special thanks to the following contributors: @B1gG, @codac, @ezeholz, @khassel,
- Added custom-properties for gaps around body and between modules - Added custom-properties for gaps around body and between modules
- Added test case for recurring calendar events - Added test case for recurring calendar events
- Added new Environment Canada provider for default WEATHER module (weather data for Canadian locations only) - Added new Environment Canada provider for default WEATHER module (weather data for Canadian locations only)
- Added list view for newsfeed module.
### Updated ### Updated

View File

@ -12,3 +12,12 @@ iframe.newsfeed-fullarticle {
bottom: inherit; bottom: inherit;
top: -90px; top: -90px;
} }
.newsfeed-list {
list-style: none;
}
.newsfeed-list li {
text-align: justify;
margin-bottom: 0.5em;
}

View File

@ -14,6 +14,7 @@ Module.register("newsfeed", {
encoding: "UTF-8" //ISO-8859-1 encoding: "UTF-8" //ISO-8859-1
} }
], ],
showAsList: false,
showSourceTitle: true, showSourceTitle: true,
showPublishDate: true, showPublishDate: true,
broadcastNewsFeeds: true, broadcastNewsFeeds: true,
@ -128,6 +129,10 @@ Module.register("newsfeed", {
} }
const item = this.newsItems[this.activeItem]; const item = this.newsItems[this.activeItem];
const items = this.newsItems.map(function (item) {
item.publishDate = moment(new Date(item.pubdate)).fromNow();
return item;
});
return { return {
loaded: true, loaded: true,
@ -135,7 +140,8 @@ Module.register("newsfeed", {
sourceTitle: item.sourceTitle, sourceTitle: item.sourceTitle,
publishDate: moment(new Date(item.pubdate)).fromNow(), publishDate: moment(new Date(item.pubdate)).fromNow(),
title: item.title, title: item.title,
description: item.description description: item.description,
items: items
}; };
}, },
@ -192,7 +198,6 @@ Module.register("newsfeed", {
return true; return true;
}, this); }, this);
} }
newsItems.forEach((item) => { newsItems.forEach((item) => {
//Remove selected tags from the beginning of rss feed items (title or description) //Remove selected tags from the beginning of rss feed items (title or description)
if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") { if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") {

View File

@ -1,28 +1,59 @@
{% if loaded %} {% if loaded %}
<div> {% if config.showAsList %}
{% if (config.showSourceTitle and sourceTitle) or config.showPublishDate %} <ul class="newsfeed-list">
<div class="newsfeed-source light small dimmed"> {% for item in items %}
{% if sourceTitle and config.showSourceTitle %} <li>
{{ sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %} {% if (config.showSourceTitle and item.sourceTitle) or config.showPublishDate %}
{% endif %} <div class="newsfeed-source light small dimmed">
{% if config.showPublishDate %} {% if item.sourceTitle and config.showSourceTitle %}
{{ publishDate }}: {{ item.sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %}
{% endif %} {% endif %}
{% if config.showPublishDate %}
{{ item.publishDate }}:
{% endif %}
</div>
{% endif %}
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
{{ item.title }}
</div>
{% if config.showDescription %}
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
{% if config.truncDescription %}
{{ item.description | truncate(config.lengthDescription) }}
{% else %}
{{ item.description }}
{% endif %}
</div>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<div>
{% if (config.showSourceTitle and sourceTitle) or config.showPublishDate %}
<div class="newsfeed-source light small dimmed">
{% if sourceTitle and config.showSourceTitle %}
{{ sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %}
{% endif %}
{% if config.showPublishDate %}
{{ publishDate }}:
{% endif %}
</div>
{% endif %}
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
{{ title }}
</div> </div>
{% endif %} {% if config.showDescription %}
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}"> <div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
{{ title }} {% if config.truncDescription %}
{{ description | truncate(config.lengthDescription) }}
{% else %}
{{ description }}
{% endif %}
</div>
{% endif %}
</div> </div>
{% if config.showDescription %} {% endif %}
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
{% if config.truncDescription %}
{{ description | truncate(config.lengthDescription) }}
{% else %}
{{ description }}
{% endif %}
</div>
{% endif %}
</div>
{% elseif error %} {% elseif error %}
<div class="small dimmed"> <div class="small dimmed">
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }} {{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}