working draft of thoughts

This commit is contained in:
2026-11-05 11:58:07 +00:00
parent 5aa828852a
commit e60475cc93
13 changed files with 575 additions and 1 deletions

View File

@@ -0,0 +1,232 @@
/* Home thoughts preview */
.thoughts-preview {
margin: calc(var(--gap) * 0.5) 0 calc(var(--gap) * 2);
}
.thoughts-preview-header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: var(--gap);
margin-bottom: var(--content-gap);
}
.thoughts-preview-header h2 {
font-size: 20px;
font-weight: 600;
color: var(--primary);
}
.thoughts-all-link {
flex-shrink: 0;
color: var(--secondary);
font-size: 13px;
text-decoration: none;
}
.thoughts-all-link:hover,
.thoughts-all-link:focus-visible {
color: var(--standout);
}
.thoughts-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: var(--gap);
}
.thought-card {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
min-height: 30px;
padding: calc(var(--gap) * 0.75) var(--gap);
color: inherit;
background: var(--entry);
border: 1px solid var(--border);
border-radius: var(--radius);
text-decoration: none;
transition:
transform 0.25s ease,
border-color 0.25s ease;
}
.thought-card:hover,
.thought-card:focus-visible {
transform: translateY(-2px);
border-color: var(--tertiary);
}
.thought-card:focus-visible {
outline: 2px solid var(--standout);
outline-offset: 2px;
}
.thought-card-text {
display: block;
font-weight: bold;
overflow: hidden;
color: var(--primary);
font-size: 18px;
line-height: 1.5;
text-overflow: ellipsis;
white-space: nowrap;
}
.thought-card-meta {
display: block;
margin-top: auto;
padding-top: 0.6rem;
color: var(--secondary);
font-size: 12px;
}
/* Thoughts timeline */
.thought-timeline {
position: relative;
margin-top: var(--content-gap);
padding-left: 34px;
}
.thought-timeline::before {
content: "";
position: absolute;
top: 10px;
bottom: 10px;
left: 10px;
width: 2px;
background: var(--border);
border-radius: 2px;
}
.thought-entry {
position: relative;
margin-bottom: var(--gap);
scroll-margin-top: calc(var(--header-height) + var(--gap));
}
.thought-entry::before {
content: "";
position: absolute;
top: 22px;
left: -30px;
width: 10px;
height: 10px;
background: var(--standout);
border: 2px solid var(--code-bg);
border-radius: 50%;
box-sizing: content-box;
}
[data-theme="dark"] .thought-entry::before {
border-color: var(--theme);
}
.thought-entry-body {
padding: var(--content-gap);
background: var(--entry);
border: 1px solid var(--border);
border-radius: var(--radius);
transition: border-color 0.25s ease;
}
.thought-entry:target .thought-entry-body {
border-color: var(--standout);
box-shadow: 0 0 0 1px var(--standout);
}
.thought-entry-date {
display: block;
margin-bottom: 0.4rem;
color: var(--secondary);
font-size: 13px;
}
.thought-entry-text {
color: var(--primary);
font-size: 18px;
font-weight: bold;
line-height: 1.5;
overflow-wrap: anywhere;
}
.thought-timeline-more {
display: flex;
justify-content: center;
margin: calc(var(--gap) * 1.5) 0 var(--gap);
}
.thought-load-more {
padding: 0.75rem 1.25rem;
color: var(--theme);
font: inherit;
font-size: 14px;
line-height: 1;
background: var(--primary);
border: 1px solid var(--primary);
border-radius: 999px;
cursor: pointer;
transition:
background 0.2s ease,
border-color 0.2s ease;
}
.thought-load-more:hover,
.thought-load-more:focus-visible {
background: var(--standout);
border-color: var(--standout);
}
.thought-load-more:focus-visible {
outline: 2px solid var(--standout);
outline-offset: 3px;
}
.thought-load-more:disabled {
cursor: wait;
opacity: 0.65;
}
.thought-empty {
color: var(--secondary);
}
@media screen and (max-width: 768px) {
.thoughts-grid {
grid-template-columns: 1fr;
}
.thought-card {
min-height: 0;
}
.thought-timeline {
padding-left: 26px;
}
.thought-entry::before {
left: -22px;
}
.thought-entry-body {
padding: calc(var(--content-gap) * 0.85);
}
.thought-entry-text {
font-size: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.thought-card,
.thought-entry-body,
.thought-load-more {
transition: none;
}
.thought-card:hover,
.thought-card:focus-visible {
transform: none;
}
}

87
assets/js/thoughts.js Normal file
View File

@@ -0,0 +1,87 @@
(() => {
const timeline = document.getElementById("thought-timeline");
const more = document.querySelector(".thought-timeline-more");
const button = document.querySelector(".thought-load-more");
if (!timeline || !button) return;
const defaultLabel = button.textContent.trim();
async function loadPage(url) {
const response = await fetch(url, { credentials: "same-origin" });
if (!response.ok) {
throw new Error(`Could not load ${url}: ${response.status}`);
}
const html = await response.text();
const doc = new DOMParser().parseFromString(html, "text/html");
const nextTimeline = doc.getElementById("thought-timeline");
const nextButton = doc.querySelector(".thought-load-more");
if (nextTimeline) {
timeline.append(...Array.from(nextTimeline.children));
}
if (nextButton && nextButton.dataset.next) {
button.dataset.next = nextButton.dataset.next;
return true;
}
button.remove();
if (more) more.remove();
return false;
}
async function loadOlder() {
if (button.disabled || !button.dataset.next) return;
const next = button.dataset.next;
button.disabled = true;
button.textContent = "Loading…";
try {
await loadPage(next);
} catch (error) {
console.error(error);
window.location.href = next;
return;
}
if (document.body.contains(button)) {
button.disabled = false;
button.textContent = defaultLabel;
}
}
button.addEventListener("click", loadOlder);
// A link to an older thought (for example from the RSS feed) may point to an
// entry that has not been loaded yet. Keep loading pages until it exists.
const hash = decodeURIComponent(window.location.hash.slice(1));
if (hash && !document.getElementById(hash) && button.dataset.next) {
(async () => {
let next = button.dataset.next;
while (next && !document.getElementById(hash)) {
button.disabled = true;
button.textContent = "Loading…";
try {
if (!(await loadPage(next))) break;
} catch (error) {
console.error(error);
break;
}
next = button.dataset.next;
}
if (document.body.contains(button)) {
button.disabled = false;
button.textContent = defaultLabel;
}
const target = document.getElementById(hash);
if (target) target.scrollIntoView({ block: "start" });
})();
}
})();