-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
467 lines (454 loc) · 17.9 KB
/
index.html
File metadata and controls
467 lines (454 loc) · 17.9 KB
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Search News • HASYIM56</title>
<!-- SEO META -->
<meta name="description" content="Search News Demo by HASYIM56 – Platform pencarian berita terkini berbasis API yang dapat diakses secara cepat dan mudah. Temukan informasi terbaru dari berbagai kategori seperti teknologi, bisnis, hiburan, kesehatan, sains, olahraga, dan dunia dalam Bahasa Indonesia atau English. Didukung tampilan dark mode modern, smooth, responsif, serta integrasi API yang stabil dan real-time. Cocok untuk kebutuhan riset, update harian, dan demo integrasi API berita.">
<meta name="keywords" content="search news, demo api berita, berita terkini, pencarian berita, teknologi, bisnis, hiburan, kesehatan, sains, olahraga, dunia, HASYIM56, dark mode, responsive, API berita, Indonesia, English">
<meta name="author" content="HASYIM56">
<meta property="og:title" content="Demo Search News • HASYIM56">
<meta property="og:description" content="Platform demo pencarian berita real-time, lengkap dengan kategori dan bahasa. Didukung API stabil, tampilan modern, dan fitur smooth UX.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://github.com/HASYIM56/Search-News-Demo/">
<meta property="og:site_name" content="Search News Demo HASYIM56">
<meta property="og:image" content="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/logo.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="600">
<meta property="og:image:height" content="600">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Demo Search News • HASYIM56">
<meta name="twitter:description" content="Platform demo pencarian berita real-time, lengkap dengan kategori dan bahasa. Didukung API stabil, tampilan modern, dan fitur smooth UX.">
<meta name="twitter:image" content="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<meta name="twitter:site" content="@HASYIM56">
<meta name="twitter:creator" content="@HASYIM56">
<link rel="canonical" href="https://github.com/HASYIM56/Search-News-Demo/">
<!-- Favicon & Apple Touch Icons -->
<link rel="icon" type="image/png" sizes="32x32" href="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<link rel="apple-touch-icon" sizes="180x180" href="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<link rel="shortcut icon" href="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<meta name="msapplication-TileColor" content="#7aa2ff">
<meta name="msapplication-TileImage" content="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">
<meta name="theme-color" content="#0b0d10">
<!-- Google Fonts: Inter for UI, Merriweather for news title -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Merriweather:wght@700&display=swap" rel="stylesheet">
<style>
:root{
--bg:#0b0d10;
--panel:#12151a;
--muted:#79808a;
--text:#e8eaed;
--accent:#7aa2ff;
--accent-2:#8b5cf6;
--ring: rgba(122,162,255,.35);
--radius:18px;
--shadow:0 10px 30px rgba(0,0,0,.28);
--fade:rgba(122,162,255,.13);
--card-hover:rgba(122,162,255,.07);
--card-border:rgba(122,162,255,.12);
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
font: 16px/1.7 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial;
color:var(--text);
background: radial-gradient(1200px 800px at 10% -10%, rgba(138,92,246,.08), transparent 60%),
radial-gradient(1000px 600px at 100% 0%, rgba(122,162,255,.07), transparent 50%),
var(--bg);
transition: background 0.3s;
}
.wrap{
max-width:1100px;
margin:0 auto;
padding:32px 24px 24px 24px;
}
header{
display:flex;
gap:18px;
align-items:center;
justify-content:space-between;
margin-bottom:24px;
}
.title{
font-family:'Merriweather', serif;
font-weight:700;
letter-spacing:.2px;
font-size:clamp(22px, 4vw, 31px);
color:var(--accent-2);
text-shadow:0 2px 10px rgba(138,92,246,.12);
transition: color .2s;
}
.badge{
font-size:13px;
color:var(--muted);
background:var(--fade);
border-radius:9px;
padding:4px 12px;
box-shadow:0 2px 8px rgba(0,0,0,.07);
border:1px solid rgba(255,255,255,.03);
font-weight:500;
}
.panel{
background:rgba(18,21,26,.77);
backdrop-filter: blur(14px);
border:1px solid var(--card-border);
box-shadow:var(--shadow);
border-radius:var(--radius);
transition: background .2s, border .2s;
}
form#searchForm{
display:grid;
gap:14px;
grid-template-columns: 1fr;
padding:20px 18px 10px 18px;
border-radius:var(--radius) var(--radius) 0 0;
background:linear-gradient(180deg, #181a1f 0%, #12151a 100%);
}
.fields{display:grid; gap:11px; grid-template-columns: 1fr;}
@media(min-width:720px){
form#searchForm{grid-template-columns: 1fr auto}
.fields{grid-template-columns: 1.4fr .8fr .8fr}
}
input[type="text"], select{
font-family:'Inter', system-ui;
width:100%;
padding:15px 16px;
border-radius:14px;
border:1.5px solid rgba(255,255,255,.11);
background:linear-gradient(180deg, #14161c 0%, #12151a 100%);
color:var(--text);
outline:none;
font-size:16px;
letter-spacing:.05px;
transition: box-shadow .2s, border-color .2s, transform .06s;
box-shadow:0 2px 8px rgba(122,162,255,.07);
}
input:focus, select:focus{
border-color:var(--accent);
box-shadow:0 0 0 7px var(--ring);
background:linear-gradient(180deg, #181a1f 0%, #14161c 100%);
}
select{
font-weight:500;
}
button{
cursor:pointer;
border:0;
padding:15px 22px;
border-radius:14px;
font-weight:600;
font-family:'Inter', system-ui;
color:#0b0d10;
background:linear-gradient(90deg, #a8c0ff 0%, #7aa2ff 100%);
transition: transform .08s, box-shadow .15s;
box-shadow:0 8px 24px rgba(122,162,255,.12);
font-size:16px;
letter-spacing:.03px;
}
button:active{transform: translateY(1px)}
button:hover{
background:linear-gradient(90deg, #8b5cf6 0%, #7aa2ff 100%);
box-shadow:0 4px 16px rgba(122,162,255,.21);
}
.toolbar{
display:flex; gap:12px; align-items:center; justify-content:flex-end;
padding:12px 20px;
border-top:1px solid rgba(255,255,255,.05);
border-radius:0 0 var(--radius) var(--radius);
background:linear-gradient(90deg, #181a1f 0%, #12151a 100%);
}
.info{display:flex; gap:10px; align-items:center; color:var(--muted); font-size:13px}
.dot{width:10px;height:10px;border-radius:50%;background:#86efac; box-shadow:0 0 0 6px rgba(134,239,172,.15)}
.warn{background:#fbbf24}
.err{background:#f87171}
#stats.badge{margin-top:16px; margin-bottom:4px;}
.results{
display:grid;
gap:18px;
grid-template-columns: 1fr;
margin-top:24px;
margin-bottom:10px;
transition: gap .2s;
}
@media(min-width:740px){.results{grid-template-columns: repeat(2, 1fr)}}
@media(min-width:1020px){.results{grid-template-columns: repeat(3, 1fr)}}
.card{
overflow:hidden;
border-radius:18px;
border:1.5px solid var(--card-border);
background:var(--panel);
display:flex;
flex-direction:column;
min-height:260px;
box-shadow:0 3px 22px rgba(122,162,255,.07);
transition: box-shadow .23s, background .25s;
position:relative;
}
.card:hover{
box-shadow:0 4px 40px rgba(122,162,255,.16), 0 2px 18px rgba(138,92,246,.07);
background:var(--card-hover);
}
.thumb{
position:relative;
background:#0f1217;
aspect-ratio:16/9;
overflow:hidden;
border-bottom:1px solid rgba(255,255,255,.06);
display:flex;
align-items:center;
justify-content:center;
}
.thumb img{
width:100%;
height:100%;
object-fit:cover;
display:block;
transition: transform .6s cubic-bezier(.38,.94,.42,1.03), filter .15s;
filter:brightness(0.98) contrast(1.03);
border-radius:0 0 14px 14px;
}
.card:hover .thumb img{transform:scale(1.035);filter:brightness(1.04);}
.content{
padding:16px 14px 14px 14px;
display:flex;
gap:10px;
flex-direction:column;
}
.titleLink{
color:var(--accent-2);
text-decoration:none;
font-family:'Merriweather', serif;
font-size:1.11em;
font-weight:700;
letter-spacing:.01em;
line-height:1.3;
margin-bottom:2px;
transition: color .18s;
word-break:break-word;
}
.titleLink:hover{ text-decoration:underline; color:var(--accent);}
.meta{
display:flex; gap:12px; flex-wrap:wrap; align-items:center; color:var(--muted); font-size:13px;
font-family:'Inter', system-ui;
opacity:.99;
}
.source{opacity:.85;font-weight:500;}
.desc{
color:#c9ccd1;
font-size:15px;
font-family:'Inter', system-ui;
margin-top:4px;
opacity:.97;
line-height:1.55;
word-break:break-word;
}
.empty{
opacity:.77;
text-align:center;
padding:44px 12px;
font-size:18px;
border-radius:var(--radius);
font-family:'Inter', system-ui;
color:var(--muted);
}
.skeleton{
animation: pulse 1.1s infinite ease-in-out;
background: linear-gradient(90deg, rgba(255,255,255,.06), rgba(255,255,255,.13), rgba(255,255,255,.06));
background-size:200% 100%;
border-radius:14px;
min-height:22px;
}
@keyframes pulse{0%{background-position:200% 0}100%{background-position:-200% 0}}
.footer{
margin:46px 0 20px;
color:var(--muted);
font-size:13px;
text-align:center;
font-family:'Inter', system-ui;
letter-spacing:.03px;
opacity:.93;
}
.count{
font-weight:600;
color:var(--accent-2);
background:var(--fade);
padding:2px 8px;
border-radius:8px;
font-family:'Inter', system-ui;
}
/* Smooth transitions for UI elements */
.panel, .card, .results, .title, input, select, button, .badge, .toolbar, .footer{
transition: background .18s, color .17s, border .15s, box-shadow .15s;
}
/* Add scroll bar styling for dark theme */
::-webkit-scrollbar {
width: 10px;
background: var(--panel);
}
::-webkit-scrollbar-thumb {
background: var(--accent);
border-radius: 10px;
}
::-webkit-scrollbar-thumb:active {
background: var(--accent-2);
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div class="title">🔎 Demo News Search</div>
<div class="badge" id="apiStatus">Memuat status API…</div>
</header>
<section class="panel">
<form id="searchForm">
<div class="fields">
<input id="q" name="q" type="text" placeholder="Cari topik berita (mis. teknologi, sepak bola, politik)…" />
<select id="language" name="language" aria-label="Bahasa">
<option value="id" selected>Bahasa Indonesia</option>
<option value="en">English</option>
</select>
<select id="category" name="category" aria-label="Kategori">
<option value="">Semua Kategori</option>
<option value="technology">Technology</option>
<option value="business">Business</option>
<option value="entertainment">Entertainment</option>
<option value="health">Health</option>
<option value="science">Science</option>
<option value="sports">Sports</option>
<option value="world">World</option>
</select>
</div>
<button type="submit">Cari Berita</button>
</form>
<div class="toolbar">
<div class="info" id="infoBar">
<span class="dot" id="statusDot"></span>
<span id="infoText">Siap mencari berita.</span>
</div>
</div>
</section>
<section id="stats" class="badge" style="margin-top:10px; display:none"></section>
<section id="results" class="results" aria-live="polite" aria-busy="false"></section>
<div class="footer">
<img src="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png" alt="HASYIM56" style="height:18px;vertical-align:middle;margin-right:6px;border-radius:4px;">
Powered by <span class="count">h56-search-news-api</span> • Demo sederhana (dark, smooth)
</div>
</div>
<script>
const API_BASE = 'https://h56-search-news-api.netlify.app/api/news';
// === Basic API Info Request (as given) ===
fetch(API_BASE)
.then(r => r.json())
.then(data => {
const s = document.getElementById('apiStatus');
if (data && (data.status || data.ok)) {
s.textContent = 'API siap digunakan';
} else {
s.textContent = 'API terhubung';
}
})
.catch(() => {
const s = document.getElementById('apiStatus');
s.textContent = 'Gagal cek API';
});
const resultsEl = document.getElementById('results');
const infoBar = document.getElementById('infoBar');
const statusDot = document.getElementById('statusDot');
const infoText = document.getElementById('infoText');
const statsEl = document.getElementById('stats');
function setBusy(b){
resultsEl.setAttribute('aria-busy', String(b));
statusDot.className = 'dot' + (b ? ' warn' : '');
infoText.textContent = b ? 'Mencari berita…' : 'Selesai.';
}
function fmtDate(s){
try{ const d = new Date(s); return d.toLocaleString(undefined, {year:'numeric', month:'short', day:'2-digit', hour:'2-digit', minute:'2-digit'}); }catch{ return s }
}
function getImageFromArticle(a){
// Tolerate different fields the API may use
return a.image_url || a.image || a.thumbnail || (a.enclosure && a.enclosure.url) || 'https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png';
}
function renderSkeleton(n=6){
resultsEl.innerHTML = '';
for(let i=0;i<n;i++){
const c = document.createElement('div');
c.className = 'card';
c.innerHTML = `
<div class="thumb skeleton"></div>
<div class="content">
<div class="skeleton" style="height:18px; width:80%"></div>
<div class="skeleton" style="height:12px; width:60%"></div>
<div class="skeleton" style="height:12px; width:40%"></div>
</div>`;
resultsEl.appendChild(c);
}
}
function renderResults(list){
resultsEl.innerHTML = '';
if(!list || !list.length){
resultsEl.innerHTML = `<div class="panel empty">Tidak ada hasil. Coba kata kunci lain atau ganti kategori/bahasa.</div>`;
return;
}
const frag = document.createDocumentFragment();
list.forEach(a => {
const img = getImageFromArticle(a);
const card = document.createElement('article');
card.className = 'card';
card.innerHTML = `
<div class="thumb">${img ? `<img alt="" loading="lazy" src="${img}">` : `<img alt="" loading="lazy" src="https://raw.githubusercontent.com/HASYIM56/Search-News-Demo/main/H56.png">`}</div>
<div class="content">
<a class="titleLink" target="_blank" rel="noopener noreferrer" href="${a.link || a.url}"><strong>${a.title || 'Tanpa judul'}</strong></a>
<div class="meta">
<span class="source">${a.source_id || a.source || 'Sumber tak diketahui'}</span>
${a.pubDate ? `<span>• ${fmtDate(a.pubDate)}</span>` : ''}
</div>
${a.description ? `<div class="desc">${a.description}</div>` : ''}
</div>`;
frag.appendChild(card);
});
resultsEl.appendChild(frag);
}
async function searchNews(params){
const url = new URL(API_BASE);
Object.entries(params).forEach(([k,v])=>{ if(v) url.searchParams.set(k,v) });
setBusy(true); renderSkeleton(6);
try{
const res = await fetch(url.toString());
const data = await res.json();
let results = [];
let totalText = '';
if (data.status === 'success'){
results = data.results || [];
totalText = data.totalResults ? `${data.totalResults} hasil` : `${results.length} hasil`;
} else if (Array.isArray(data.articles)) {
results = data.articles;
totalText = `${results.length} hasil`;
}
statsEl.style.display = 'block';
statsEl.textContent = `Menampilkan ${results.length} dari ${totalText || 'hasil'}`;
renderResults(results);
setBusy(false);
}catch(err){
resultsEl.innerHTML = `<div class="panel empty">Terjadi kesalahan saat memuat berita. Coba lagi nanti.</div>`;
statusDot.className = 'dot err';
infoText.textContent = 'Gagal memuat.';
statsEl.style.display = 'none';
}
}
document.getElementById('searchForm').addEventListener('submit', (e)=>{
e.preventDefault();
const q = document.getElementById('q').value.trim();
const language = document.getElementById('language').value;
const category = document.getElementById('category').value;
searchNews({ q: q || 'teknologi', language, category });
});
searchNews({ q: 'teknologi', language: 'id', category: 'technology' });
</script>
</body>
</html>