mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
feat: if using GitHub API, reduce requests in dev env
For sites using the `.js-github-release` feature to get the latest release of their project, prevent sending request to GitHub everytime Hugo Server reloads pages.
This commit is contained in:
parent
42e60e0287
commit
769d5f0ad1
2 changed files with 19 additions and 12 deletions
|
@ -5,6 +5,8 @@
|
|||
* Core JS functions and initialization.
|
||||
**************************************************/
|
||||
|
||||
import {hugoEnvironment} from '@params';
|
||||
|
||||
import {
|
||||
canChangeTheme,
|
||||
changeThemeModeClick,
|
||||
|
@ -13,6 +15,7 @@ import {
|
|||
renderThemeVariation
|
||||
} from './wowchemy-theming';
|
||||
|
||||
console.debug(`Environment: ${hugoEnvironment}`)
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Responsive scrolling for URL hashes.
|
||||
|
@ -305,6 +308,7 @@ function initMap() {
|
|||
* --------------------------------------------------------------------------- */
|
||||
|
||||
function printLatestRelease(selector, repo) {
|
||||
if (hugoEnvironment === 'production') {
|
||||
$.getJSON('https://api.github.com/repos/' + repo + '/tags').done(function (json) {
|
||||
let release = json[0];
|
||||
$(selector).append(' ' + release.name);
|
||||
|
@ -313,6 +317,7 @@ function printLatestRelease(selector, repo) {
|
|||
console.log("Request Failed: " + err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Toggle search dialog.
|
||||
|
@ -596,8 +601,9 @@ $(window).on('load', function () {
|
|||
|
||||
// Print latest version of GitHub projects.
|
||||
let githubReleaseSelector = '.js-github-release';
|
||||
if ($(githubReleaseSelector).length > 0)
|
||||
if ($(githubReleaseSelector).length > 0) {
|
||||
printLatestRelease(githubReleaseSelector, $(githubReleaseSelector).data('repo'));
|
||||
}
|
||||
|
||||
// On search icon click toggle search dialog.
|
||||
$('.js-search').click(function (e) {
|
||||
|
|
|
@ -155,7 +155,8 @@
|
|||
{{ $js_comment := printf "/* Wowchemy v%s | https://wowchemy.com/ */\n" site.Data.wowchemy.version }}
|
||||
{{ $js_bundle_head := $js_comment | resources.FromString "js/bundle-head.js" }}
|
||||
{{ $js_linebreak := "\n" | resources.FromString "js/linebreak.js" }}{{/* Fix no line break after Bootstrap JS causing error. */}}
|
||||
{{ $js_academic := resources.Get "js/wowchemy.js" | js.Build }}
|
||||
{{ $js_params := dict "hugoEnvironment" hugo.Environment }}
|
||||
{{ $js_academic := resources.Get "js/wowchemy.js" | js.Build (dict "params" $js_params) }}
|
||||
{{ $js_academic_search := resources.Get "js/wowchemy-search.js" }}
|
||||
{{ $js_algolia_search := resources.Get "js/algolia-search.js" }}
|
||||
{{ $js_bootstrap := resources.Get "js/_vendor/bootstrap.bundle.js" }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue