Skip to content

Commit 9fb685c

Browse files
Updated now page and shortcodes to handle custom cases
1 parent 5d30c60 commit 9fb685c

3 files changed

Lines changed: 36 additions & 25 deletions

File tree

‎content/now.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ ShowReadingTime: false
88
dataDir: "data"
99
---
1010

11-
##### Last updated on 21-11-2024
11+
##### Last updated on 28-11-2024
1212

13-
I’m currently in 🌍 **[{{< currentlocation >}}](https://what3words.com/inferior.reserved.drives)**!
13+
🌍 I’m based in **[{{< currentlocation >}}](https://what3words.com/inferior.reserved.drives)** but currently in Chennai, India for vacation!
1414

15-
The local time here is ⏰ **{{< current_time >}}**
15+
⏰ The local time here is **{{< current_time timezone="Asia/Kolkata" >}}**
1616

17-
{{< current_weather >}}
17+
{{< current_weather location="Chennai" >}}
1818

1919
---
2020

@@ -30,7 +30,7 @@ The local time here is ⏰ **{{< current_time >}}**
3030

3131
I'll be in India from 23rd November to 16th December.
3232

33-
My current plan is Mumbai → Nagpur → Chennai → Kochi.
33+
My current plan is ~~Mumbai~~ → ~~Nagpur~~ → Thanjavur → Chennai → Kochi.
3434

3535
I'm excited to visit Mumbai to meet a friend after a long time, try some yummy street food, attend a friend's wedding in Nagpur, reconnect with family in Chennai, and spend time at home. We'll also take a short trip to my wife's ancestral house in Tanjavur! Super excited!
3636

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
<span id="current-time">Loading...</span>
2-
1+
<span id="current-time-{{ .Ordinal }}">Loading...</span>
32
<script>
4-
async function fetchCurrentTime() {
5-
const timezone = "{{ .Site.Params.Timezone }}";
3+
(function() {
4+
const timezone = "{{ .Get "timezone" | default "UTC" }}";
5+
const elementId = "current-time-{{ .Ordinal }}";
66

7-
try {
8-
// Fetch current time based on the timezone from the config.yaml
9-
const timeResponse = await fetch(`https://timeapi.io/api/Time/current/zone?timeZone=${timezone}`);
10-
const timeData = await timeResponse.json();
11-
const currentTime = new Date(timeData.dateTime).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
12-
13-
// Update the HTML content
14-
document.getElementById("current-time").textContent = currentTime;
15-
16-
} catch (error) {
17-
console.error("Error fetching current time:", error);
7+
function updateTime() {
8+
const timeElement = document.getElementById(elementId);
9+
const options = {
10+
hour: '2-digit',
11+
minute: '2-digit',
12+
timeZone: timezone
13+
};
14+
15+
try {
16+
timeElement.textContent = new Date().toLocaleString('en-US', options);
17+
} catch (error) {
18+
console.error("Error displaying time:", error);
19+
timeElement.textContent = "Invalid timezone";
20+
}
1821
}
19-
}
20-
21-
fetchCurrentTime();
22-
</script>
22+
23+
updateTime();
24+
setInterval(updateTime, 60000);
25+
})();
26+
</script>

‎themes/hugo-PaperMod/layouts/shortcodes/current_weather.html‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
<script async>
44
const el = document.getElementById("temperature");
5-
const loc = "{{ .Site.Params.CurrentLocation | urlize }}";
5+
6+
// Function to get location from shortcode call or default to Params
7+
function getLocation() {
8+
// Replace '{{ .Get "location" | default .Site.Params.CurrentLocation | urlize }}' dynamically using Hugo
9+
return "{{ .Get "location" | default .Site.Params.CurrentLocation | urlize }}";
10+
}
11+
12+
const loc = getLocation();
613

714
const map = {
815
"🌑": "It's a new moon 🌑, so the sky will be dark tonight.",

0 commit comments

Comments
 (0)