Skip to content

Commit 317f2c8

Browse files
committed
Merge branch 'master' of https://github.com/casmbu/dashy
2 parents 3995a3d + 16dbadc commit 317f2c8

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed

docs/widgets.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
2929
- [Stock Price History](#stock-price-history)
3030
- [ETH Gas Prices](#eth-gas-prices)
3131
- [Joke of the Day](#joke)
32+
- [Chuck Norris quotes](#chucknorris)
3233
- [XKCD Comics](#xkcd-comics)
3334
- [Flight Data](#flight-data)
3435
- [NASA APOD](#astronomy-picture-of-the-day)
@@ -1001,6 +1002,36 @@ Renders a programming or generic joke. Data is fetched from the [JokesAPI](https
10011002

10021003
---
10031004

1005+
### Chuck Norris quotes
1006+
1007+
Renders a Chuck Norris quote. Data is fetched from the [ChuckNorrisAPI](https://api.chucknorris.io/) by @matchilling. All fields are optional.
1008+
1009+
<p align="center"><img width="400" src="https://tbd" /></p>
1010+
1011+
#### Options
1012+
1013+
**Field** | **Type** | **Required** | **Description**
1014+
--- | --- | --- | ---
1015+
**`categories`** | `string` | _Optional_ | Set the category of jokes to return. Use a string to specify a single category, or an array to pass in multiple options. Available options are: `animal`,`career`,`celebrity`,`dev`,`explicit`,`fashion`,`food`,`history`,`money`,`movie`,`music`,`political`,`religion`,`science`,`sport` and `travel`. An up-to-date list of supported categories can be found [here](https://api.chucknorris.io/jokes/categories). Defaults to not explicitely set and therefore any of the categories can come up.
1016+
1017+
#### Example
1018+
1019+
```yaml
1020+
- type: chucknorris
1021+
options:
1022+
categories: history,sport
1023+
```
1024+
1025+
#### Info
1026+
1027+
- **CORS**: 🟢 Enabled
1028+
- **Auth**: 🟢 Not Required
1029+
- **Price**: 🟢 Free
1030+
- **Host**: Managed Instance
1031+
- **Privacy**: _See [matchilling's Privacy Policy](https://api.chucknorris.io/privacy)_
1032+
1033+
---
1034+
10041035
### XKCD Comics
10051036

10061037
Have a laugh with the daily comic from [XKCD](https://xkcd.com/). A classic webcomic website covering everything from Linux, math, romance, science and language. All fields are optional.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<div class="chuckNorris-wrapper">
3+
<p class="chuckNorris chuckNorris-line">{{ chuckNorrisLine }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
import axios from 'axios';
9+
import WidgetMixin from '@/mixins/WidgetMixin';
10+
import { widgetApiEndpoints } from '@/utils/defaults';
11+
12+
export default {
13+
mixins: [WidgetMixin],
14+
components: {},
15+
data() {
16+
return {
17+
chuckNorrisLine: null,
18+
};
19+
},
20+
computed: {
21+
/* Format the users preferred categories */
22+
categories() {
23+
let usersChoice = this.options.categories;
24+
if (!usersChoice) return '';
25+
if (Array.isArray(usersChoice)) usersChoice = usersChoice.join(',');
26+
const categories = ["animal","career","celebrity","dev","explicit","fashion","food","history","money","movie","music","political","religion","science","sport","travel"];
27+
if (categories.some((cat) => usersChoice.toLowerCase().includes(cat))) return usersChoice;
28+
return '';
29+
},
30+
/* Combine data parameters for the API endpoint */
31+
endpoint() {
32+
if (this.categories !== '') return `${widgetApiEndpoints.chuckNorris}?category=${this.categories}`;
33+
return `${widgetApiEndpoints.chuckNorris}`;
34+
},
35+
},
36+
methods: {
37+
/* Make GET request to ChuckNorris API endpoint */
38+
fetchData() {
39+
axios.get(this.endpoint)
40+
.then((response) => {
41+
this.processData(response.data);
42+
})
43+
.catch((dataFetchError) => {
44+
this.error('Unable to fetch any Chuck Norris quote', dataFetchError);
45+
})
46+
.finally(() => {
47+
this.finishLoading();
48+
});
49+
},
50+
/* Assign data variables to the returned data */
51+
processData(data) {
52+
this.chuckNorrisLine = data.value;
53+
},
54+
},
55+
};
56+
</script>
57+
58+
<style scoped lang="scss">
59+
.chuckNorris-wrapper {
60+
p.chuckNorris {
61+
color: var(--widget-text-color);
62+
font-size: 1.2rem;
63+
}
64+
}
65+
66+
</style>

src/components/Widgets/WidgetBase.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ const COMPAT = {
4949
anonaddy: 'addy.io',
5050
apod: 'Apod',
5151
'blacklist-check': 'BlacklistCheck',
52+
chucknorris: 'ChuckNorris',
5253
clock: 'Clock',
54+
'code-stats': 'CodeStats',
55+
'covid-stats': 'CovidStats',
5356
'crypto-price-chart': 'CryptoPriceChart',
5457
'crypto-watch-list': 'CryptoWatchList',
5558
'custom-search': 'CustomSearch',
5659
'custom-list': 'CustomList',
5760
'cve-vulnerabilities': 'CveVulnerabilities',
5861
'domain-monitor': 'DomainMonitor',
59-
'code-stats': 'CodeStats',
60-
'covid-stats': 'CovidStats',
6162
'drone-ci': 'DroneCi',
6263
embed: 'EmbedWidget',
6364
'eth-gas-prices': 'EthGasPrices',
@@ -81,16 +82,16 @@ const COMPAT = {
8182
'gl-network-traffic': 'GlNetworkTraffic',
8283
'gl-system-load': 'GlSystemLoad',
8384
'gl-cpu-temp': 'GlCpuTemp',
85+
'gluetun-status': 'GluetunStatus',
8486
'health-checks': 'HealthChecks',
8587
'hackernews-trending': 'HackernewsTrending',
86-
'gluetun-status': 'GluetunStatus',
8788
iframe: 'IframeWidget',
8889
image: 'ImageWidget',
8990
joke: 'Jokes',
91+
linkding: 'Linkding',
9092
'minecraft-status': 'MinecraftStatus',
9193
'mullvad-status': 'MullvadStatus',
9294
mvg: 'Mvg',
93-
linkding: 'Linkding',
9495
'mvg-connection': 'MvgConnection',
9596
'nd-cpu-history': 'NdCpuHistory',
9697
'nd-load-history': 'NdLoadHistory',

src/utils/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ module.exports = {
227227
anonAddy: 'https://app.addy.io',
228228
astronomyPictureOfTheDay: 'https://apod.as93.net/apod',
229229
blacklistCheck: 'https://api.blacklistchecker.com/check',
230+
chuckNorris: 'https://api.chucknorris.io/jokes/random',
230231
codeStats: 'https://codestats.net/',
231232
covidStats: 'https://disease.sh/v3/covid-19',
232233
cryptoPrices: 'https://api.coingecko.com/api/v3/coins/',

0 commit comments

Comments
 (0)