feat: display author avatar images in blog post (#204)

* feat: support displaying author images in blog post

* chore: fix typo

* chore: run build:css

* refactor: support both plain author list

* chore: run build:css

* chore: add support for local avatar images

* chore: update css classes
This commit is contained in:
Xin 2023-11-16 20:49:18 -05:00 committed by GitHub
parent d675d3bc7b
commit 27c976bcc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 24 deletions

View File

@ -634,6 +634,9 @@ video {
.ml-4 {
margin-left: 1rem;
}
.mr-1 {
margin-right: 0.25rem;
}
.mr-2 {
margin-right: 0.5rem;
}
@ -848,6 +851,9 @@ video {
.flex-col {
flex-direction: column;
}
.flex-wrap {
flex-wrap: wrap;
}
.items-start {
align-items: flex-start;
}
@ -878,6 +884,17 @@ video {
.gap-4 {
gap: 1rem;
}
.gap-x-1 {
-moz-column-gap: 0.25rem;
column-gap: 0.25rem;
}
.gap-x-1\.5 {
-moz-column-gap: 0.375rem;
column-gap: 0.375rem;
}
.gap-y-2 {
row-gap: 0.5rem;
}
.overflow-auto {
overflow: auto;
}
@ -1408,9 +1425,6 @@ video {
-webkit-hyphens: auto;
hyphens: auto;
}
.\[text-underline-position\:from-font\] {
text-underline-position: from-font;
}
.\[transition\:background-color_1\.5s_ease\] {
transition: background-color 1.5s ease;
}
@ -2735,6 +2749,9 @@ body {
--tw-rotate: 90deg;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}
.group:hover .group-hover\:underline {
text-decoration-line: underline;
}
.group\/code:hover .group-hover\/code\:opacity-100 {
opacity: 1;
}

View File

@ -2,8 +2,12 @@
title: Markdown Syntax Guide
date: 2020-01-01
authors:
- name: John Doe
link: https://example.com/johndoe
- name: imfing
link: https://github.com/imfing
image: https://github.com/imfing.png
- name: Octocat
link: https://github.com/octocat
image: https://github.com/octocat.png
tags:
- Markdown
- Example

View File

@ -66,7 +66,6 @@
"[-webkit-touch-callout:none]",
"[counter-reset:step]",
"[hyphens:auto]",
"[text-underline-position:from-font]",
"[transition:background-color_1.5s_ease]",
"[word-break:break-word]",
"absolute",
@ -241,6 +240,7 @@
"fixed",
"flex",
"flex-col",
"flex-wrap",
"focus:bg-white",
"focus:outline-none",
"focus:ring-4",
@ -258,6 +258,8 @@
"gap-1",
"gap-2",
"gap-4",
"gap-x-1.5",
"gap-y-2",
"grid",
"grid-cols-1",
"group",
@ -266,6 +268,7 @@
"group-data-[theme=dark]:hidden",
"group-data-[theme=light]:hidden",
"group-hover/code:opacity-100",
"group-hover:underline",
"group-open:before:rotate-90",
"group/code",
"group/copybtn",
@ -407,6 +410,7 @@
"ml-1",
"ml-4",
"mobile-menu-overlay",
"mr-1",
"mr-2",
"mt-1",
"mt-1.5",

View File

@ -1,13 +1,13 @@
{{- $alt := .PlainText | safeHTML -}}
{{- $lazyLoading := .Page.Site.Params.enableImagelazyLoading | default true -}}
{{- $lazyLoading := .Page.Site.Params.enableImageLazyLoading | default true -}}
{{- $dest := .Destination -}}
{{- $isRemote := not (urls.Parse $dest).Scheme -}}
{{- $isLocal := not (urls.Parse $dest).Scheme -}}
{{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}}
{{- $startsWithSlash := hasPrefix $dest "/" -}}
{{- $startsWithRelative := hasPrefix $dest "../" -}}
{{- if and $dest $isRemote -}}
{{- if and $dest $isLocal -}}
{{- if $startsWithSlash -}}
{{/* Images under static directory */}}
{{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}

View File

@ -1,27 +1,40 @@
{{ define "main" }}
<div class='mx-auto flex {{ partial "utils/page-width" . }}'>
<div class="mx-auto flex {{ partial `utils/page-width` . }}">
{{ partial "sidebar.html" (dict "context" . "disableSidebar" true "displayPlaceholder" true) }}
{{ partial "toc.html" . }}
<article class="w-full break-words flex min-h-[calc(100vh-var(--navbar-height))] min-w-0 justify-center pb-8 pr-[calc(env(safe-area-inset-right)-1.5rem)]">
<main class="w-full min-w-0 max-w-6xl px-6 pt-4 md:px-12">
{{ partial "breadcrumb.html" . }}
<h1 class="mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate-100">{{ .Title }}</h1>
{{ with $date := .Date }}
<div class="mt-4 mb-16 text-gray-500 text-sm">
{{ partial "utils/format-date" $date }}
{{- if $.Params.authors }}&nbsp;by&nbsp;{{ end -}}
<div class="mt-4 mb-16 text-gray-500 text-sm flex items-center flex-wrap gap-y-2">
{{- with $date := .Date }}<span class="mr-1">{{ partial "utils/format-date" $date }}</span>{{ end -}}
{{- $lazyLoading := site.Params.enableImageLazyLoading | default true -}}
{{ if and .Date .Params.authors }}<span class="mx-1">·</span>{{ end -}}
{{- with $.Params.authors -}}
{{- range $i, $author := . -}}
{{- if $i }},{{ end -}}
{{- if $author.link -}}
<a href="{{ $author.link }}" target="_blank" class="mx-1 text-current underline [text-underline-position:from-font] decoration-from-font">{{ $author.name }}</a>
{{- if reflect.IsMap $author -}}
{{- if and $i (not $author.image) }}<span class="mr-1">,</span>{{ end -}}
<a
{{ with $author.link }}href="{{ . }}" target="_blank"{{ end }}
class="group inline-flex items-center text-current gap-x-1.5 mx-1"
{{ with $author.name }}title="{{ . }}"{{ end }}
>
{{- with $image := $author.image }}
{{- $isLocal := not (urls.Parse $image).Scheme -}}
{{- $startsWithSlash := hasPrefix $image "/" -}}
{{- if and $isLocal $startsWithSlash }}
{{- $image = (relURL (strings.TrimPrefix "/" $image)) -}}
{{ end -}}
<img src="{{ $image | safeURL }}" alt="{{ $author.name }}" class="inline-block h-4 w-4 rounded-full" {{ if $lazyLoading }}loading="lazy"{{ end }} />
{{ end -}}
<div class="group-hover:underline">{{ $author.name }}</div>
</a>
{{- else -}}
<span>{{ $author.name }}</span>
{{- if $i }}<span class="mr-1">,</span>{{ end -}}<span class="mx-1">{{ $author }}</span>
{{- end -}}
{{- end -}}
{{- end -}}
</div>
{{ end }}
<div class="content">
{{ .Content }}
</div>