Skip to content

Commit 5ecf143

Browse files
Add links to episode description
1 parent 7fd23e1 commit 5ecf143

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed

.DS_Store

0 Bytes
Binary file not shown.

templates/item.html.php

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,64 @@
66

77
<h1 class="text-xl pb-5"><?= $item['name'] ?></h1>
88

9-
<p><img src="/image?<?= 'item_id='.$item['id'] ?: 'feed_id'.$feed['id'] ?>" class="mx-auto w-3/5 border-solid border-neutral-800 border"></p>
9+
<div class="media-container">
10+
<img src="/image?<?= 'item_id='.$item['id'] ?: 'feed_id'.$feed['id'] ?>" class="album-art">
11+
<audio autoplay controls src="/audio?item_id=<?= $item['id'] ?>" class="player"></audio>
12+
</div>
1013

11-
<p><audio autoplay controls src="/audio?item_id=<?= $item['id'] ?>" class="w-full m-4 h-13"></audio></p>
12-
13-
<p><?= $item['description'] ?></p>
14+
<div id="item-desc">
15+
<?= $item['description'] ?>
16+
</div>
1417

1518
</div>
1619

1720
<style type="text/css">
18-
#item-desc a {color: rgb(253, 230, 138);}
19-
#item-desc p {padding-bottom: 1em;}
21+
#item-desc {
22+
max-width: 65ch;
23+
margin: 0 auto;
24+
line-height: 1.6;
25+
font-size: 1.05rem;
26+
}
27+
#item-desc a {
28+
color: rgb(253, 230, 138);
29+
text-decoration: underline;
30+
}
31+
#item-desc p {
32+
margin-bottom: 1em;
33+
}
34+
35+
.media-container {
36+
max-width: 380px;
37+
margin: 0 auto 2rem;
38+
border-radius: 8px;
39+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
40+
overflow: hidden; /* ensure rounded corners apply to children */
41+
}
42+
43+
.album-art {
44+
display: block;
45+
width: 100%;
46+
height: auto;
47+
}
48+
49+
.player {
50+
width: 100%;
51+
margin: 0;
52+
border: none;
53+
background-color: #1f2937; /* neutral-800 */
54+
}
55+
56+
/* Darker controls */
57+
.player::-webkit-media-controls-panel {
58+
background-color: #1f2937;
59+
color: rgb(253, 230, 138);
60+
}
61+
62+
@media (max-width: 640px) {
63+
.media-container {
64+
max-width: 90%;
65+
}
66+
}
2067
</style>
2168
<script type="text/javascript">
2269
(function() {
@@ -41,5 +88,37 @@
4188
fetch('/set_playback', {method: 'POST', body: params});
4289
}
4390
}, interval);
91+
92+
// Convert bare URLs inside #item-desc to clickable links that open in new tab
93+
(function linkifyDesc() {
94+
const container = document.getElementById('item-desc');
95+
if (!container) return;
96+
97+
const urlRegex = /https?:\/\/[^\s]+/g;
98+
99+
function linkifyNode(node) {
100+
// Process only text nodes
101+
if (node.nodeType === Node.TEXT_NODE) {
102+
const text = node.textContent;
103+
if (!text) return;
104+
if (urlRegex.test(text)) {
105+
const span = document.createElement('span');
106+
span.innerHTML = text.replace(urlRegex, url => `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`);
107+
node.replaceWith(...span.childNodes);
108+
}
109+
} else if (node.nodeType === Node.ELEMENT_NODE && node.tagName !== 'A') {
110+
// Recurse into child nodes but skip existing anchors
111+
Array.from(node.childNodes).forEach(linkifyNode);
112+
}
113+
}
114+
115+
Array.from(container.childNodes).forEach(linkifyNode);
116+
})();
117+
118+
// Ensure any existing links open in a new window/tab
119+
document.querySelectorAll('#item-desc a').forEach(link => {
120+
link.setAttribute('target', '_blank');
121+
link.setAttribute('rel', 'noopener noreferrer');
122+
});
44123
})();
45124
</script>

0 commit comments

Comments
 (0)