100 lines
3.1 KiB
HTML
100 lines
3.1 KiB
HTML
{{ define "home/embed.html" }}
|
|
<html lang='en'>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Cat of the Day</title>
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=Atma:wght@300;400;500;600;700&display=swap');
|
|
|
|
.card {
|
|
background-color: #161616;
|
|
border-radius: 15px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
|
padding: 20px;
|
|
width: 90%;
|
|
max-width: 400px;
|
|
text-align: center;
|
|
transition: transform 0.2s ease-in-out;
|
|
font-family: "Atma", system-ui;
|
|
|
|
}
|
|
.cat-image {
|
|
width: 100%;
|
|
border-radius: 5px;
|
|
margin-bottom: 15px;
|
|
object-fit: cover;
|
|
max-height: auto;
|
|
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
|
|
transition: opacity 0.3s ease;
|
|
}
|
|
|
|
|
|
.button {
|
|
background-color: #9e44ae;
|
|
color: #e0e0e0;
|
|
border: none;
|
|
padding: 2px 15px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
text-decoration: none;
|
|
box-sizing: border-box;
|
|
transition: background-color 0.3s ease, transform 0.2s ease-in-out;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.button:hover {
|
|
background-color: #6d0e7e;
|
|
transform: scale(1.01);
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="card" style="margin: 0 auto;">
|
|
<img class="cat-image" id="catImage" src="{{ .imageUrl }}" alt="Cat Photo" onload="this.removeAttribute('onload')">
|
|
<a class="button" id="mastodonLink" href="{{ .postUrl }}" target="_blank" style="display: block;">View on Mastodon</a>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
<script>
|
|
const img = document.querySelector('.cat-image');
|
|
const link = document.getElementById('mastodonLink');
|
|
|
|
img.onerror = () => {
|
|
console.warn("failed to load the image - retrying...");
|
|
fetch('/api/post/random')
|
|
.then(response => {
|
|
if (!response.ok) throw new Error("Network error");
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
if (!data || !data.account || !data.media_attachments || data.media_attachments.length === 0) {
|
|
throw new Error("Invalid data format");
|
|
}
|
|
|
|
let imageUrl = data.media_attachments[0].remote_url;
|
|
if (imageUrl) {
|
|
imageUrl = imageUrl.replace('/original/', '/small/');
|
|
} else if (data.media_attachments[0].preview_url) {
|
|
imageUrl = data.media_attachments[0].preview_url;
|
|
} else {
|
|
throw new Error("No image URL found");
|
|
}
|
|
|
|
img.src = imageUrl;
|
|
link.href = data.url;
|
|
})
|
|
.catch(error => {
|
|
console.error("Failed to load fallback image:", error);
|
|
img.src = "https://s6.uupload.ir/files/im_sad_0zg9.jpg";
|
|
});
|
|
};
|
|
</script>
|
|
|
|
|
|
</html>
|
|
{{ end }}
|
|
|