From 1a42a41a53c65bc425699b0a6e50f07b77fc9bb8 Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Mon, 22 May 2023 21:57:09 +0200 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=9A=A7=20=E2=9C=A8=20Register=20a=20W?= =?UTF-8?q?idget=20to=20display=20stories=20from=20HN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Widgets/HackernewsTrending.vue | 54 +++++++++++++++++++ src/components/Widgets/WidgetBase.vue | 1 + src/utils/defaults.js | 17 +++--- 3 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 src/components/Widgets/HackernewsTrending.vue diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue new file mode 100644 index 00000000..348d5783 --- /dev/null +++ b/src/components/Widgets/HackernewsTrending.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue index fd6543e7..c59985df 100644 --- a/src/components/Widgets/WidgetBase.vue +++ b/src/components/Widgets/WidgetBase.vue @@ -78,6 +78,7 @@ const COMPAT = { 'gl-system-load': 'GlSystemLoad', 'gl-cpu-temp': 'GlCpuTemp', 'health-checks': 'HealthChecks', + 'hackernews-trending': 'HackernewsTrending', 'gluetun-status': 'GluetunStatus', iframe: 'IframeWidget', image: 'ImageWidget', diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 8f51df94..69e0ff3e 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -107,11 +107,7 @@ module.exports = { footer: true, }, /* A list of route names that page furniture (header, footer, etc) should be hidden on */ - hideFurnitureOn: [ - 'minimal', - 'login', - 'download', - ], + hideFurnitureOn: ['minimal', 'login', 'download'], /* Key names for local storage identifiers */ localStorageKeys: { LANGUAGE: 'language', @@ -166,9 +162,7 @@ module.exports = { /* Amount of time to show splash screen, when enabled, in milliseconds */ splashScreenTime: 1000, /* Page meta-data, rendered in the header of each view */ - metaTagData: [ - { name: 'description', content: 'A simple static homepage for you\'re server' }, - ], + metaTagData: [{ name: 'description', content: "A simple static homepage for you're server" }], /* Default option for Toast messages */ toastedOptions: { position: 'bottom-center', @@ -212,8 +206,10 @@ module.exports = { generativeFallback: 'https://evatar.io/{icon}', localPath: './item-icons', faviconName: 'favicon.ico', - homeLabIcons: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/master/png/{icon}.png', - homeLabIconsFallback: 'https://raw.githubusercontent.com/NX211/homer-icons/master/png/{icon}.png', + homeLabIcons: + 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/master/png/{icon}.png', + homeLabIconsFallback: + 'https://raw.githubusercontent.com/NX211/homer-icons/master/png/{icon}.png', }, /* API endpoints for widgets that need to fetch external data */ widgetApiEndpoints: { @@ -231,6 +227,7 @@ module.exports = { exchangeRates: 'https://v6.exchangerate-api.com/v6/', flights: 'https://aerodatabox.p.rapidapi.com/flights/airports/icao/', githubTrending: 'https://gh-trending-repos.herokuapp.com/', + hackernewsTrending: 'https://hacker-news.firebaseio.com/v0', healthChecks: 'https://healthchecks.io/api/v1/checks', holidays: 'https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange', jokes: 'https://v2.jokeapi.dev/joke/', From cfdd4a13e819fa7879206d476a08733e3cfc1c7d Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:01:16 +0200 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9C=A8=20basic=20Widget=20which=20fetche?= =?UTF-8?q?s=20the=20HN=20posts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Widgets/HackernewsTrending.vue | 128 ++++++++++++++++-- 1 file changed, 115 insertions(+), 13 deletions(-) diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue index 348d5783..a61ac64c 100644 --- a/src/components/Widgets/HackernewsTrending.vue +++ b/src/components/Widgets/HackernewsTrending.vue @@ -1,10 +1,20 @@ @@ -21,34 +31,126 @@ export default { trendingPosts: null, }; }, - filters: { - debug() { console.debug('Not implemented'); }, - }, computed: { storyType() { // This can be `beststories`, `topstories` or newstories - return this.options.stories || 'beststories'; + // TODO: display error message if another string not matching the keywords was insert + return this.options.stories || 'topstories'; }, limit() { return this.options.limit || 10; }, endpoint() { - return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json` + return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json`; }, }, methods: { fetchData() { - console.log("Let's fetch some Data"); - this.makeRequest(this.endpoint).then(this.fetchPostDetails) + this.makeRequest(this.endpoint).then(this.fetchPostDetails); }, async fetchPostDetails(data) { - const topPosts = data.slice(0, this.limit) + const topPosts = data.slice(0, this.limit); const allData = topPosts.map((post) => { const url = `${widgetApiEndpoints.hackernewsTrending}/item/${post}.json`; return this.makeRequest(url); }) - Promise.all(allData).then((values) => console.log(values)) + Promise.all(allData).then((resolvedPostValues) => { + this.trendingPosts = resolvedPostValues.map((element, index) => { + element.originURL = `https://news.ycombinator.com/item?id=${topPosts.at(index)}` + return element + }); + console.log(this.trendingPosts) + }); }, + formatDate(unixTime) { + const date = new Date(unixTime * 1000); + // Then specify how you want your dates to be formatted + return new Intl.DateTimeFormat('default', {dateStyle: 'long'}).format(date); + } }, }; + + From 098600365af76ca8dd3f50d634acc22fec872ef2 Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:14:41 +0200 Subject: [PATCH 3/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20rename=20story=20type?= =?UTF-8?q?=20fetch=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Widgets/HackernewsTrending.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue index a61ac64c..dad694fd 100644 --- a/src/components/Widgets/HackernewsTrending.vue +++ b/src/components/Widgets/HackernewsTrending.vue @@ -32,7 +32,7 @@ export default { }; }, computed: { - storyType() { + stories() { // This can be `beststories`, `topstories` or newstories // TODO: display error message if another string not matching the keywords was insert return this.options.stories || 'topstories'; @@ -41,7 +41,7 @@ export default { return this.options.limit || 10; }, endpoint() { - return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json`; + return `${widgetApiEndpoints.hackernewsTrending}/${this.stories}.json`; }, }, methods: { From 503d66206519b896744d7328132f429c7f55b2fc Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:15:19 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=E2=9C=A8=20=F0=9F=93=9D=20document=20HN=20?= =?UTF-8?q?trending=20Widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/widgets.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/widgets.md b/docs/widgets.md index cc9a1450..bc722308 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -35,6 +35,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a - [GitHub Trending](#github-trending) - [GitHub Profile Stats](#github-profile-stats) - [Healthchecks Status](#healthchecks-status) + - [Hackernews Trending](#hackernews-trending) - [Mvg Departure](#mvg-departure) - [Mvg Connection](#mvg-connection) - **[Self-Hosted Services Widgets](#self-hosted-services-widgets)** @@ -1178,6 +1179,25 @@ Display status of one or more HealthChecks project(s). Works with healthcheck.io --- +### Hackernews Trending + +Display new and trending Posts from Hackernews + +#### Options +**Field** | **Type** | **Required** | **Description** +--- | --- | --- | --- +**`stories`** | `string` | _Optional_ | HN Stories to display defaults to `topstories`. Options are: `beststories`, `topstories` or `newstories` + +##### Example + +```yaml +- type: hackernews-trending + options: + stories: newstories +``` + +--- + ### MVG Departure Display departure time of a MVG (Münchner Verkehrs Gesellschaft) station. From 7e1057d05985c32e5b070623e916a6f59acd22d8 Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:25:03 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=9A=A8=20=E2=9A=B0=EF=B8=8F=20remove?= =?UTF-8?q?=20unused=20css,=20fix=20linting=20issues=20in=20HN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Widgets/HackernewsTrending.vue | 54 +++++-------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue index dad694fd..1698150a 100644 --- a/src/components/Widgets/HackernewsTrending.vue +++ b/src/components/Widgets/HackernewsTrending.vue @@ -6,12 +6,10 @@

{{ trendingPosts.title }}

-
- -
+

score: {{ trendingPosts.score }}

@@ -53,20 +51,19 @@ export default { const allData = topPosts.map((post) => { const url = `${widgetApiEndpoints.hackernewsTrending}/item/${post}.json`; return this.makeRequest(url); - }) + }); Promise.all(allData).then((resolvedPostValues) => { this.trendingPosts = resolvedPostValues.map((element, index) => { - element.originURL = `https://news.ycombinator.com/item?id=${topPosts.at(index)}` - return element + const trendingPost = { ...element, originURL: `https://news.ycombinator.com/item?id=${topPosts.at(index)}` }; + return trendingPost; }); - console.log(this.trendingPosts) }); }, formatDate(unixTime) { - const date = new Date(unixTime * 1000); - // Then specify how you want your dates to be formatted - return new Intl.DateTimeFormat('default', {dateStyle: 'long'}).format(date); - } + const date = new Date(unixTime * 1000); + // Then specify how you want your dates to be formatted + return new Intl.DateTimeFormat('default', { dateStyle: 'long' }).format(date); + }, }, }; @@ -117,39 +114,12 @@ export default { opacity: var(--dimming-factor); color: var(--widget-text-color); } - img.post-img { - border-radius: var(--curve-factor); - width: 2rem; - height: 2rem; - margin-right: 0.5rem; - } - } - .post-body { - font-size: 0.85rem; - color: var(--widget-text-color); - max-height: 400px; - overflow: hidden; - ::v-deep p { - margin: 0.5rem 0; - } - ::v-deep img { - max-width: 80%; - display: flex; - margin: 0 auto; - border-radius: var(--curve-factor); - } - ::v-deep a { + p.post-score { + font-size: 0.8rem; + margin: 0; + opacity: var(--dimming-factor); color: var(--widget-text-color); } - ::v-deep svg path { - fill: var(--widget-text-color); - } - ::v-deep blockquote { - margin-left: 0.5rem; - padding-left: 0.5rem; - border-left: 4px solid var(--widget-text-color); - } - ::v-deep .avatar.avatar-user { display: none; } } } } From 2d77a155d57a4693dc8f49f58b80c278307d4e85 Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:29:19 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20dead=20css=20?= =?UTF-8?q?in=20HN=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Widgets/HackernewsTrending.vue | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue index 1698150a..09680f2d 100644 --- a/src/components/Widgets/HackernewsTrending.vue +++ b/src/components/Widgets/HackernewsTrending.vue @@ -75,24 +75,6 @@ export default { align-items: center; text-decoration: none; margin: 0.25rem 0 0.5rem 0; - p.feed-title { - margin: 0; - font-size: 1.2rem; - font-weight: bold; - color: var(--widget-text-color); - } - p.feed-author { - margin: 0; - font-size: 0.8rem; - opacity: var(--dimming-factor); - color: var(--widget-text-color); - } - img.feed-icon { - border-radius: var(--curve-factor); - width: 2rem; - height: 2rem; - margin-right: 0.5rem; - } } .post-row { From 040b472a054fabd9d1cc1a2392fcdd730ab8e53d Mon Sep 17 00:00:00 2001 From: Josua Blejeru Date: Wed, 24 May 2023 12:31:42 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=93=9D=20document=20post=20size=20opt?= =?UTF-8?q?ion=20in=20HN=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/widgets.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/widgets.md b/docs/widgets.md index bc722308..24f75874 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -1187,6 +1187,7 @@ Display new and trending Posts from Hackernews **Field** | **Type** | **Required** | **Description** --- | --- | --- | --- **`stories`** | `string` | _Optional_ | HN Stories to display defaults to `topstories`. Options are: `beststories`, `topstories` or `newstories` +**`limit`** | `int` | _Optional_ | The size of the list of Posts to show. ##### Example @@ -1194,6 +1195,7 @@ Display new and trending Posts from Hackernews - type: hackernews-trending options: stories: newstories + limit: 10 ``` ---