Add repost of syntax

This commit is contained in:
JP Hastings-Spital 2024-04-05 16:02:38 +01:00
parent 2724c57b10
commit 2e9893cdbb
10 changed files with 53 additions and 65 deletions

View file

@ -69,7 +69,7 @@
margin-left: 0.2em;
}
p.in-reply-to, p.bookmark-of, p.next-visit {
p.reference-to, p.next-visit {
font-size: small;
font-style: italic;
}
@ -553,7 +553,7 @@ details {
}
}
.bookmark-of {
.reference-to {
font-style: italic;
font-synthesis: none;
}

View file

@ -1 +1 @@
{{ partial "rich-link.html" (dict "Text" .Text "Destination" .Destination "Title" .Title "Page" .Page) }}
{{ partial "rich-link.html" (dict "Text" .Text "url" .Destination "Title" .Title "references" .Page.Params.references) }}

View file

@ -92,9 +92,11 @@
<div class="post-content e-content" data-pagefind-body data-pagefind-filter="type:{{.Type | title}}">
{{ if .Params.bookmarkOf }}
<p class="bookmark-of">{{ partial "bookmark-of.html" . }}</p>
<p class="reference-to">{{ partial "bookmark-of.html" . }}</p>
{{ else if .Params.inReplyTo -}}
<p class="in-reply-to">{{ partial "in-reply-to.html" . }}</p>
<p class="reference-to">{{ partial "in-reply-to.html" . }}</p>
{{ else if .Params.repostOf -}}
<p class="reference-to">{{ partial "repost-of.html" . }}</p>
{{- end }}
{{ .Content }}
</div>

View file

@ -1,21 +1,4 @@
{{- if not .Params.bookmarkOf -}}
{{ errorf "BookmarkOf partial called when no bookmark of param set" -}}
{{- end -}}
{{- define "partials/article-type.html" -}}
{{- if collections.In (slice "cite" "entry") . -}}
{{- "article" -}}
{{- else -}}
{{- . -}}
{{- end -}}
{{- end -}}
{{- $page := . -}}
{{- $url := .Params.bookmarkOf -}}
{{- $hostname := ($url | urls.Parse).Hostname -}}
{{- $reference := partial "reference.obj" (dict "url" $url "page" $page) -}}
{{ partial "svg.html" (dict "name" "message") }} Thoughts on{{" "}}
{{- with $reference.name -}}
the {{ partial "partials/article-type.html" (default "article" $reference.type) }} {{ partial "rich-link.html" (dict "Class" "u-bookmark-of" "Destination" $url "Text" . "Page" $page) }}
{{- else -}}
{{ partial "rich-link.html" (dict "Class" "u-bookmark-of" "Destination" $url "Text" (printf "an article from %s" $hostname) "Page" $page) }}
{{- end }}
{{ partial "reference-to.html" (dict "url" .Params.bookmarkOf "references" .Params.references "svg" "message" "phrase" "Thoughts on" "mf2" "u-bookmark-of") }}

View file

@ -1,31 +1,4 @@
{{- if not .Params.inReplyTo -}}
{{ errorf "InReplyTo partial called when no inReplyTo param set" -}}
{{- end -}}
{{- define "partials/article-type.html" -}}
{{- if collections.In (slice "cite" "entry") . -}}
{{- "article" -}}
{{- else if eq . "calendar" -}}
{{- "calendar event" -}}
{{- else -}}
{{- . | singularize -}}
{{- end -}}
{{- end -}}
{{- $page := . -}}
{{- $url := .Params.inReplyTo -}}
{{- $hostname := (($url | urls.Parse).Hostname) -}}
{{- $reference := partial "reference.obj" (dict "url" $url "page" $page) -}}
{{- if and (not $reference.name) (strings.HasPrefix $url "/") -}}
{{- $other := site.GetPage $url -}}
{{- if and $other $other.Page -}}
{{- $reference = dict "name" (partial "fallbacktitle.txt" $other.Page) "type" $other.Page.Type "internal" true -}}
{{- end -}}
{{- end -}}
{{ partial "svg.html" (dict "name" "reply") }} As a reply to{{" "}}
{{- with $reference.name -}}
{{- if $reference.internal -}}my{{else}}the{{end}} {{ partial "partials/article-type.html" (default "article" $reference.type) }} {{ partial "rich-link.html" (dict "Class" "u-in-reply-to" "Destination" $url "Text" . "Page" $page) }}.
{{- else -}}
{{- $text := printf "an article from %s" $hostname -}}
{{- partial "rich-link.html" (dict "Class" "u-in-reply-to" "Destination" $url "Text" $text "Page" $page) }}
{{- end }}
{{ partial "reference-to.html" (dict "url" .Params.inReplyTo "references" .Params.references "svg" "reply" "phrase" "As a reply to" "mf2" "u-in-reply-to") }}

View file

@ -0,0 +1,30 @@
{{- $url := .url -}}
{{- $references := .references -}}
{{- $mf2 := .mf2 -}}
{{- define "partials/article-type.html" -}}
{{- if collections.In (slice "cite" "entry") . -}}
{{- "article" -}}
{{- else if eq . "calendar" -}}
{{- "calendar event" -}}
{{- else -}}
{{- . | singularize -}}
{{- end -}}
{{- end -}}
{{- $hostname := (($url | urls.Parse).Hostname) -}}
{{- $reference := partial "reference.obj" . -}}
{{- if and (not $reference.name) (strings.HasPrefix $url "/") -}}
{{- $other := site.GetPage $url -}}
{{- if and $other $other.Page -}}
{{- $reference = dict "name" (partial "fallbacktitle.txt" $other.Page) "type" $other.Page.Type "internal" true -}}
{{- end -}}
{{- end -}}
{{ partial "svg.html" (dict "name" .svg) }} {{ .phrase }}{{" "}}
{{- with $reference.name -}}
{{- if $reference.internal -}}my{{else}}the{{end}} {{ partial "partials/article-type.html" (default "article" $reference.type) }} {{ partial "rich-link.html" (dict "Class" (printf "%s h-cite" $mf2) "url" $url "Text" . "references" $references) }}.
{{- else -}}
{{- $text := printf "an article from %s" $hostname -}}
{{- partial "rich-link.html" (dict "Class" $mf2 "url" $url "Text" $text "references" $references) }}
{{- end }}

View file

@ -1,7 +1,7 @@
{{- $url := .url -}}
{{- $page := .page -}}
{{- $references := .references -}}
{{- $reference := dict -}}
{{- range $page.Params.references -}}
{{- range $references -}}
{{- if eq .url $url -}}
{{- $reference = . -}}
{{- end }}

View file

@ -0,0 +1,6 @@
{{- if not .Params.repostOf -}}
{{ errorf "RepostOf partial called when no repost param set" -}}
{{- end -}}
{{ partial "reference-to.html" (dict "url" .Params.repostOf "references" .Params.references "svg" "repost" "phrase" "Repost of" "mf2" "u-repost-of") }}

View file

@ -1,6 +1,6 @@
{{- $destination := .Destination -}}
{{- $url := .url -}}
{{- $title := .Title -}}
{{- $isExternal := strings.HasPrefix $destination "http" -}}
{{- $isExternal := strings.HasPrefix $url "http" -}}
{{- $text := .Text -}}
{{/* It pains me that Hugo doesn't have a urls.IsValid method, and has no error catching to allow me to try urls.Parse and catch failures */}}
{{- if gt (len (strings.FindRE `^https?:\/\/[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$` .Text)) 0 -}}
@ -17,13 +17,5 @@
{{- $text = path.Join $text "…" $last -}}
{{- end -}}
{{- end -}}
{{- $ref := dict -}}
{{- range $k, $refSpec := .Page.Params.references -}}
{{- if eq $refSpec.url $destination -}}
{{- $ref = $refSpec -}}
{{- if and (ne $title $ref.name) (ne $text $ref.name) -}}
{{- $title = printf "External article: %s" $ref.name -}}
{{- end -}}
{{- end -}}
{{- end -}}
<a href="{{ $destination | safeURL }}"{{ with .Class }} class="{{ . }}"{{ end }}{{ with $title }} title="{{ . }}"{{ end }}{{ if $isExternal }} target="_blank"{{ end }}{{ with $ref.rel }} rel="{{ . }}"{{ end }}>{{ $text | safeHTML }}</a>
{{- $ref := partial "reference.obj" (dict "url" $url "references" .references) -}}
<a href="{{ $url | safeURL }}"{{ with .Class }} class="{{ . }}"{{ end }}{{ with $title }} title="{{ . }}"{{ end }}{{ if $isExternal }} target="_blank"{{ end }}{{ with $ref.rel }} rel="{{ . }}"{{ end }}>{{ $text | safeHTML }}</a>

View file

@ -148,6 +148,8 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="none"><path d="M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.248 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z"/></svg>
{{- else if (eq .name "reply") -}}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 10 20 15 15 20"></polyline><path d="M4 4v7a4 4 0 0 0 4 4h12"></path></svg>
{{- else if (eq .name "repost") -}}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"></polyline><path d="M3 11V9a4 4 0 0 1 4-4h14"></path><polyline points="7 23 3 19 7 15"></polyline><path d="M21 13v2a4 4 0 0 1-4 4H3"></path></svg>
{{- else if (eq .name "researchgate") -}}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="none"><path d="M19.586 0c-.818 0-1.508.19-2.073.565-.563.377-.97.936-1.213 1.68a3.193 3.193 0 0 0-.112.437 8.365 8.365 0 0 0-.078.53 9 9 0 0 0-.05.727c-.01.282-.013.621-.013 1.016a31.121 31.123 0 0 0 .014 1.017 9 9 0 0 0 .05.727 7.946 7.946 0 0 0 .077.53h-.005a3.334 3.334 0 0 0 .113.438c.245.743.65 1.303 1.214 1.68.565.376 1.256.564 2.075.564.8 0 1.536-.213 2.105-.603.57-.39.94-.916 1.175-1.65.076-.235.135-.558.177-.93a10.9 10.9 0 0 0 .043-1.207v-.82c0-.095-.047-.142-.14-.142h-3.064c-.094 0-.14.047-.14.141v.956c0 .094.046.14.14.14h1.666c.056 0 .084.03.084.086 0 .36 0 .62-.036.865-.038.244-.1.447-.147.606-.108.385-.348.664-.638.876-.29.212-.738.35-1.227.35-.545 0-.901-.15-1.21-.353-.306-.203-.517-.454-.67-.915a3.136 3.136 0 0 1-.147-.762 17.366 17.367 0 0 1-.034-.656c-.01-.26-.014-.572-.014-.939a26.401 26.403 0 0 1 .014-.938 15.821 15.822 0 0 1 .035-.656 3.19 3.19 0 0 1 .148-.76 1.89 1.89 0 0 1 .742-1.01c.344-.244.593-.352 1.137-.352.508 0 .815.096 1.144.303.33.207.528.492.764.925.047.094.111.118.198.07l1.044-.43c.075-.048.09-.115.042-.199a3.549 3.549 0 0 0-.466-.742 3 3 0 0 0-.679-.607 3.313 3.313 0 0 0-.903-.41A4.068 4.068 0 0 0 19.586 0zM8.217 5.836c-1.69 0-3.036.086-4.297.086-1.146 0-2.291 0-3.007-.029v.831l1.088.2c.744.144 1.174.488 1.174 2.264v11.288c0 1.777-.43 2.12-1.174 2.263l-1.088.2v.832c.773-.029 2.12-.086 3.465-.086 1.29 0 2.951.057 3.667.086v-.831l-1.49-.2c-.773-.115-1.174-.487-1.174-2.264v-4.784c.688.057 1.29.057 2.206.057 1.748 3.123 3.41 5.472 4.355 6.56.86 1.032 2.177 1.691 3.839 1.691.487 0 1.003-.086 1.318-.23v-.744c-1.031 0-2.063-.716-2.808-1.518-1.26-1.376-2.95-3.582-4.355-6.074 2.32-.545 4.04-2.722 4.04-4.9 0-3.208-2.492-4.698-5.758-4.698zm-.515 1.29c2.406 0 3.839 1.26 3.839 3.552 0 2.263-1.547 3.782-4.097 3.782-.974 0-1.404-.03-2.063-.086v-7.19c.66-.059 1.547-.059 2.32-.059z"/></svg>
{{- else if (eq .name "review") -}}