2021-10-19 10:26:50 -07:00
|
|
|
<script context="module">
|
2022-05-13 21:50:19 -07:00
|
|
|
import { onMount } from 'svelte';
|
2021-10-20 14:23:46 -07:00
|
|
|
import { formatDate } from './datefmt.js';
|
2021-10-21 21:25:28 -07:00
|
|
|
import { makeSlug } from '$lib/slug.js';
|
2021-10-19 10:26:50 -07:00
|
|
|
import Link from './Link.svelte';
|
|
|
|
export { Link as a };
|
|
|
|
</script>
|
|
|
|
|
2021-10-19 06:44:15 -07:00
|
|
|
<script>
|
2021-10-19 10:26:50 -07:00
|
|
|
export let title, date;
|
2022-05-13 21:50:19 -07:00
|
|
|
|
|
|
|
// deal with sidenote collisions
|
2022-05-14 07:43:08 -07:00
|
|
|
function tileNotes() {
|
2022-05-13 21:50:19 -07:00
|
|
|
const minNoteGap = 15;
|
2022-05-14 07:43:08 -07:00
|
|
|
// let sidenotes = Array.from(document.getElementsByClassName('sidenote'));
|
|
|
|
let notes = document.querySelectorAll('.sidenote');
|
|
|
|
if (window.getComputedStyle(notes[0]).position === 'fixed') {
|
|
|
|
// fixed position means we are in mobile territory, so
|
|
|
|
// get rid of the overflow stuff and then exit
|
|
|
|
for (let note of notes) {
|
|
|
|
note.style.top = '';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let labels = document.querySelectorAll('label.counter');
|
2022-05-13 21:50:19 -07:00
|
|
|
var prev = 0;
|
2022-05-14 07:43:08 -07:00
|
|
|
for (var i=0; i < notes.length; i++) {
|
|
|
|
let labelTop = labels[i].getBoundingClientRect().y + window.scrollY;
|
|
|
|
let noteHeight = notes[i].getBoundingClientRect().height;
|
|
|
|
if (labelTop < prev + minNoteGap) {
|
|
|
|
// there is a collision
|
|
|
|
notes[i].style.top = `${prev + minNoteGap}px`;
|
|
|
|
prev = prev + minNoteGap + noteHeight;
|
2022-05-13 21:50:19 -07:00
|
|
|
}
|
|
|
|
else {
|
2022-05-14 07:43:08 -07:00
|
|
|
// no collision
|
|
|
|
notes[i].style.top = `${labelTop}px`;
|
|
|
|
prev = labelTop + noteHeight;
|
2022-05-13 21:50:19 -07:00
|
|
|
}
|
|
|
|
}
|
2022-05-14 07:43:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
tileNotes();
|
|
|
|
window.addEventListener('resize', tileNotes);
|
|
|
|
});
|
2021-10-19 06:44:15 -07:00
|
|
|
</script>
|
|
|
|
|
2021-10-19 21:03:31 -07:00
|
|
|
<svelte:head>
|
|
|
|
<title>{title}</title>
|
|
|
|
</svelte:head>
|
2021-10-19 06:44:15 -07:00
|
|
|
|
|
|
|
<div id="post">
|
2021-10-21 21:25:28 -07:00
|
|
|
<h1 id="{makeSlug(title)}">{title}</h1>
|
2021-10-20 14:23:46 -07:00
|
|
|
<p><em>{formatDate(date)}</em></p>
|
2021-10-19 10:26:50 -07:00
|
|
|
<slot></slot>
|
2021-10-19 06:44:15 -07:00
|
|
|
</div>
|