mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
handling errors, simplifying code and using let/const instead of var
This commit is contained in:
parent
dc43737896
commit
9ca1318830
@ -8,6 +8,7 @@ const addCopyButtons = () => {
|
|||||||
let els = document.getElementsByClassName("highlight");
|
let els = document.getElementsByClassName("highlight");
|
||||||
// for each highlight
|
// for each highlight
|
||||||
for (let i = 0; i < els.length; i++) {
|
for (let i = 0; i < els.length; i++) {
|
||||||
|
try {
|
||||||
if (els[i].getElementsByClassName("clipboard-button").length) continue;
|
if (els[i].getElementsByClassName("clipboard-button").length) continue;
|
||||||
|
|
||||||
// find pre > code inside els[i]
|
// find pre > code inside els[i]
|
||||||
@ -36,5 +37,8 @@ const addCopyButtons = () => {
|
|||||||
// find chroma inside els[i]
|
// find chroma inside els[i]
|
||||||
let chroma = els[i].getElementsByClassName("chroma")[0];
|
let chroma = els[i].getElementsByClassName("chroma")[0];
|
||||||
els[i].insertBefore(button, chroma);
|
els[i].insertBefore(button, chroma);
|
||||||
|
} catch(error) {
|
||||||
|
console.debug(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
|
|
||||||
function addTitleToCodeBlocks() {
|
function addTitleToCodeBlocks() {
|
||||||
var els = document.getElementsByClassName("highlight");
|
const els = document.getElementsByClassName("highlight");
|
||||||
for (var i = 0; i < els.length; i++) {
|
for (let i = 0; i < els.length; i++) {
|
||||||
|
try {
|
||||||
if (els[i].title.length) {
|
if (els[i].title.length) {
|
||||||
let div = document.createElement("div");
|
let div = document.createElement("div");
|
||||||
if (els[i].getElementsByClassName("code-title").length) continue;
|
if (els[i].getElementsByClassName("code-title").length) continue;
|
||||||
div.textContent=els[i].title;
|
div.textContent = els[i].title;
|
||||||
div.classList.add("code-title")
|
div.classList.add("code-title")
|
||||||
els[i].insertBefore(div, els[i].firstChild);
|
els[i].insertBefore(div, els[i].firstChild);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.debug(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
registerHandlers((e) => {
|
registerHandlers((e) => {
|
||||||
term = e.target.value
|
const term = e.target.value
|
||||||
const searchResults = contentIndex.search(term, [
|
const searchResults = contentIndex.search(term, [
|
||||||
{
|
{
|
||||||
field: "content",
|
field: "content",
|
||||||
|
|||||||
@ -113,7 +113,7 @@ async function drawGraph(baseUrl, isHome, pathColors, graphConfig) {
|
|||||||
.append("svg")
|
.append("svg")
|
||||||
.attr("width", width)
|
.attr("width", width)
|
||||||
.attr("height", height)
|
.attr("height", height)
|
||||||
.attr('viewBox', [-width / 2 * 1 / scale, -height / 2 * 1 / scale, width * 1 / scale, height * 1 / scale])
|
.attr('viewBox', [-width / 2 / scale, -height / 2 / scale, width / scale, height / scale])
|
||||||
|
|
||||||
if (enableLegend) {
|
if (enableLegend) {
|
||||||
const legend = [{ Current: "var(--g-node-active)" }, { Note: "var(--g-node)" }, ...pathColors]
|
const legend = [{ Current: "var(--g-node-active)" }, { Note: "var(--g-node)" }, ...pathColors]
|
||||||
|
|||||||
@ -12,7 +12,7 @@ function initPopover(baseURL, useContextualBacklinks) {
|
|||||||
links
|
links
|
||||||
.filter(li => li.dataset.src || (li.dataset.idx && useContextualBacklinks))
|
.filter(li => li.dataset.src || (li.dataset.idx && useContextualBacklinks))
|
||||||
.forEach(li => {
|
.forEach(li => {
|
||||||
var el
|
let el
|
||||||
if (li.dataset.ctx) {
|
if (li.dataset.ctx) {
|
||||||
const linkDest = content[li.dataset.src]
|
const linkDest = content[li.dataset.src]
|
||||||
const popoverElement = `<div class="popover">
|
const popoverElement = `<div class="popover">
|
||||||
|
|||||||
@ -40,8 +40,8 @@ const removeMarkdown = (
|
|||||||
.replace(/^\s{0,3}>\s?/g, "")
|
.replace(/^\s{0,3}>\s?/g, "")
|
||||||
.replace(/(^|\n)\s{0,3}>\s?/g, "\n\n")
|
.replace(/(^|\n)\s{0,3}>\s?/g, "\n\n")
|
||||||
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, "")
|
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, "")
|
||||||
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, "$2")
|
.replace(/([\*_]{1,3})(\S.*?\S?)\1/g, "$2")
|
||||||
.replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, "$2")
|
.replace(/([\*_]{1,3})(\S.*?\S?)\1/g, "$2")
|
||||||
.replace(/(`{3,})(.*?)\1/gm, "$2")
|
.replace(/(`{3,})(.*?)\1/gm, "$2")
|
||||||
.replace(/`(.+?)`/g, "$1")
|
.replace(/`(.+?)`/g, "$1")
|
||||||
.replace(/\n{2,}/g, "\n\n")
|
.replace(/\n{2,}/g, "\n\n")
|
||||||
@ -65,7 +65,7 @@ const highlight = (content, term) => {
|
|||||||
.split(" ")
|
.split(" ")
|
||||||
.slice(0, h)
|
.slice(0, h)
|
||||||
return (
|
return (
|
||||||
(before.length == h ? `...${before.join(" ")}` : before.join(" ")) +
|
(before.length === h ? `...${before.join(" ")}` : before.join(" ")) +
|
||||||
`<span class="search-highlight">${term}</span>` +
|
`<span class="search-highlight">${term}</span>` +
|
||||||
after.join(" ")
|
after.join(" ")
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user