mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 05:14:06 -06:00
Merge branch 'hugo' into hugo
This commit is contained in:
commit
15ac7ff5dc
@ -87,17 +87,13 @@ async function drawGraph(
|
|||||||
.on('end', enableDrag ? dragended : noop);
|
.on('end', enableDrag ? dragended : noop);
|
||||||
};
|
};
|
||||||
|
|
||||||
const height = 250;
|
const height = Math.max(document.getElementById("graph-container").offsetHeight, 250)
|
||||||
const width = document.getElementById('graph-container').offsetWidth;
|
const width = document.getElementById("graph-container").offsetWidth
|
||||||
|
|
||||||
const simulation = d3
|
const simulation = d3.forceSimulation(data.nodes)
|
||||||
.forceSimulation(data.nodes)
|
.force("charge", d3.forceManyBody().strength(-30))
|
||||||
.force('charge', d3.forceManyBody().strength(-30))
|
.force("link", d3.forceLink(data.links).id(d => d.id).distance(40))
|
||||||
.force(
|
.force("center", d3.forceCenter());
|
||||||
'link',
|
|
||||||
d3.forceLink(data.links).id((d) => d.id)
|
|
||||||
)
|
|
||||||
.force('center', d3.forceCenter());
|
|
||||||
|
|
||||||
const svg = d3
|
const svg = d3
|
||||||
.select('#graph-container')
|
.select('#graph-container')
|
||||||
@ -151,21 +147,22 @@ async function drawGraph(
|
|||||||
.enter()
|
.enter()
|
||||||
.append('g');
|
.append('g');
|
||||||
|
|
||||||
|
// calculate radius
|
||||||
|
const nodeRadius = (d) => {
|
||||||
|
const numOut = index.links[d.id]?.length || 0
|
||||||
|
const numIn = index.backlinks[d.id]?.length || 0
|
||||||
|
return 3 + (numOut + numIn) / 4
|
||||||
|
}
|
||||||
|
|
||||||
// draw individual nodes
|
// draw individual nodes
|
||||||
const node = graphNode
|
const node = graphNode.append("circle")
|
||||||
.append('circle')
|
.attr("class", "node")
|
||||||
.attr('class', 'node')
|
.attr("id", (d) => d.id)
|
||||||
.attr('id', (d) => d.id)
|
.attr("r", nodeRadius)
|
||||||
.attr('r', (d) => {
|
.attr("fill", color)
|
||||||
const numOut = index.links[d.id]?.length || 0;
|
.style("cursor", "pointer")
|
||||||
const numIn = index.backlinks[d.id]?.length || 0;
|
.on("click", (_, d) => {
|
||||||
return 3 + (numOut + numIn) / 4;
|
window.location.href = `${baseUrl}/${decodeURI(d.id).replace(/\s+/g, '-')}/`
|
||||||
})
|
|
||||||
.attr('fill', color)
|
|
||||||
.style('cursor', 'pointer')
|
|
||||||
.on('click', (_, d) => {
|
|
||||||
const url = baseUrl + decodeURI(d.id).replace(/\s+/g, '-');
|
|
||||||
navigate(new URL(url), '.singlePage');
|
|
||||||
})
|
})
|
||||||
.on('mouseover', function (_, d) {
|
.on('mouseover', function (_, d) {
|
||||||
d3.selectAll('.node')
|
d3.selectAll('.node')
|
||||||
@ -196,14 +193,17 @@ async function drawGraph(
|
|||||||
|
|
||||||
// show text for self
|
// show text for self
|
||||||
d3.select(this.parentNode)
|
d3.select(this.parentNode)
|
||||||
.select('text')
|
|
||||||
.raise()
|
.raise()
|
||||||
|
.select("text")
|
||||||
.transition()
|
.transition()
|
||||||
.duration(200)
|
.duration(200)
|
||||||
.style('opacity', 1);
|
.style("opacity", 1)
|
||||||
})
|
.raise()
|
||||||
.on('mouseleave', function (_, d) {
|
}).on("mouseleave", function(_, d) {
|
||||||
d3.selectAll('.node').transition().duration(200).attr('fill', color);
|
d3.selectAll(".node")
|
||||||
|
.transition()
|
||||||
|
.duration(200)
|
||||||
|
.attr("fill", color)
|
||||||
|
|
||||||
const currentId = d.id;
|
const currentId = d.id;
|
||||||
const linkNodes = d3
|
const linkNodes = d3
|
||||||
@ -221,32 +221,32 @@ async function drawGraph(
|
|||||||
.call(drag(simulation));
|
.call(drag(simulation));
|
||||||
|
|
||||||
// draw labels
|
// draw labels
|
||||||
const labels = graphNode
|
const labels = graphNode.append("text")
|
||||||
.append('text')
|
.attr("dx", 0)
|
||||||
.attr('dx', 12)
|
.attr("dy", d => nodeRadius(d) + 8 + "px")
|
||||||
.attr('dy', '.35em')
|
.attr("text-anchor", "middle")
|
||||||
.text((d) => content[d.id]?.title || d.id.replace('-', ' '))
|
.text((d) => content[d.id]?.title || d.id.replace("-", " "))
|
||||||
.style('opacity', 0)
|
.style("opacity", 0)
|
||||||
.style('pointer-events', 'none')
|
.style("pointer-events", "none")
|
||||||
|
.style("font-size", "0.4em")
|
||||||
|
.raise()
|
||||||
.call(drag(simulation));
|
.call(drag(simulation));
|
||||||
|
|
||||||
// set panning
|
// set panning
|
||||||
|
|
||||||
if (enableZoom) {
|
if (enableZoom) {
|
||||||
svg.call(
|
svg.call(d3.zoom()
|
||||||
d3
|
.extent([[0, 0], [width, height]])
|
||||||
.zoom()
|
.scaleExtent([0.25, 4])
|
||||||
.extent([
|
.on("zoom", ({ transform }) => {
|
||||||
[0, 0],
|
link.attr("transform", transform);
|
||||||
[width, height],
|
node.attr("transform", transform);
|
||||||
])
|
const scale = transform.k
|
||||||
.scaleExtent([0.25, 4])
|
const scaledOpacity = Math.max((scale - 1) / 3.75, 0)
|
||||||
.on('zoom', ({ transform }) => {
|
labels
|
||||||
link.attr('transform', transform);
|
.attr("transform", transform)
|
||||||
node.attr('transform', transform);
|
.style("opacity", scaledOpacity)
|
||||||
labels.attr('transform', transform);
|
}));
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// progress the simulation
|
// progress the simulation
|
||||||
|
|||||||
@ -131,7 +131,7 @@ const removeMarkdown = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const redir = (id, term) => {
|
const redir = (id, term) => {
|
||||||
window.location.href = BASE_URL + `${id}#:~:text=${encodeURIComponent(term)}`
|
window.location.href = `${BASE_URL}${id}#:~:text=${encodeURIComponent(term)}/`
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatForDisplay = id => ({
|
const formatForDisplay = id => ({
|
||||||
|
|||||||
@ -329,6 +329,12 @@ hr {
|
|||||||
& #graph-container {
|
& #graph-container {
|
||||||
border: var(--outlinegray) 1px solid;
|
border: var(--outlinegray) 1px solid;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
& > svg {
|
||||||
|
margin-bottom: -5px;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,7 +532,7 @@ header {
|
|||||||
box-shadow: 6px 6px 36px 0px rgba(0,0,0,0.25);
|
box-shadow: 6px 6px 36px 0px rgba(0,0,0,0.25);
|
||||||
|
|
||||||
@media all and (max-width: 600px) {
|
@media all and (max-width: 600px) {
|
||||||
display: none;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.visible {
|
&.visible {
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
{{if $inbound}}
|
{{if $inbound}}
|
||||||
{{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
|
{{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
|
||||||
{{- range $cleanedInbound | uniq -}}
|
{{- range $cleanedInbound | uniq -}}
|
||||||
{{$l := printf "%s%s" $host .}}
|
{{$l := printf "%s%s/" $host .}}
|
||||||
{{with (index $contentTable .)}}
|
{{with (index $contentTable .)}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{$l}}">{{index (index . "title")}}</a>
|
<a href="{{$l}}">{{index (index . "title")}}</a>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user