let querystring = require('querystring') return async env => { let globals = await env.site.get_json('/_config/globals.json') let navbar = await _require('/navbar.jst') let zet_site = await env.site.get_zettair('/_zet/site') let query = env.parsed_url.query.query let first = parseInt(env.parsed_url.query.first || '0') let search = zet_site.search(query, first, 10) console.log( `${env.parsed_url.host} search "${query}" first ${first} results ${search.results.length} total results ${search.total_results}` ) await navbar( env, async _out => {}, async _out => { h1 {'Search results'} h4 { 'Query: ' strong {`${query}`} } if (search.results.length) { p {`Showing results ${first + 1}–${first + search.results.length} of ${search.total_results}`} ol(start=first + 1) { for (let i = 0; i < search.results.length; ++i) { let page = search.results[i].auxiliary li { a(href=page) {`${globals.page_to_title[page] || page}`} br {} p {_out.push(search.results[i].summary)} // note: contains HTML } } } ul.pagination { for (let i = 0; i * 10 < search.total_results; ++i) { let page = '/search.html?' + querystring.stringify( {query: query, first: i * 10} ) let text = (i + 1).toString() if (i * 10 === first) li.active { a(href=page) { `${text}` span.sr-only {'(current)'} } } else li { a(href=page) {`${text}`} } } } } else p {'No results'} } ) }