-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoday.jsx
84 lines (72 loc) · 2.13 KB
/
today.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Today Widget for Übersicht
*
* Version: 1.0
* Last Updated: 02/06/2022
*
* Created by Bert Bredewold
*/
// Get's WAN IP from a dig to OpenDNS
export const command = 'today.widget/today.sh';
// Refresh every X miliseconds
export const refreshFrequency = 30000;
// Base layout
export const className = {
bottom: '5px',
right: '5px',
color: '#fff',
fontFamily: 'Cascadia Code',
fontWeight: 300,
fontSize: '12px',
textAlign: 'right'
}
const parseIcalBuddyOutput = input => {
// Regex for parsing icalbuddy's output.
const regex = /• (.*?)\n (.*?)\n(?: (attendees:.*?)\n)?(?: (location:.*?)\n)?(?: (notes:.*?)\n)?/gm;
// Match all
const matches = input.matchAll(regex);
// Array for the processed events.
const events = [];
// Construct a nice array
for (const match of matches) {
events.push({
title: match[1],
datetime: match[2],
attendees: match[3],
location: parseLocation(match[4]),
notes: match[5],
url: parseMeetingUrlFromNotes(match[5])
})
}
// Map to JSX objects
return events.map((event, index) => (
<div key={index}>
{event.url} {event.title} {event.location} ▶ {event.datetime}
</div>
));
};
const parseMeetingUrlFromNotes = notes => {
if (notes) {
const regex = /https:\/\/(?:zoom\.us|meet\.google\.com|teams.microsoft.com)\/.*? /;
const matchResult = notes.match(regex);
if (matchResult) {
return <a style={{textDecoration: 'none'}} href={matchResult}>🤙🏼</a>;
}
}
};
const parseLocation = location => {
if (location) {
return '(' + location.split('location: ')[1] + ')';
}
};
// Render the widget
export const render = ({output, error}) => {
const events = parseIcalBuddyOutput(output);
return error ? (
<div>Oops: <strong>{String(error)}</strong></div>
) : (
<div>
{parseIcalBuddyOutput(output)}
</div>
);
}