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" });
})();
}
})();

6
content/thoughts/test.md Normal file
View File

@@ -0,0 +1,6 @@
---
title: thought1
date: 2026-09-20T18:34:00
draft: false
---
# this really is a feature, huh?

View File

@@ -0,0 +1,6 @@
---
title: thought2
date: 2026-09-20T19:34:00
draft: false
---
# This is a really long test thought to see what happens when things go into 2 lines and i go off on a tangent

View File

@@ -0,0 +1,4 @@
{{- if eq .Type "thoughts" }}
{{- $js := resources.Get "js/thoughts.js" | resources.Minify | resources.Fingerprint }}
<script defer src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}"></script>
{{- end }}

View File

@@ -0,0 +1 @@
{{- return (printf "thought-%s" (.File.ContentBaseName | urlize)) -}}

View File

@@ -0,0 +1,10 @@
{{- /* A thought is the first H1 in the page body. The front matter title is only a formality. */ -}}
{{- $matches := findRE `<h1[^>]*>[\s\S]*?</h1>` .Content 1 -}}
{{- $text := "" -}}
{{- with $matches -}}
{{- $text = index . 0 | plainify | htmlUnescape | strings.TrimSpace -}}
{{- end -}}
{{- if not $text -}}
{{- $text = .Plain | strings.TrimSpace -}}
{{- end -}}
{{- return $text -}}

View File

@@ -0,0 +1,6 @@
<article class="thought-entry" id="{{ partial "thought_anchor.html" . }}">
<div class="thought-entry-body">
<time class="thought-entry-date" datetime="{{ .Date.Format "2006-01-02" }}">{{ .Date | time.Format ":date_long" }}</time>
<p class="thought-entry-text">{{ partial "thought_text.html" . }}</p>
</div>
</article>

View File

@@ -0,0 +1,17 @@
{{- $thoughts := where site.RegularPages "Type" "thoughts" -}}
{{- $thoughts = $thoughts.ByDate.Reverse -}}
{{- with first 3 $thoughts -}}
<section class="thoughts-preview" aria-labelledby="thoughts-preview-heading">
<div class="thoughts-preview-header">
<h2 id="thoughts-preview-heading">Thoughts</h2>
<a class="thoughts-all-link" href="{{ "thoughts/" | relLangURL }}">All thoughts <span aria-hidden="true">&rarr;</span></a>
</div>
<div class="thoughts-grid">
{{- range . }}
<a class="thought-card" href="{{ "thoughts/" | relLangURL }}#{{ partial "thought_anchor.html" . }}">
<span class="thought-card-text">{{ partial "thought_text.html" . }}</span>
</a>
{{- end }}
</div>
</section>
{{- end -}}

66
layouts/index.html Normal file
View File

@@ -0,0 +1,66 @@
{{- define "main" }}
{{- if (and site.Params.profileMode.enabled .IsHome) }}
{{- partial "index_profile.html" . }}
{{- else }}
{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}
{{- $pages = where $pages "Params.hiddenInHomeList" "!=" "true" }}
{{- $paginator := .Paginate $pages }}
{{- if eq $paginator.PageNumber 1 }}
{{- partial "home_info.html" . }}
{{- partial "thoughts_preview.html" . }}
{{- end }}
{{- range $index, $page := $paginator.Pages }}
{{- $class := "post-entry" }}
{{- $user_preferred := or site.Params.disableSpecial1stPost site.Params.homeInfoParams }}
{{- if (and $.IsHome (eq $paginator.PageNumber 1) (eq $index 0) (not $user_preferred)) }}
{{- $class = "first-entry" }}
{{- end }}
<article class="{{ $class }}">
{{- $isHidden := (.Param "cover.hiddenInList") | default (.Param "cover.hidden") | default false }}
{{- partial "cover.html" (dict "cxt" . "IsSingle" false "isHidden" $isHidden) }}
<header class="entry-header">
<h2 class="entry-hint-parent">
{{- .Title }}
{{- if .Draft }}
<span class="entry-hint" title="Draft">
<svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" fill="currentColor">
<path d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
</svg>
</span>
{{- end }}
</h2>
</header>
{{- if (ne (.Param "hideSummary") true) }}
<div class="entry-content">
<p>{{ .Description | plainify | htmlUnescape }}</p>
</div>
{{- end }}
{{- if not (.Param "hideMeta") }}
<footer class="entry-footer">{{- partial "post_meta.html" . -}}</footer>
{{- end }}
<a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}"></a>
</article>
{{- end }}
{{- if gt $paginator.TotalPages 1 }}
<footer class="page-footer">
<nav class="pagination">
{{- if $paginator.HasPrev }}
<a class="prev" href="{{ $paginator.Prev.URL | absURL }}">
&laquo;&nbsp;{{ i18n "prev_page" }}&nbsp;
{{- if (.Param "ShowPageNums") }}{{ sub $paginator.PageNumber 1 }}/{{ $paginator.TotalPages }}{{ end }}
</a>
{{- end }}
{{- if $paginator.HasNext }}
<a class="next" href="{{ $paginator.Next.URL | absURL }}">
{{- i18n "next_page" }}&nbsp;
{{- if (.Param "ShowPageNums") }}{{ add 1 $paginator.PageNumber }}/{{ $paginator.TotalPages }}{{ end }}&nbsp;&raquo;
</a>
{{- end }}
</nav>
</footer>
{{- end }}
{{- end }}
{{- end }}

