Skip to content

Commit

Permalink
Exclude file for algolia indexing, update hit template
Browse files Browse the repository at this point in the history
  • Loading branch information
rnehra01 committed Mar 11, 2019
1 parent c3a8f00 commit 918a256
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ algolia:
application_id: GVFM3KX3UX
index_name: rnehra01.github.io
search_only_api_key: 4f0ffe8c2149d573ab7f386921c55713
files_to_exclude: [
index.html,
about/index.md
]
settings:
attributesToSnippet: ['*:33']
highlightPreTag: '<em class="ais-match-highlight">'
Expand Down
64 changes: 35 additions & 29 deletions _includes/algolia.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,65 @@

const hitTemplate = function(hit){
let isCover = hit.cover;
let articleClass = "post-card";
let articleClass = "post-card home-template";
if(!isCover) articleClass += " no-image";

const title = hit._highlightResult.title.value;
const content = hit._highlightResult.html.value;
console.log(hit._highlightResult);
let template = `<article class="${articleClass}">`
if(isCover){
template += ` <a class="post-card-image-link" href="{{ site.baseurl }}${hit.url.substring(1)}">
<div class="post-card-image" style="background-image: url({{ site.baseurl }}${ hit.cover })"></div>
</a>`;
template += `
<a class="post-card-image-link" href="{{ site.baseurl }}${hit.url.substring(1)}">
<div class="post-card-image" style="background-image: url({{ site.baseurl }}${ hit.cover })"></div>
</a>`;
}

template += `<div class="post-card-content">
<div class="post-card-content-link">
<header class="post-card-header">`;

template += `
<div class="post-card-content">
<div class="post-card-content-link">
<header class="post-card-header">`;

let date = '';
if (hit.date) {
date = moment.unix(hit.date).format('MMM D, YYYY');
template += `<time class="post-card-tags-date" datetime="{{ page.date | date:'%e %B %Y' }}">${date}</time>`;
date = moment.unix(hit.date).format('D MMMM YYYY');
template += `
<time class="post-card-tags-date" datetime="{{ page.date | date:'%e %B %Y' }}">${date}</time>`;
}

if('tags' in hit && hit.tags.length){
template += `<span class="post-card-tags-date">/</span>`;
template += `
<span class="post-card-tags-date">/</span>`;
for(tag_index in hit.tags){
if(tag_index == hit.tags.length-1)
template += `<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]}</a>`;
template += `
<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]}</a>`;
else
template += `<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]},</a>`;
template += `
<a class="post-card-tags-date" href='{{ site.baseurl }}tag/${hit.tags[tag_index]}/'>${hit.tags[tag_index]},</a>`;
}
}

template += `</header>
<header class="post-card-header">
<h2 class="post-card-title">${ title }</h2>
</header>
<section class="post-card-excerpt">
<p>${ content }...</p>
</section>
</div>
<footer class="post-card-meta">
</footer>
</div>
</article>`;
template += `
</header>
<header class="post-card-header">
<h2 class="post-card-title">${ title }</h2>
</header>
<section class="post-card-excerpt">
${ content }
</section>
</div>
<footer class="post-card-meta">
</footer>
</div>
</article>`;

return template;
};

search.addWidget(
instantsearch.widgets.hits({
container: '#search-hits',
container: '#search-hits',
templates: {
item: hitTemplate,
empty: function(data){
Expand Down

0 comments on commit 918a256

Please sign in to comment.