This commit is contained in:
xaoxuu 2021-02-20 14:56:07 +08:00
parent c22599abbe
commit 981ec4f5f9
7 changed files with 78 additions and 83 deletions

View File

@ -1,6 +1,3 @@
<%
console.log(page.path, page.header);
%>
<% if (page.header != false) { %> <% if (page.header != false) { %>
<%- partial('../../sidebar/header') %> <%- partial('../../sidebar/header') %>
<% } %> <% } %>

View File

@ -1,72 +0,0 @@
<script>
// 懒加载 js
function loadScript(src, cb) {
setTimeout(function () {
var HEAD =
document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
if (cb) script.onload = cb;
script.setAttribute("src", src);
HEAD.appendChild(script);
});
}
// 懒加载 css https://github.com/filamentgroup/loadCSS
var loadCSS = function (href, before, media, attributes) {
var doc = window.document;
var ss = doc.createElement("link");
var ref;
if (before) {
ref = before;
} else {
var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes;
ref = refs[refs.length - 1];
}
var sheets = doc.styleSheets;
if (attributes) {
for (var attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
ss.setAttribute(attributeName, attributes[attributeName]);
}
}
}
ss.rel = "stylesheet";
ss.href = href;
ss.media = "only x";
function ready(cb) {
if (doc.body) {
return cb();
}
setTimeout(function () {
ready(cb);
});
}
ready(function () {
ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling);
});
var onloadcssdefined = function (cb) {
var resolvedHref = ss.href;
var i = sheets.length;
while (i--) {
if (sheets[i].href === resolvedHref) {
return cb();
}
}
setTimeout(function () {
onloadcssdefined(cb);
});
};
function loadCB() {
if (ss.addEventListener) {
ss.removeEventListener("load", loadCB);
}
ss.media = media || "all";
}
if (ss.addEventListener) {
ss.addEventListener("load", loadCB);
}
ss.onloadcssdefined = onloadcssdefined;
onloadcssdefined(loadCB);
return ss;
};
</script>

View File

@ -1,5 +1,4 @@
<!-- required --> <!-- required -->
<%- partial('global') %>
<%- js({src: theme.plugins.jquery || 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js'}) %> <%- js({src: theme.plugins.jquery || 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js'}) %>
<% if (theme.stellar.cdn_js) { %> <% if (theme.stellar.cdn_js) { %>
<%- js({src: theme.stellar.cdn_js, async: true}) %> <%- js({src: theme.stellar.cdn_js, async: true}) %>

View File

@ -1,10 +1,10 @@
<script> <script>
function loadIssuesJS() { function loadIssuesJS() {
const issues = document.getElementById('issues-api'); const issues = document.getElementById('issues-api');
if (issues != undefined) { if (issues != undefined) {
loadScript('<%- url_for("/js/issues.js") %>'); loadScript('<%- url_for("/js/issues.js") %>');
} }
}; };
$(function () { $(function () {
loadIssuesJS(); loadIssuesJS();
}); });

View File

@ -4,7 +4,6 @@ if (page.class == undefined) {
} }
if (page.header == undefined) { if (page.header == undefined) {
page.header = false; page.header = false;
console.log('header = false');
} }
%> %>
<% let post = page; %> <% let post = page; %>

View File

@ -1,6 +1,7 @@
.md .tag.link .md .tag.link
margin-top: 1em margin-top: 1em
margin-bottom: 1em margin-bottom: 1em
max-width: 360px
.md .link-card .md .link-card
margin-right: 1em margin-right: 1em

View File

@ -1,5 +1,75 @@
const l_body = document.querySelector('.l_body'); const l_body = document.querySelector('.l_body');
// 懒加载 js
function loadScript(src, cb) {
setTimeout(function () {
var HEAD =
document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
if (cb) script.onload = cb;
script.setAttribute("src", src);
HEAD.appendChild(script);
});
}
// 懒加载 css https://github.com/filamentgroup/loadCSS
var loadCSS = function (href, before, media, attributes) {
var doc = window.document;
var ss = doc.createElement("link");
var ref;
if (before) {
ref = before;
} else {
var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes;
ref = refs[refs.length - 1];
}
var sheets = doc.styleSheets;
if (attributes) {
for (var attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
ss.setAttribute(attributeName, attributes[attributeName]);
}
}
}
ss.rel = "stylesheet";
ss.href = href;
ss.media = "only x";
function ready(cb) {
if (doc.body) {
return cb();
}
setTimeout(function () {
ready(cb);
});
}
ready(function () {
ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling);
});
var onloadcssdefined = function (cb) {
var resolvedHref = ss.href;
var i = sheets.length;
while (i--) {
if (sheets[i].href === resolvedHref) {
return cb();
}
}
setTimeout(function () {
onloadcssdefined(cb);
});
};
function loadCB() {
if (ss.addEventListener) {
ss.removeEventListener("load", loadCB);
}
ss.media = media || "all";
}
if (ss.addEventListener) {
ss.addEventListener("load", loadCB);
}
ss.onloadcssdefined = onloadcssdefined;
onloadcssdefined(loadCB);
return ss;
};
// 弹出侧边栏 // 弹出侧边栏
function toggleSidebar() { function toggleSidebar() {
if (l_body) { if (l_body) {
@ -53,4 +123,5 @@ function setSedebar() {
$(function () { $(function () {
setToc(); setToc();
setSedebar(); setSedebar();
}); });