function feedback(type, message) { console.log(`feedback: https://github.com/rundocs/jekyll-rtd-theme/issues?q=${type}+${message}`); } function highlight() { let text = new URL(location.href).searchParams.get("highlight"); let regexp = new RegExp(text, "im"); if (text) { $(".section").find("*").each(function() { if (this.outerHTML.match(regexp)) { $(this).addClass("highlighted-box"); } }); $(".section").find(".highlighted-box").each(function() { if (($(this).find(".highlighted-box").length > 0)) { $(this).removeClass("highlighted-box"); } }); } } function search(data) { let text = new URL(location.href).searchParams.get("q"); let results = []; let regexp = new RegExp(text, "im"); function slice(content, min, max) { return content.slice(min, max).replace(regexp, (match) => `${match}`); } for (page of data) { let [title, content] = [null, null]; try { if (page.title) { title = page.title.match(regexp); } else { if (page.url == "/") { page.title = "{{ site.title }}"; } else { page.title = page.url; } } } catch (e) { feedback("search", e.message); } try { if (page.content) { page.content = $("
").html(page.content).text(); content = page.content.match(regexp); } } catch (e) { feedback("search", e.message); } if (title || content) { let result = [`${page.title}`]; if (content) { let [min, max] = [content.index - 100, content.index + 100]; let [prefix, suffix] = ["...", "..."]; if (min < 0) { prefix = ""; min = 0; } if (max > page.content.length) { suffix = ""; max = page.content.length; } result.push(`${prefix}${slice(page.content ,min, max)}${suffix}
`); } results.push(`${items[item]}
${content}