Skip to content

Commit

Permalink
移除 docs & 更新 toc 来源
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Lord committed Sep 11, 2022
1 parent a2443a3 commit 7f48603
Show file tree
Hide file tree
Showing 152 changed files with 120 additions and 8,287 deletions.
19 changes: 19 additions & 0 deletions assets/js/jekyll-table-of-contents/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2013 Alex Ghiculescu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
100 changes: 100 additions & 0 deletions assets/js/jekyll-table-of-contents/toc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// https://github.com/ghiculescu/jekyll-table-of-contents
// share under MIT License
(function($){
$.fn.toc = function(options) {
var defaults = {
noBackToTopLinks: false,
title: '<i>Jump to...</i>',
minimumHeaders: 3,
headers: 'h1, h2, h3, h4, h5, h6',
listType: 'ol', // values: [ol|ul]
showEffect: 'show', // values: [show|slideDown|fadeIn|none]
showSpeed: 'slow', // set to 0 to deactivate effect
classes: { list: '',
item: '',
link: ''
}
},
settings = $.extend(defaults, options);

function fixedEncodeURIComponent (str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}

function createLink (header) {
var innerText = (header.textContent === undefined) ? header.innerText : header.textContent;
return "<a class='"+settings.classes.link+"' href='#" + fixedEncodeURIComponent(header.id) + "'>" + innerText + "</a>";
}

var headers = $(settings.headers).filter(function() {
// get all headers with an ID
var previousSiblingName = $(this).prev().attr( "name" );
if (!this.id && previousSiblingName) {
this.id = $(this).attr( "id", previousSiblingName.replace(/\./g, "-") );
}
return this.id;
}), output = $(this);
if (!headers.length || headers.length < settings.minimumHeaders || !output.length) {
$(this).hide();
return;
}

if (0 === settings.showSpeed) {
settings.showEffect = 'none';
}

var render = {
show: function() { output.hide().html(html).show(settings.showSpeed); },
slideDown: function() { output.hide().html(html).slideDown(settings.showSpeed); },
fadeIn: function() { output.hide().html(html).fadeIn(settings.showSpeed); },
none: function() { output.html(html); }
};

var get_level = function(ele) { return parseInt(ele.nodeName.replace("H", ""), 10); };
var highest_level = headers.map(function(_, ele) { return get_level(ele); }).get().sort()[0];
var return_to_top = '<i class="icon-arrow-up back-to-top"> </i>';

var level = get_level(headers[0]),
this_level,
html = settings.title + " <" +settings.listType + " class=\"" + settings.classes.list +"\">";
headers.on('click', function() {
if (!settings.noBackToTopLinks) {
window.location.hash = this.id;
}
})
.addClass('clickable-header')
.each(function(_, header) {
this_level = get_level(header);
if (!settings.noBackToTopLinks && this_level === highest_level) {
$(header).addClass('top-level-header').after(return_to_top);
}
if (this_level === level) // same level as before; same indenting
html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
else if (this_level <= level){ // higher level than before; end parent ol
for(var i = this_level; i < level; i++) {
html += "</li></"+settings.listType+">"
}
html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
}
else if (this_level > level) { // lower level than before; expand the previous to contain a ol
for(i = this_level; i > level; i--) {
html += "<" + settings.listType + " class=\"" + settings.classes.list +"\">" +
"<li class=\"" + settings.classes.item + "\">"
}
html += createLink(header);
}
level = this_level; // update for the next one
});
html += "</"+settings.listType+">";
if (!settings.noBackToTopLinks) {
$(document).on('click', '.back-to-top', function() {
$(window).scrollTop(0);
window.location.hash = '';
});
}

render[settings.showEffect]();
};
})(jQuery);
2 changes: 1 addition & 1 deletion assets/js/jekyll_table_of_contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var SOURCES = window.TEXT_VARIABLES.sources;
window.Lazyload.js(SOURCES.jquery, function () {
var JSElement=document.createElement("script");
JSElement.setAttribute("src","//cdn.jsdelivr.net/gh/ghiculescu/jekyll-table-of-contents/toc.min.js");
JSElement.setAttribute("src","//cdn.jsdelivr.net/gh/Young-Lord/Young-Lord.github.io/assets/js/jekyll-table-of-contents/toc.min.js");
document.body.appendChild(JSElement)
document.addEventListener("DOMContentLoaded", function () { $('#toc').toc(); });
})
Expand Down
Loading

0 comments on commit 7f48603

Please sign in to comment.