on master help sign in
Fix search results date formatting
c49eed2francescanarea
static/scripts.js+6−12
@@ -171,29 +171,22 @@ function makeTeaser(body, terms) {
171 startIndex = word[2];
171 startIndex = word[2];
172 }
172 }
173
173
174− // add dark color around search terms
175− if (word[1] === TERM_WEIGHT) {
176− teaser.push("<span>");
177− }
178 startIndex = word[2] + word[0].length;
174 startIndex = word[2] + word[0].length;
179 teaser.push(body.substring(word[2], startIndex));
175 teaser.push(body.substring(word[2], startIndex));
180
176
181− if (word[1] === TERM_WEIGHT) {
182− teaser.push("</span>");
183− }
184 }
177 }
185 teaser.push("…");
178 teaser.push("…");
186 return teaser.join("");
179 return teaser.join("");
187}
180}
188
181
189−function formatSearchResultTitle(path) {
182+function formatSearchResultTitle(item) {
190− var pathArray = path.split( '/' );
183+ var pathArray = item.ref.split( '/' );
191
184
192 // first directory is in 4th element of split path array
185 // first directory is in 4th element of split path array
193 var firstPartTitle = pathArray[3];
186 var firstPartTitle = pathArray[3];
194
187
195 // last directory is in 2nd to last element of array
188 // last directory is in 2nd to last element of array
196− var lastPartTitle = pathArray[pathArray.length-2].replace(/-/g,' ');
189+ var lastPartTitle = item.doc.title;
197
190
198 var fullTitle = firstPartTitle + '<span class="gray90 inline-block pl2">' + ' / ' + lastPartTitle + '</span>';
191 var fullTitle = firstPartTitle + '<span class="gray90 inline-block pl2">' + ' / ' + lastPartTitle + '</span>';
199
192
@@ -201,10 +194,11 @@ function formatSearchResultTitle(path) {
201}
194}
202
195
203function formatSearchResultItem(item, terms) {
196function formatSearchResultItem(item, terms) {
197+ console.log(item);
204 var li = document.createElement("li");
198 var li = document.createElement("li");
205 var createA = document.createElement("a");
199 var createA = document.createElement("a");
206 li.appendChild(createA);
200 li.appendChild(createA);
207− var teaserTitle = formatSearchResultTitle(item.ref);
201+ var teaserTitle = formatSearchResultTitle(item);
208 li.classList.add("search-results__item");
202 li.classList.add("search-results__item");
209 li.classList.add("ph3");
203 li.classList.add("ph3");
210 var hrefA = item.ref;
204 var hrefA = item.ref;
@@ -297,7 +291,7 @@ function initSearch() {
297 }
291 }
298
292
299 currentTerm = term;
293 currentTerm = term;
300− searchResultsHeader.innerText = `${results.length} search results for '${term}':`;
294+ searchResultsHeader.innerText = `${results.length} search results for '${term}':`;
301 for (var i = 0; i < Math.min(results.length, MAX_ITEMS); i++) {
295 for (var i = 0; i < Math.min(results.length, MAX_ITEMS); i++) {
302 if (!results[i].doc.body) {
296 if (!results[i].doc.body) {
303 continue;
297 continue;