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,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 }}