11---
22title: Jamstack TV
33layout: layouts/base.njk
4+ preconnect:
5+ - https://cdn.jsdelivr.net
6+ javascriptIncludes:
7+ - search-js.njk
48---
59{# This search index data is populated by the code at https://github.com/netlify/jamstack-tv-search-data #}
610
@@ -17,86 +21,3 @@ layout: layouts/base.njk
1721 <div id =" hits" class =" mt-20" ></div >
1822</div >
1923
20- <
script src =
" https://cdn.jsdelivr.net/npm/[email protected] /dist/algoliasearch-lite.umd.js" integrity =
" sha256-EXPXz4W6pQgfYY3yTpnDa3OH8/EPn16ciVsPQ/ypsjk=" crossorigin =
" anonymous" ></
script >
21- <
script src =
" https://cdn.jsdelivr.net/npm/[email protected] /dist/instantsearch.production.min.js" integrity =
" sha256-LAGhRRdtVoD6RLo2qDQsU2mp+XVSciKRC8XPOBWmofM=" crossorigin =
" anonymous" ></
script >
22- <script >
23- const searchClient = algoliasearch (' {{ algolia.appId }}' , ' {{ algolia.searchOnlyApiKey }}' );
24-
25- const search = instantsearch ({
26- indexName: ' {{ algolia.indexName }}' ,
27- searchClient,
28- });
29-
30- {% raw % }
31- function pad (num ) { return num < 10 ? ` 0${ num} ` : num; }
32-
33- function getDurationString (duration ) {
34- let secondsInOne = {
35- hour: 60 * 60 ,
36- minute: 60
37- };
38-
39- let hours = Math .floor (duration / secondsInOne .hour );
40- let minutes = Math .floor ((duration % secondsInOne .hour ) / secondsInOne .minute );
41- let seconds = Math .floor (duration % secondsInOne .minute );
42-
43- return ` ${ hours ? ` ${ hours} :` : " " }${ hours ? pad (minutes) : minutes} :${ pad (seconds)} ` ;
44- }
45-
46- search .addWidgets ([
47- instantsearch .widgets .searchBox ({
48- container: ' #searchbox' ,
49- // placeholder: 'Search Video Content',
50- showReset: false ,
51- showSubmit: false ,
52- }),
53-
54- instantsearch .widgets .hits ({
55- snippetEllipsisText: ' …' ,
56- container: ' #hits' ,
57- cssClasses: {
58- root: " bg-blue-900 text-blue-100" ,
59- // item: "bg-blue-900 text-blue-100",
60- },
61- transformItems (items ) {
62- return items .map (item => {
63- let start = item .caption .start ;
64-
65- let obj = {
66- ... item,
67- url: ` https://www.youtube.com/watch?v=${ item .video .id } }&t=${ start} s` ,
68- displayDuration: getDurationString (item .video .duration ),
69- };
70-
71- if (start > 10 ) { // only show for deep links > 10 seconds
72- obj .displayStartInline = ` <span class="jamstacktv-time"><b></b><b></b>${ getDurationString (start)} of</span>` ;
73- // obj._highlightResult.caption.content = `…${obj._highlightResult.caption.content}`;
74- } else {
75- obj .wrapperClass = " jamstacktv-no-skip" ;
76- }
77- return obj;
78- });
79- },
80- templates: {
81- item: `
82- <a href="{{ url }}" class="grid grid-cols-3 gap-4 mb-4 group">
83- <div class="aspect-ratio-youtube relative jamstacktv-card">
84- <img src="{{ video.thumbnails.medium }}" alt="{{ video.title }}" class="jamstacktv-img absolute top-0 card-shadow bg-gradient-card-sunrise group-hover:card-shadow-sunrise">
85- <span class="jamstacktv-duration">{{{ displayStartInline }}}{{ displayDuration }}</span>
86- </div>
87- <div class="col-span-2 jamstacktv-item {{ wrapperClass }}">
88- <div class="jamstacktv-meta mb-1">
89- <span class="jamstacktv-category">{{#helpers.highlight}}{ "attribute": "playlist.title" }{{/helpers.highlight}}</span>
90- <span class="jamstacktv-title">{{#helpers.highlight}}{ "attribute": "video.title" }{{/helpers.highlight}}</span>
91- </div>
92- <strong class="jamstacktv-caption"><span class="jamstacktv-caption-quote">{{#helpers.highlight}}{ "attribute": "caption.content" }{{/helpers.highlight}}</span></strong>
93- </div>
94- </div>
95- ` ,
96- },
97- })
98- ]);
99-
100- search .start ();
101- {% endraw % }
102- </script >
0 commit comments