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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
"""
PodcastItLater Episode Detail Components.
Components for displaying individual episode pages with media player,
share functionality, and signup prompts for non-authenticated users.
"""
# : out podcastitlater-episode
# : dep ludic
import Biz.PodcastItLater.UI as UI
import ludic.html as html
import typing
from ludic.attrs import Attrs
from ludic.components import Component
from ludic.types import AnyChildren
from typing import override
class EpisodePlayerAttrs(Attrs):
"""Attributes for EpisodePlayer component."""
audio_url: str
title: str
class EpisodePlayer(Component[AnyChildren, EpisodePlayerAttrs]):
"""HTML5 audio player for episode playback."""
@override
def render(self) -> html.div:
audio_url = self.attrs["audio_url"]
return html.div(
html.div(
html.div(
html.h5(
html.i(classes=["bi", "bi-play-circle", "me-2"]),
"Listen",
classes=["card-title", "mb-3"],
),
html.audio(
html.source(src=audio_url, type="audio/mpeg"),
"Your browser does not support the audio element.",
controls=True,
preload="metadata",
classes=["w-100"],
style={"max-width": "100%"},
),
classes=["card-body"],
),
classes=["card", "mb-4"],
),
)
class ShareButtonAttrs(Attrs):
"""Attributes for ShareButton component."""
share_url: str
class ShareButton(Component[AnyChildren, ShareButtonAttrs]):
"""Button to copy episode URL to clipboard."""
@override
def render(self) -> html.div:
share_url = self.attrs["share_url"]
return html.div(
html.div(
html.div(
html.h5(
html.i(classes=["bi", "bi-share", "me-2"]),
"Share Episode",
classes=["card-title", "mb-3"],
),
html.div(
html.div(
html.button(
html.i(classes=["bi", "bi-copy", "me-1"]),
"Copy",
type="button",
id="share-button",
on_click=f"navigator.clipboard.writeText('{share_url}'); " # noqa: E501
"const btn = document.getElementById('share-button'); " # noqa: E501
"const originalHTML = btn.innerHTML; "
"btn.innerHTML = '<i class=\"bi bi-check me-1\"></i>Copied!'; " # noqa: E501
"btn.classList.remove('btn-outline-secondary'); " # noqa: E501
"btn.classList.add('btn-success'); "
"setTimeout(() => {{ "
"btn.innerHTML = originalHTML; "
"btn.classList.remove('btn-success'); "
"btn.classList.add('btn-outline-secondary'); "
"}}, 2000);",
classes=["btn", "btn-outline-secondary"],
),
html.input(
type="text",
value=share_url,
readonly=True,
on_focus="this.select()",
classes=["form-control"],
),
classes=["input-group"],
),
),
classes=["card-body"],
),
classes=["card"],
),
classes=["mb-4"],
)
class SignupBannerAttrs(Attrs):
"""Attributes for SignupBanner component."""
creator_email: str
base_url: str
class SignupBanner(Component[AnyChildren, SignupBannerAttrs]):
"""Banner prompting non-authenticated users to sign up."""
@override
def render(self) -> html.div:
creator_email = self.attrs["creator_email"]
return html.div(
html.div(
html.div(
html.div(
html.i(
classes=[
"bi",
"bi-info-circle-fill",
"me-2",
],
),
html.strong("This episode was created by "),
html.code(
creator_email,
classes=["text-dark"],
),
html.strong(" using PodcastItLater."),
classes=["mb-3"],
),
html.div(
html.p(
"Want to convert your own articles "
"to podcast episodes?",
classes=["mb-2"],
),
html.form(
html.div(
html.input(
type="email",
name="email",
placeholder="Enter your email to start",
required=True,
classes=["form-control"],
),
html.button(
html.i(
classes=[
"bi",
"bi-arrow-right-circle",
"me-2",
],
),
"Sign Up",
type="submit",
classes=["btn", "btn-primary"],
),
classes=["input-group"],
),
hx_post="/login",
hx_target="#signup-result",
hx_swap="innerHTML",
),
html.div(id="signup-result", classes=["mt-2"]),
),
classes=["card-body"],
),
classes=["card", "border-primary"],
),
classes=["mb-4"],
)
class EpisodeDetailPageAttrs(Attrs):
"""Attributes for EpisodeDetailPage component."""
episode: dict[str, typing.Any]
creator_email: str | None
user: dict[str, typing.Any] | None
base_url: str
class EpisodeDetailPage(Component[AnyChildren, EpisodeDetailPageAttrs]):
"""Full page view for a single episode."""
@override
def render(self) -> UI.PageLayout:
episode = self.attrs["episode"]
creator_email = self.attrs.get("creator_email")
user = self.attrs.get("user")
base_url = self.attrs["base_url"]
share_url = f"{base_url}/episode/{episode['id']}"
duration_str = UI.format_duration(episode.get("duration"))
# Build page title
page_title = f"{episode['title']} - PodcastItLater"
# Build meta tags for Open Graph
meta_tags = [
html.meta(property="og:title", content=episode["title"]),
html.meta(property="og:type", content="website"),
html.meta(property="og:url", content=share_url),
html.meta(
property="og:description",
content=f"Listen to this article read aloud. "
f"Duration: {duration_str}"
+ (f" by {episode['author']}" if episode.get("author") else ""),
),
html.meta(
property="og:site_name",
content="PodcastItLater",
),
html.meta(property="og:audio", content=episode["audio_url"]),
html.meta(property="og:audio:type", content="audio/mpeg"),
]
# Add Twitter Card tags
meta_tags.extend([
html.meta(name="twitter:card", content="summary"),
html.meta(name="twitter:title", content=episode["title"]),
html.meta(
name="twitter:description",
content=f"Listen to this article. Duration: {duration_str}",
),
])
# Add author if available
if episode.get("author"):
meta_tags.append(
html.meta(property="article:author", content=episode["author"]),
)
return UI.PageLayout(
# Show signup banner if user is not logged in
SignupBanner(
creator_email=creator_email or "a user",
base_url=base_url,
)
if not user and creator_email
else html.div(),
# Episode title and metadata
html.div(
html.h2(
episode["title"],
classes=["display-6", "mb-3"],
),
html.div(
html.span(
html.i(classes=["bi", "bi-person", "me-1"]),
f"by {episode['author']}",
classes=["text-muted", "me-3"],
)
if episode.get("author")
else html.span(),
html.span(
html.i(classes=["bi", "bi-clock", "me-1"]),
f"Duration: {duration_str}",
classes=["text-muted", "me-3"],
),
html.span(
html.i(classes=["bi", "bi-calendar", "me-1"]),
f"Created: {episode['created_at']}",
classes=["text-muted"],
),
classes=["mb-3"],
),
html.div(
html.a(
html.i(classes=["bi", "bi-link-45deg", "me-1"]),
"View original article",
href=episode["original_url"],
target="_blank",
rel="noopener",
classes=["btn", "btn-sm", "btn-outline-secondary"],
),
)
if episode.get("original_url")
else html.div(),
classes=["mb-4"],
),
# Audio player
EpisodePlayer(
audio_url=episode["audio_url"],
title=episode["title"],
),
# Share button
ShareButton(share_url=share_url),
# Back to home link
html.div(
html.a(
html.i(classes=["bi", "bi-arrow-left", "me-1"]),
"Back to Home",
href="/",
classes=["btn", "btn-link"],
),
classes=["mt-4"],
),
user=user,
current_page="",
error=None,
page_title=page_title,
meta_tags=meta_tags,
)
|