search.ejs
9,982 bytes
| 1 | <%- include("partials/head", { title: query ? "Search results" : "Search", bodyClass: "viewer-page search-page" }) %> |
|---|---|
| 2 | <header class="viewer-header"> |
| 3 | <a class="wordmark wordmark-light" href="/s/<%= share.id %>">profile<span>Share</span></a> |
| 4 | <form class="snapshot-search" action="/s/<%= share.id %>/search" method="get" role="search"> |
| 5 | <% if (repository) { %><input type="hidden" name="repository" value="<%= repository.id %>"><% } %> |
| 6 | <% if (selectedReference && !selectedReference.isDefault) { %> |
| 7 | <input type="hidden" name="ref" value="<%= selectedReference.name %>"> |
| 8 | <input type="hidden" name="refType" value="<%= selectedReference.type %>"> |
| 9 | <% } %> |
| 10 | <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M10.5 3a7.5 7.5 0 1 1-4.7 13.34l-3.07 3.07-1.42-1.42 3.08-3.07A7.5 7.5 0 0 1 10.5 3Zm0 2a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z"/></svg> |
| 11 | <input data-search-input name="q" value="<%= query %>" aria-label="Search <%= repository ? repository.name : 'this snapshot' %>" placeholder="Search <%= repository ? repository.name : 'this snapshot' %>"> |
| 12 | <button type="submit">Search</button> |
| 13 | </form> |
| 14 | <nav class="top-nav" aria-label="Snapshot navigation"> |
| 15 | <a href="/s/<%= share.id %>">Profile</a> |
| 16 | <span class="meta-divider"></span> |
| 17 | <span>Expires <%= formatDate(share.expires_at) %></span> |
| 18 | </nav> |
| 19 | </header> |
| 20 | |
| 21 | <main class="search-shell"> |
| 22 | <% const referenceScope = selectedReference && !selectedReference.isDefault ? "&ref=" + encodeURIComponent(selectedReference.name) + "&refType=" + encodeURIComponent(selectedReference.type) : ""; %> |
| 23 | <% const scope = repository ? "&repository=" + encodeURIComponent(repository.id) + referenceScope : ""; %> |
| 24 | <% const visibleTotal = type === "all" ? total : results[type].length; %> |
| 25 | <aside class="search-filters" aria-label="Search filters"> |
| 26 | <h2>Filter by</h2> |
| 27 | <a class="<%= type === 'all' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %><%= scope %>"> |
| 28 | Everything |
| 29 | <span><%= total %></span> |
| 30 | </a> |
| 31 | <a class="<%= type === 'code' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=code<%= scope %>"> |
| 32 | Code |
| 33 | <span><%= results.code.length %></span> |
| 34 | </a> |
| 35 | <a class="<%= type === 'commits' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=commits<%= scope %>"> |
| 36 | Commits |
| 37 | <span><%= results.commits.length %></span> |
| 38 | </a> |
| 39 | <a class="<%= type === 'issues' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=issues<%= scope %>"> |
| 40 | Issues |
| 41 | <span><%= results.issues.length %></span> |
| 42 | </a> |
| 43 | <a class="<%= type === 'pulls' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=pulls<%= scope %>"> |
| 44 | Pull requests |
| 45 | <span><%= results.pulls.length %></span> |
| 46 | </a> |
| 47 | <a class="<%= type === 'releases' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=releases<%= scope %>"> |
| 48 | Releases |
| 49 | <span><%= results.releases.length %></span> |
| 50 | </a> |
| 51 | <a class="<%= type === 'repositories' ? 'active' : '' %>" href="?q=<%= encodeURIComponent(query) %>&type=repositories<%= scope %>"> |
| 52 | Repositories |
| 53 | <span><%= results.repositories.length %></span> |
| 54 | </a> |
| 55 | <% if (repository) { %> |
| 56 | <div class="search-scope"> |
| 57 | <strong>In this repository</strong> |
| 58 | <span><%= repository.name %></span> |
| 59 | <% if (selectedReference) { %><span><%= selectedReference.type %>: <%= selectedReference.name %></span><% } %> |
| 60 | <a href="?q=<%= encodeURIComponent(query) %>">Search all repositories</a> |
| 61 | </div> |
| 62 | <% } %> |
| 63 | </aside> |
| 64 | |
| 65 | <section class="search-results"> |
| 66 | <header class="search-heading"> |
| 67 | <% if (query) { %> |
| 68 | <p><%= repository ? repository.name + (selectedReference ? " · " + selectedReference.name : "") : "Snapshot" %></p> |
| 69 | <h1><%= visibleTotal %> <%= visibleTotal === 1 ? "result" : "results" %> for <strong><%= query %></strong></h1> |
| 70 | <% } else { %> |
| 71 | <p>Snapshot search</p> |
| 72 | <h1>Find code, commits, and repositories</h1> |
| 73 | <% } %> |
| 74 | </header> |
| 75 | |
| 76 | <% if (!query) { %> |
| 77 | <div class="search-empty"> |
| 78 | <strong>Search the frozen snapshot</strong> |
| 79 | <p>Enter code, a file name, commit, issue, pull request, release, author, or repository name.</p> |
| 80 | </div> |
| 81 | <% } else if (!visibleTotal) { %> |
| 82 | <div class="search-empty"> |
| 83 | <strong>No results matched <%= query %></strong> |
| 84 | <p>Try a shorter term or search all repositories in this snapshot.</p> |
| 85 | </div> |
| 86 | <% } %> |
| 87 | |
| 88 | <% if ((type === "all" || type === "code") && results.code.length) { %> |
| 89 | <section class="result-group"> |
| 90 | <header> |
| 91 | <h2>Code</h2> |
| 92 | <span><%= results.code.length %></span> |
| 93 | </header> |
| 94 | <% results.code.forEach((item) => { %> |
| 95 | <article class="code-result"> |
| 96 | <a class="result-path" href="<%= resultHref(item.repository.id, { file: item.file.path, view: item.view }) %>#L<%= item.lineNumber %>"> |
| 97 | <strong><%= item.repository.name %></strong> |
| 98 | <span>/</span> |
| 99 | <span><%= item.file.path %></span> |
| 100 | </a> |
| 101 | <% if (item.snippet) { %> |
| 102 | <a class="code-result-line" href="<%= resultHref(item.repository.id, { file: item.file.path, view: item.view }) %>#L<%= item.lineNumber %>"> |
| 103 | <span><%= item.lineNumber %></span> |
| 104 | <code><%= item.snippet %></code> |
| 105 | </a> |
| 106 | <% } else { %> |
| 107 | <p>File path matches this search.</p> |
| 108 | <% } %> |
| 109 | </article> |
| 110 | <% }) %> |
| 111 | </section> |
| 112 | <% } %> |
| 113 | |
| 114 | <% if ((type === "all" || type === "commits") && results.commits.length) { %> |
| 115 | <section class="result-group"> |
| 116 | <header> |
| 117 | <h2>Commits</h2> |
| 118 | <span><%= results.commits.length %></span> |
| 119 | </header> |
| 120 | <% results.commits.forEach(({ repository: resultRepository, commit }) => { %> |
| 121 | <article class="commit-result"> |
| 122 | <a href="<%= resultHref(resultRepository.id, { commit: commit.sha }) %>"> |
| 123 | <strong><%= commit.message.split("\n")[0] %></strong> |
| 124 | <span><%= resultRepository.name %> by <%= commit.author %> on <%= formatDate(commit.date) %></span> |
| 125 | </a> |
| 126 | <code><%= commit.sha.slice(0, 7) %></code> |
| 127 | </article> |
| 128 | <% }) %> |
| 129 | </section> |
| 130 | <% } %> |
| 131 | |
| 132 | <% if ((type === "all" || type === "issues") && results.issues.length) { %> |
| 133 | <section class="result-group"> |
| 134 | <header> |
| 135 | <h2>Issues</h2> |
| 136 | <span><%= results.issues.length %></span> |
| 137 | </header> |
| 138 | <% results.issues.forEach(({ repository: resultRepository, issue }) => { %> |
| 139 | <article class="work-search-result"> |
| 140 | <a href="<%= globalResultHref(resultRepository.id, { issue: issue.number }) %>"> |
| 141 | <strong><%= issue.title %></strong> |
| 142 | <span><%= resultRepository.name %> #<%= issue.number %></span> |
| 143 | </a> |
| 144 | <p><%= issue.body ? issue.body.slice(0, 220) : "No description was provided." %></p> |
| 145 | <span class="state-badge <%= issue.state %>"><%= issue.state %></span> |
| 146 | </article> |
| 147 | <% }) %> |
| 148 | </section> |
| 149 | <% } %> |
| 150 | |
| 151 | <% if ((type === "all" || type === "pulls") && results.pulls.length) { %> |
| 152 | <section class="result-group"> |
| 153 | <header> |
| 154 | <h2>Pull requests</h2> |
| 155 | <span><%= results.pulls.length %></span> |
| 156 | </header> |
| 157 | <% results.pulls.forEach(({ repository: resultRepository, pullRequest }) => { const pullState = pullRequest.draft ? "draft" : pullRequest.merged ? "merged" : pullRequest.state; %> |
| 158 | <article class="work-search-result"> |
| 159 | <a href="<%= globalResultHref(resultRepository.id, { pull: pullRequest.number }) %>"> |
| 160 | <strong><%= pullRequest.title %></strong> |
| 161 | <span><%= resultRepository.name %> #<%= pullRequest.number %></span> |
| 162 | </a> |
| 163 | <p><%= pullRequest.body ? pullRequest.body.slice(0, 220) : "No description was provided." %></p> |
| 164 | <span class="state-badge <%= pullState %>"><%= pullState %></span> |
| 165 | </article> |
| 166 | <% }) %> |
| 167 | </section> |
| 168 | <% } %> |
| 169 | |
| 170 | <% if ((type === "all" || type === "releases") && results.releases.length) { %> |
| 171 | <section class="result-group"> |
| 172 | <header> |
| 173 | <h2>Releases</h2> |
| 174 | <span><%= results.releases.length %></span> |
| 175 | </header> |
| 176 | <% results.releases.forEach(({ repository: resultRepository, release }) => { %> |
| 177 | <article class="work-search-result"> |
| 178 | <a href="<%= globalResultHref(resultRepository.id, { release: release.id }) %>"> |
| 179 | <strong><%= release.name %></strong> |
| 180 | <span><%= resultRepository.name %> · <%= release.tagName %></span> |
| 181 | </a> |
| 182 | <p><%= release.body ? release.body.slice(0, 220) : "No release notes were provided." %></p> |
| 183 | <span class="release-tag"><%= release.tagName %></span> |
| 184 | </article> |
| 185 | <% }) %> |
| 186 | </section> |
| 187 | <% } %> |
| 188 | |
| 189 | <% if ((type === "all" || type === "repositories") && results.repositories.length) { %> |
| 190 | <section class="result-group"> |
| 191 | <header> |
| 192 | <h2>Repositories</h2> |
| 193 | <span><%= results.repositories.length %></span> |
| 194 | </header> |
| 195 | <% results.repositories.forEach((resultRepository) => { %> |
| 196 | <article class="repository-result"> |
| 197 | <a href="<%= resultHref(resultRepository.id) %>"><%= resultRepository.name %></a> |
| 198 | <p><%= resultRepository.description || "No repository description." %></p> |
| 199 | <span><%= resultRepository.language || "Mixed" %> · <%= resultRepository.files.length %> files · <%= resultRepository.commits.length %> commits</span> |
| 200 | </article> |
| 201 | <% }) %> |
| 202 | </section> |
| 203 | <% } %> |
| 204 | </section> |
| 205 | </main> |
| 206 | <script src="/assets/app.js" defer></script> |
| 207 | <%- include("partials/foot") %> |
| 208 | |