1
+ ---
2
+ title: Jamstack TV
3
+ layout: layouts/base.njk
4
+ ---
5
+
6
+ {# <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected] /themes/reset-min.css" integrity="sha256-t2ATOGCtAIZNnzER679jwcFcKYfLlw01gli6F6oszk8=" crossorigin="anonymous"> #}
7
+ {# <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected] /themes/satellite-min.css" integrity="sha256-TehzF/2QvNKhGQrrNpoOb2Ck4iGZ1J/DI4pkd2oUsBc=" crossorigin="anonymous"> #}
8
+ <div class =" p-8" >
9
+ <div id =" searchbox" ></div >
10
+ <div id =" hits" ></div >
11
+ </div >
12
+ <
script src =
" https://cdn.jsdelivr.net/npm/[email protected] /dist/algoliasearch-lite.umd.js" integrity =
" sha256-EXPXz4W6pQgfYY3yTpnDa3OH8/EPn16ciVsPQ/ypsjk=" crossorigin =
" anonymous" ></
script >
13
+ <
script src =
" https://cdn.jsdelivr.net/npm/[email protected] /dist/instantsearch.production.min.js" integrity =
" sha256-LAGhRRdtVoD6RLo2qDQsU2mp+XVSciKRC8XPOBWmofM=" crossorigin =
" anonymous" ></
script >
14
+ <script >
15
+ const searchClient = algoliasearch (' {{ algolia.appId }}' , ' {{ algolia.searchOnlyApiKey }}' );
16
+
17
+ const search = instantsearch ({
18
+ indexName: ' {{ algolia.indexName }}' ,
19
+ searchClient,
20
+ });
21
+
22
+ {% raw % }
23
+ search .addWidgets ([
24
+ instantsearch .widgets .searchBox ({
25
+ container: ' #searchbox' ,
26
+ }),
27
+
28
+ instantsearch .widgets .hits ({
29
+ snippetEllipsisText: ' …' ,
30
+ container: ' #hits' ,
31
+ cssClasses: {
32
+ root: " bg-blue-900 text-blue-100" ,
33
+ // item: "bg-blue-900 text-blue-100",
34
+ },
35
+ transformItems (items ) {
36
+ return items .map (item => {
37
+ let start = item .caption .start ;
38
+
39
+ let obj = {
40
+ ... item,
41
+ url: ` https://www.youtube.com/watch?v=${ item .video .id } }&t=${ start} s` ,
42
+ };
43
+ if (start > 0 ) {
44
+ let secondsInOne = {
45
+ hour: 60 * 60 ,
46
+ minute: 60
47
+ }
48
+ function pad (num ) { return num < 10 ? ` 0${ num} ` : num; }
49
+ let hours = Math .floor (start / secondsInOne .hour );
50
+ let minutes = Math .floor ((start % secondsInOne .hour ) / secondsInOne .minute );
51
+ let seconds = Math .floor (start % secondsInOne .minute );
52
+ obj .displayStart = ` (at ${ hours ? ` ${ pad (hours)} :` : " " }${ pad (minutes)} :${ pad (seconds)} ) ` ;
53
+ // obj._highlightResult.caption.content = `…${obj._highlightResult.caption.content}`;
54
+ }
55
+ return obj;
56
+ });
57
+ },
58
+ templates: {
59
+ item: `
60
+ <a href="{{ url }}" class="grid grid-cols-4 gap-4 mb-4">
61
+ <div class="aspect-ratio-youtube relative">
62
+ <img src="{{ video.thumbnails.medium }}" alt="{{ video.title }}" class="absolute top-0">
63
+ </div>
64
+ <div class="col-span-3">
65
+ <div>{{#helpers.highlight}}{ "attribute": "playlist.title" }{{/helpers.highlight}}: {{#helpers.highlight}}{ "attribute": "video.title" }{{/helpers.highlight}}</div>
66
+ <span class="text-2xl">{{ displayStart }}</span>
67
+ <strong class="text-2xl">{{#helpers.highlight}}{ "attribute": "caption.content" }{{/helpers.highlight}}</strong>
68
+ <div></div>
69
+ </div>
70
+ </div>
71
+ ` ,
72
+ },
73
+ })
74
+ ]);
75
+
76
+ search .start ();
77
+ {% endraw % }
78
+ </script >
0 commit comments