1 let assert = require('assert')
2 let querystring = require('querystring')
5 let breadcrumbs = await _require('/_lib/breadcrumbs.jst')
6 let navbar = await _require('/_lib/navbar.jst')
7 let zet_site = await env.site.get_zettair('/_zet/site')
9 let query = env.parsed_url.query.query
10 let first = parseInt(env.parsed_url.query.first || '0')
11 let search = zet_site.search(query, first, 10)
13 `${env.parsed_url.host} search "${query}" first ${first} results ${search.results.length} total results ${search.total_results}`
20 async function breadcrumbs_str(pathname) {
21 assert(pathname.slice(0, 1) === '/')
23 // find names of path components
24 console.log('pathname', pathname)
25 let components = ['Home']
26 for (let i = 1, j; (j = pathname.indexOf('/', i)) !== -1; i = j + 1) {
29 menu = await env.site.get_menu(`${pathname.slice(0, i)}_menu.json`)
32 return pathname // fallback
34 let dir = pathname.slice(i, j)
35 if (!Object.prototype.hasOwnProperty.call(menu.index, dir))
36 return pathname // fallback
37 components.push(menu.entries[menu.index[dir]].name)
40 return components.join(' > ')
43 await breadcrumbs(env, _out)
50 if (search.results.length) {
51 p {`Showing results ${first + 1}–${first + search.results.length} of ${search.total_results}`}
54 for (let i = 0; i < search.results.length; ++i) {
55 let page = search.results[i].auxiliary
57 a(href=page) {`${await breadcrumbs_str(page)}`}
59 p {_out.push(search.results[i].summary)} // note: contains HTML
65 for (let i = 0; i * 10 < search.total_results; ++i) {
66 let page = '/search/index.html?' + querystring.stringify(
67 {query: query, first: i * 10}
69 let text = (i + 1).toString()
72 a.page-link(href=page) {
74 span.sr-only {'(current)'}
79 a.page-link(href=page) {`${text}`}