78
layouts/rss.xml Normal file
View File

@@ -0,0 +1,78 @@
{{- $authorEmail := "" }}
{{- with site.Params.author }}
{{- if reflect.IsMap . }}
{{- with .email }}
{{- $authorEmail = . }}
{{- end }}
{{- end }}
{{- end }}
{{- $authorName := "" }}
{{- with site.Params.author }}
{{- if reflect.IsMap . }}
{{- with .name }}
{{- $authorName = . }}
{{- end }}
{{- else }}
{{- $authorName = . }}
{{- end }}
{{- end }}
{{- $pctx := . }}
{{- if .IsHome }}{{ $pctx = site }}{{ end }}
{{- $pages := slice }}
{{- if or $.IsHome $.IsSection }}
{{- $pages = $pctx.RegularPages }}
{{- else }}
{{- $pages = $pctx.Pages }}
{{- end }}
{{- $pages = where $pages "Params.hiddenInRss" "!=" true }}
{{- $pages = $pages.ByPublishDate.Reverse }}
{{- $limit := site.Config.Services.RSS.Limit }}
{{- if ge $limit 1 }}
{{- $pages = $pages | first $limit }}
{{- end }}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>{{ if eq .Title site.Title }}{{ site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ site.Title }}</description>
{{- with site.Params.images }}
<image>
<title>{{ site.Title }}</title>
<url>{{ index . 0 | absURL }}</url>
<link>{{ index . 0 | absURL }}</link>
</image>
{{- end }}
<generator>Hugo</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{.}}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with site.Copyright }}
<copyright>{{ . | markdownify | plainify | strings.TrimPrefix "© " }}</copyright>{{ end }}{{ if not .Date.IsZero }}
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{- end }}
{{- range $pages }}
{{- if and (ne .Layout `search`) (ne .Layout `archives`) }}
{{- $isThought := eq .Type "thoughts" }}
{{- $thoughtText := "" }}
{{- if $isThought }}{{ $thoughtText = partial "thought_text.html" . }}{{ end }}
{{- $link := .Permalink }}
{{- if $isThought }}{{ $link = printf "%s#%s" ("thoughts/" | absLangURL) (partial "thought_anchor.html" .) }}{{ end }}
<item>
<title>{{ if $isThought }}{{ $thoughtText }}{{ else }}{{ .Title }}{{ end }}</title>
<link>{{ $link }}</link>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }}
<guid>{{ $link }}</guid>
<description>{{ if $isThought }}{{ $thoughtText | html }}{{ else }}{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end }}{{ end }}</description>
{{- if and site.Params.ShowFullTextinRSS .Content }}
<content:encoded>{{ if $isThought }}{{ (printf "<![CDATA[%s]]>" $thoughtText) | safeHTML }}{{ else }}{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}{{ end }}</content:encoded>
{{- end }}
</item>
{{- end }}
{{- end }}
</channel>
</rss>

View File

@@ -0,0 +1,61 @@
{{- define "main" }}
<header class="page-header">
<h1>
{{ .Title }} {{- if (.Param "ShowRssButtonInSectionTermList") }} {{- with
.OutputFormats.Get "rss" }}
<a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
height="23"
>
<path d="M4 11a9 9 0 0 1 9 9" />
<path d="M4 4a16 16 0 0 1 16 16" />
<circle cx="5" cy="19" r="1" />
</svg>
</a>
{{- end }} {{- end }}
</h1>
<!-- prettier-ignore -->
{{- with (.Description | default "Things undeserving of being a whole article") }}
<div class="post-description">{{ . | markdownify }}</div>
{{- end }}
</header>
{{- if .Content }}
<div class="post-content md-content">
{{- if not (.Param "disableAnchoredHeadings") }} {{- partial
"anchored_headings.html" .Content -}} {{- else }}{{ .Content }}{{ end }}
</div>
{{- end }} {{- $thoughts := where site.RegularPages "Type" "thoughts" }} {{-
$thoughts = $thoughts.ByDate.Reverse }} {{- $paginator := .Paginate $thoughts 50
}} {{- if $paginator.Pages }}
<div class="thought-timeline" id="thought-timeline">
{{- range $paginator.Pages }} {{- partial "thought_timeline_entry.html" . }}
{{- end }}
</div>
{{- if $paginator.HasNext }}
<div class="thought-timeline-more">
<button
class="thought-load-more"
type="button"
data-next="{{ $paginator.Next.URL }}"
>
Load older thoughts
</button>
<noscript>
<a class="thought-load-more" href="{{ $paginator.Next.URL }}"
>Load older thoughts</a
>
</noscript>
</div>
{{- end }} {{- else }}
<p class="thought-empty">No thoughts yet.</p>
{{- end }} {{- end }}