Permalink
Browse files

JS: Fix Algolia template and refactor Hero

  • Loading branch information...
gcushen committed Sep 15, 2018
1 parent 6ef1908 commit 7919efd7a3c0dda49b1ece4ada5718230a57a56b
Showing with 56 additions and 53 deletions.
  1. +4 −4 data/assets.toml
  2. +4 −20 exampleSite/content/home/hero.md
  3. +30 −29 layouts/partials/footer.html
  4. +18 −0 static/js/hugo-academic.js
View
@@ -56,8 +56,8 @@
sri = "sha256-4HLtjeVgH0eIB3aZ9mLYF6E8oU5chNdjU6p6rrXpl9U="
url = "https://cdnjs.cloudflare.com/ajax/libs/mark.js/%s/jquery.mark.min.js"
[js.instantsearch]
version = "2.9.0"
sri = "sha256-cJXigylnJlxvAdfFNHeS+IiMcKWS3Rf/cy3bl9bb0ng="
version = "2.10.2"
sri = "sha256-gFCtPk/sonctyfwYOgjrPoWApQ0rqB6ezBBZ7p32yGc="
url = "https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/%s/instantsearch.min.js"
[js.anchor]
version = "4.1.1"
@@ -91,8 +91,8 @@
sri = "sha256-ZtmLe16p4jS4/2wPwwH6NzJt460SJzgLmhKrYo5yn7g="
url = "https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/%s/instantsearch.min.css"
[css.instantsearchTheme]
version = "2.9.0"
sri = "sha256-0vcZrdMQksHcHrY60tPnVK71jnB3wX/JpMcah5BffjA="
version = "2.10.2"
sri = "sha256-uL8LUd3zkI/lXvc/Hv/oOu8ld6RJcOZiUY/8c+I+3/o="
url = "https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/%s/instantsearch-theme-algolia.min.css"
[css.highlight]
version = "9.12.0"
@@ -26,27 +26,11 @@ weight = 3
The highly flexible website framework for Hugo with an extensible plugin mechanism. Create a beautifully simple site in under 10 minutes :rocket:
<div style="margin-top: -0.5rem;">
<a id="academic-release" href="https://sourcethemes.com/academic/updates">Latest release</a>
<a id="academic-release" href="https://sourcethemes.com/academic/updates" data-repo="gcushen/hugo-academic">
Latest release <!-- V -->
</a>
</div>
<div class="mt-3">
<a class="github-button" href="https://github.com/gcushen/hugo-academic" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star gcushen/hugo-academic on GitHub">Star</a>
<a class="github-button" href="https://github.com/gcushen/hugo-academic" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star this on GitHub">Star</a>
</div>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script type="text/javascript">
(function defer() {
if (window.jQuery) {
jQuery(document).ready(function(){
GetLatestReleaseInfo();
});
} else {
setTimeout(function() { defer() }, 50);
}
})();
function GetLatestReleaseInfo() {
$.getJSON('https://api.github.com/repos/gcushen/hugo-academic/tags').done(function (json) {
let release = json[0];
// let downloadURL = release.zipball_url;
$('#academic-release').text('Latest release ' + release.name);
});
}
</script>
@@ -89,6 +89,34 @@
</script>
{{ end }}
{{ if eq $.Site.Params.search.engine 1 }}
{{/* Fuse search result template. */}}
<script id="search-hit-fuse-template" type="text/x-template">
<div class="search-hit" id="summary-{{"{{key}}"}}">
<div class="search-hit-content">
<div class="search-hit-name">
{{ printf "<a href=\"%s\">%s</a>" "{{relpermalink}}" "{{title}}" | safeHTML }}
<div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
<p class="search-hit-description">{{"{{snippet}}"}}</p>
</div>
</div>
</div>
</script>
{{ else if eq $.Site.Params.search.engine 2 }}
{{/* Algolia search result template. */}}
<script id="search-hit-algolia-template" type="text/html">
<div class="search-hit">
<div class="search-hit-content">
<div class="search-hit-name">
{{ printf "<a href=\"%s\">{{{_highlightResult.title.value}}}</a>" "{{relpermalink}}" | safeHTML }}
</div>
<div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
<p class="search-hit-description">{{ safeHTML "{{{_highlightResult.summary.value}}}" }}</p>
</div>
</div>
</script>
{{ end }}
{{/* Fuse search engine. */}}
{{ if eq .Site.Params.search.engine 1 }}
{{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.fuse.url $js.fuse.version) $js.fuse.sri | safeHTML }}
@@ -133,6 +161,7 @@
instantsearch.widgets.searchBox({
container: '#search-box',
autofocus: false,
reset: true,
poweredBy: {{ .Site.Params.search.algolia.show_logo | default false }},
placeholder: i18n.placeholder
})
@@ -148,7 +177,7 @@
item: getTemplate('search-hit-algolia')
},
cssClasses: {
showmoreButton: 'btn btn-primary btn-outline'
showmoreButton: 'btn btn-outline-primary'
}
})
);
@@ -169,33 +198,5 @@
</script>
{{ end }}
{{ if eq $.Site.Params.search.engine 1 }}
{{/* Fuse search result template. */}}
<script id="search-hit-fuse-template" type="text/x-template">
<div class="search-hit" id="summary-{{"{{key}}"}}">
<div class="search-hit-content">
<div class="search-hit-name">
{{ printf "<a href=\"%s\">%s</a>" "{{relpermalink}}" "{{title}}" | safeHTML }}
<div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
<p class="search-hit-description">{{"{{snippet}}"}}</p>
</div>
</div>
</div>
</script>
{{ else if eq $.Site.Params.search.engine 2 }}
{{/* Algolia search result template. */}}
<script id="search-hit-algolia-template" type="text/html">
<div class="search-hit">
<div class="search-hit-content">
<div class="search-hit-name">
{{ printf "<a href=\"%s\">{{{_highlightResult.title.value}}}</a>" "{{relpermalink}}" | safeHTML }}
</div>
<div class="article-metadata search-hit-type">{{"{{type}}"}}</div>
<p class="search-hit-description">{{ safeHTML "{{{_highlightResult.summary.value}}}" }}</p>
</div>
</div>
</script>
{{ end }}
</body>
</html>
View
@@ -235,6 +235,20 @@
}
}
/* ---------------------------------------------------------------------------
* GitHub API.
* --------------------------------------------------------------------------- */
function printLatestRelease(selector, repo) {
$.getJSON('https://api.github.com/repos/' + repo + '/tags').done(function (json) {
let release = json[0];
$(selector).append(release.name);
}).fail(function( jqxhr, textStatus, error ) {
let err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
});
}
/* ---------------------------------------------------------------------------
* On window load.
* --------------------------------------------------------------------------- */
@@ -333,6 +347,10 @@
// Fix Hugo's inbuilt Table of Contents.
$('#TableOfContents > ul > li > ul').unwrap().unwrap();
// Print latest Academic version if necessary.
if ($('#academic-release').length > 0)
printLatestRelease('#academic-release', $('#academic-release').data('repo'));
});
})(jQuery);

0 comments on commit 7919efd

Please sign in to comment.