forked from kitian616/jekyll-TeXt-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
550 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{%- include snippets/page-title.html -%} | ||
<script> | ||
(function() { | ||
function queryString() { | ||
// This function is anonymous, is executed immediately and | ||
// the return value is assigned to QueryString! | ||
var i = 0, | ||
queryObj = {}, | ||
pair; | ||
var queryStr = window.location.search.substring(1); | ||
var queryArr = queryStr.split('&'); | ||
for (i = 0; i < queryArr.length; i++) { | ||
pair = queryArr[i].split('='); | ||
// If first entry with this name | ||
if (typeof queryObj[pair[0]] === 'undefined') { | ||
queryObj[pair[0]] = pair[1]; | ||
// If second entry with this name | ||
} else if (typeof queryObj[pair[0]] === 'string') { | ||
queryObj[pair[0]] = [queryObj[pair[0]], pair[1]]; | ||
// If third or later entry with this name | ||
} else { | ||
queryObj[pair[0]].push(pair[1]); | ||
} | ||
} | ||
return queryObj; | ||
} | ||
|
||
window.Lazyload.js('{{ site.data.variables.sources.jquery }}', function() { | ||
var $pageHeading = $('.js-page-heading'); | ||
var $tags = $('.js-tags'); | ||
var $articleTag = $('.js-article-tag'); | ||
var $tagShowAll = $('.js-tag-show-all'); | ||
var $postBlock = $('.js-post-block'); | ||
var $yearSection = $('.js-year-wrapper section'); | ||
|
||
$tags.on('click', 'button', function() { | ||
tagSelect($(this).data('tag')); | ||
}); | ||
|
||
function tagSelect(tag) { | ||
var i = 0, | ||
flag = false, | ||
cur, tagStr = '', | ||
tags = [], | ||
_tag = '', | ||
lis = []; | ||
if (tag === undefined || tag === '') { | ||
$pageHeading.text('{{ __return }}'); | ||
$tagShowAll.focus(); | ||
$postBlock.show(); | ||
} else { | ||
tag = tag.trim(); | ||
// $articleTag.filter('.tag-' + tag).focus(); | ||
for (i = 0; i < $articleTag.length; i++) { | ||
cur = $articleTag.eq(i); | ||
_tag = cur.data('tag'); | ||
if (typeof _tag === 'string' && _tag.trim() === tag) { | ||
cur.focus(); | ||
tagStr = cur.children('span').text(); | ||
(typeof tagStr === 'string') && (tagStr = tagStr.trim()); | ||
$pageHeading.text('Tag: ' + tagStr); | ||
break; | ||
} | ||
} | ||
$postBlock.each(function() { | ||
flag = false; | ||
cur = $(this); | ||
tags = cur.data('tag').split(','); | ||
for (i = 0; i < tags.length; i++) { | ||
_tag = tags[i].trim(); | ||
if (_tag === tag) { | ||
flag = true; | ||
cur.show(); | ||
break; | ||
} | ||
} | ||
flag || (cur.hide()); | ||
}); | ||
} | ||
$yearSection.each(function() { | ||
flag = false; | ||
cur = $(this); | ||
lis = cur.find('li'); | ||
for (i = 0; i < lis.length; i++) { | ||
if (lis.eq(i).css('display') !== 'none') { | ||
flag = true; | ||
break; | ||
} | ||
} | ||
flag ? cur.show() : cur.hide(); | ||
}); | ||
tag === undefined || window.history.replaceState(null, '', window.location.href.split('?')[0] + '?tag=' + tag); | ||
} | ||
|
||
var query = queryString(), | ||
tag = undefined; | ||
query.tag === undefined || (tag = query.tag); | ||
tagSelect(tag); | ||
}); | ||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{%- if page.key and site.leancloud.app_id and site.leancloud.app_key and site.leancloud.app_class and jekyll.environment != "development" -%} | ||
<script> | ||
window.Lazyload.js('{{ site.data.variables.sources.leancloud_js_sdk }}', function() { | ||
AV.init({ | ||
appId: '{{ site.leancloud.app_id }}', | ||
appKey: '{{ site.leancloud.app_key }}' | ||
}); | ||
$(".article-view").each(function() { | ||
var curId = this.id; | ||
var query = new AV.Query('{{ site.leancloud.app_class }}'); | ||
query.equalTo('key', curId.substr(9)); | ||
query.first().then(function(result) { | ||
if (result) { | ||
$('#' + curId).text(result.attributes.views); | ||
} | ||
}, function(error) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> | ||
{%- endif -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
window.Lazyload.js('{{ site.data.variables.sources.jquery }}', function() { | ||
var $articleContent = $('.m-post, .m-page').find('.m-article-content'), $this; | ||
$articleContent.children('.highlight').each(function() { | ||
$this = $(this); | ||
$this.attr('data-lang', $this.find('code').attr('data-lang')); | ||
}); | ||
function scrollAnimateTo(destination, duration, callback) { | ||
var $body = $('html, body'), bodyScrollTop = $body.scrollTop(); | ||
if(bodyScrollTop === destination) { return; } | ||
$body.animate({ scrollTop: destination }, duration, callback); | ||
} | ||
$articleContent.children('h1, h2, h3, h4, h5, h6').each(function() { | ||
$this = $(this); | ||
$this.append($('<a class="anchor" aria-hidden="true"></a>').html('{%- include icon/link.svg -%}')); | ||
}); | ||
$articleContent.on('click', '.anchor', function(e) { | ||
var targetId = $(this).parent().attr('id'); | ||
scrollAnimateTo($('#' + targetId).offset().top, 400, function() { | ||
window.history.replaceState(null, '', window.location.href.split('#')[0] + '#' + targetId); | ||
}); | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{%- assign _toc_selectors = site.toc.selectors | default: site.data.variables.default.toc.selectors -%} | ||
<script> | ||
window.Lazyload.js('{{ site.data.variables.sources.jquery }}', function() { | ||
window.Lazyload.js('{{ site.data.variables.sources.toc }}', function() { | ||
var $window = $(window); | ||
var $pageStage = $('.js-page-stage'); | ||
var $pageMain = $('.js-main'); | ||
var $pageFooter = $('.js-page-footer'); | ||
var $articleContent = $('.js-article-content'); | ||
var $articleAside = $('.js-article-aside'); | ||
var $toc = $('.js-toc'); | ||
var $col2 = $('.js-col-2'); | ||
var hasTitle = $articleContent.find('{{ _toc_selectors }}').length > 0; | ||
function asideSticky() { | ||
return $col2.css('display') !== 'none' && $pageStage.hasClass('has-toc'); | ||
} | ||
|
||
function setTocClass() { | ||
if (hasTitle) { | ||
!$pageStage.hasClass('has-toc') && $pageStage.addClass('has-toc'); | ||
} | ||
} | ||
|
||
setTocClass(); | ||
|
||
function setAsideTOC() { | ||
var asideTop, asideLeft, scrollBottom, asideBottomTop, lastScrollTop; | ||
|
||
function init() { | ||
var asideOffset = $articleAside.offset(); | ||
var footerOffset = $pageFooter.offset(); | ||
var mainOffset = $pageMain.offset(); | ||
asideTop = mainOffset.top; | ||
asideHeight = $toc.outerHeight() + parseInt($articleAside.css('padding-top'), 10) + parseInt($articleAside.css('padding-bottom'), 10); | ||
asideLeft = mainOffset.left + $pageMain.outerWidth() - $articleAside.outerWidth() - parseInt($pageMain.css('padding-right'), 10); | ||
scrollBottom = footerOffset.top - asideHeight; | ||
asideBottomTop = scrollBottom - mainOffset.top; | ||
} | ||
|
||
function setAside(force) { | ||
force !== true && (force = false); | ||
var scrollTop = $window.scrollTop(); | ||
if (scrollTop >= asideTop && scrollTop <= scrollBottom) { | ||
(!force && lastScrollTop >= asideTop && lastScrollTop <= scrollBottom) || | ||
$articleAside.addClass('fixed').css({ | ||
left: asideLeft + 'px', | ||
top: 0 | ||
}); | ||
} else if (scrollTop < asideTop) { | ||
(!force && lastScrollTop < asideTop) || | ||
$articleAside.removeClass('fixed').css({ | ||
left: 0, | ||
top: 0 | ||
}); | ||
} else { | ||
(!force && lastScrollTop > scrollBottom) || | ||
$articleAside.removeClass('fixed').css({ | ||
left: 0, | ||
top: asideBottomTop + 'px' | ||
}); | ||
} | ||
lastScrollTop = scrollTop; | ||
} | ||
asideSticky() && (init(), setAside()); | ||
$window.on('scroll', function() { | ||
asideSticky() && setAside(); | ||
}); | ||
$window.on('resize', window.throttle(function() { | ||
setTocClass(); | ||
asideSticky() && (init(), setAside(true)); | ||
}, 100)); | ||
setTimeout(init, 4000); | ||
} | ||
setTimeout(setAsideTOC, 1000); | ||
$toc.toc({ | ||
selectors: '{{ _toc_selectors }}', | ||
container: '.js-article-content', | ||
highlightOffset: 0 | ||
}); | ||
}); | ||
}); | ||
|
||
{%- if page.key and site.leancloud.app_id and site.leancloud.app_key and site.leancloud.app_class and jekyll.environment != "development" -%} | ||
window.Lazyload.js(['{{ site.data.variables.sources.jquery }}', '{{ site.data.variables.sources.leancloud_js_sdk }}'], function() { | ||
AV.init({ | ||
appId: '{{ site.leancloud.app_id }}', | ||
appKey: '{{ site.leancloud.app_key }}' | ||
}); | ||
var query = new AV.Query('{{ site.leancloud.app_class }}'); | ||
query.equalTo('key', '{{ page.key }}'); | ||
query.first().then(function(result) { | ||
if (result) { | ||
addOne(result) | ||
} else { | ||
var Blog = AV.Object.extend('{{ site.leancloud.app_class }}'); | ||
var blog = new Blog(); | ||
blog.set('title', '{{ page.title }}'); | ||
blog.set('key', '{{ page.key }}'); | ||
blog.set('views', 0); | ||
blog.save().then(function(page) { | ||
addOne(page) | ||
}, function(error) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
} | ||
|
||
function addOne(page) { | ||
page.increment('views', 1); | ||
page.save(null, { | ||
fetchWhenSave: true | ||
}).then(function(page) { | ||
$("#post-key-{{ page.key }}").text(page.attributes.views); | ||
}, function(error) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
} | ||
}, function(error) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
}); | ||
{%- endif -%} | ||
</script> |
Oops, something went wrong.