mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Let gutenberg generate the table of contents
Remove the javascript toc code.
This commit is contained in:
@@ -2,22 +2,6 @@ window.onload = function() {
|
||||
var container = document.querySelector('#toc');
|
||||
|
||||
if (container != null) {
|
||||
var toc = initTOC({
|
||||
selector: 'h2, h3',
|
||||
scope: 'main',
|
||||
overwrite: false,
|
||||
prefix: 'toc'
|
||||
});
|
||||
|
||||
toc.innerHTML = toc.innerHTML.split("🔗\n").join("");
|
||||
|
||||
var heading = document.createElement("H2");
|
||||
var heading_text = document.createTextNode("Table of Contents");
|
||||
heading.appendChild(heading_text);
|
||||
|
||||
container.appendChild(heading);
|
||||
container.appendChild(toc);
|
||||
|
||||
resize_toc(container);
|
||||
}
|
||||
}
|
||||
|
||||
9
blog/static/js/toc.min.js
vendored
9
blog/static/js/toc.min.js
vendored
@@ -1,9 +0,0 @@
|
||||
/*!
|
||||
* jQuery-TOC
|
||||
* Table of Contents Generator Plugin for (non-)jQuery
|
||||
*
|
||||
* @author Dolphin Wood <dolphin.w.e@gmail.com>
|
||||
* @version 0.0.5
|
||||
* Copyright 2015. MIT licensed.
|
||||
*/
|
||||
!function(e){"use strict";var t=function(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&(e[n]=t[n]);return e},n=function(e,t){var n=[],r=document.querySelectorAll(t);return Array.prototype.forEach.call(r,function(t){var r=t.querySelectorAll(e);n=n.concat(Array.prototype.slice.call(r))}),n},r=function(e){if("string"!=typeof e)return 0;var t=e.match(/\d/g);return t?Math.min.apply(null,t):1},o=function(e,t){for(;t--;)e=e.appendChild(document.createElement("ol")),t&&(e=e.appendChild(document.createElement("li")));return e},c=function(e,t){for(;t--;)e=e.parentElement;return e},i=function(e,t){return function(n,r,o){var c=n.textContent,i=t+"-"+o;r.textContent=c;var a=e?i:n.id||i;a=encodeURIComponent(a),n.id=a,r.href="#"+a}},a=function(e){var t=e.selector,a=e.scope,u=document.createElement("ol"),l=u,f=null,h=i(e.overwrite,e.prefix);return n(t,a).reduce(function(e,t,n){var i=r(t.tagName),a=i-e;a>0&&(l=o(f,a)),0>a&&(l=c(l,2*-a)),l=l||u;var p=document.createElement("li"),d=document.createElement("a");return h(t,d,n),l.appendChild(p).appendChild(d),f=p,i},r(t)),u},u=function(e){var n={selector:"h1, h2, h3, h4, h5, h6",scope:"body",overwrite:!1,prefix:"toc"};e=t(n,e);var r=e.selector;if("string"!=typeof r)throw new TypeError("selector must be a string");if(!r.match(/^(?:h[1-6],?\s*)+$/g))throw new TypeError("selector must contains only h1-6");var o=location.hash;return o&&setTimeout(function(){location.hash="",location.hash=o},0),a(e)};"function"==typeof define&&define.amd?define(function(){return u}):e.initTOC=u}(window);
|
||||
@@ -8,6 +8,25 @@
|
||||
{{ page.date | date(format="%b %d, %Y") }}
|
||||
{% if page.extra.updated %} (updated on {{ page.extra.updated | date(format="%b %d, %Y") }}) {% endif %}
|
||||
</time>
|
||||
<aside id="toc">
|
||||
<h2>Table of Contents</h2>
|
||||
<ol>
|
||||
{% for h2 in page.toc %}
|
||||
<li>
|
||||
<a href="{{h2.permalink | safe}}">{{ h2.title }}</a>
|
||||
{% if h2.children %}
|
||||
<ol>
|
||||
{% for h3 in h2.children %}
|
||||
<li>
|
||||
<a href="{{h3.permalink | safe}}">{{ h3.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</aside>
|
||||
{{ page.content | safe }}
|
||||
{% endblock main %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user