Introduce expandable image shortcode, improve portable links logic
This commit is contained in:
+1
-4
@@ -334,10 +334,7 @@ body[dir="rtl"] .book-menu {
|
|||||||
|
|
||||||
// Responsive styles
|
// Responsive styles
|
||||||
.book-menu-content,
|
.book-menu-content,
|
||||||
.book-toc-content,
|
.book-toc-content {
|
||||||
.book-page,
|
|
||||||
.book-header aside,
|
|
||||||
.markdown {
|
|
||||||
transition: 0.2s ease-in-out;
|
transition: 0.2s ease-in-out;
|
||||||
transition-property: transform, margin, opacity, visibility;
|
transition-property: transform, margin, opacity, visibility;
|
||||||
will-change: transform, margin, opacity;
|
will-change: transform, margin, opacity;
|
||||||
|
|||||||
@@ -200,9 +200,6 @@
|
|||||||
|
|
||||||
figure {
|
figure {
|
||||||
margin: $padding-16 0;
|
margin: $padding-16 0;
|
||||||
figcaption p {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
-7
@@ -120,6 +120,7 @@
|
|||||||
.book-badge {
|
.book-badge {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: $font-size-14;
|
font-size: $font-size-14;
|
||||||
|
font-weight: $body-font-weight;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
border-radius: $border-radius;
|
border-radius: $border-radius;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -149,6 +150,8 @@
|
|||||||
|
|
||||||
// {{< steps >}}
|
// {{< steps >}}
|
||||||
.book-steps {
|
.book-steps {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
>ol {
|
>ol {
|
||||||
counter-reset: steps;
|
counter-reset: steps;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
@@ -191,25 +194,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {{< card >}}
|
// {{< card >}}, {{< figure >}}
|
||||||
.book-card {
|
.book-card, figure {
|
||||||
display: block;
|
display: inline-block;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border-radius: $border-radius;
|
border-radius: $border-radius;
|
||||||
border: $padding-1 solid var(--gray-200);
|
border: $padding-1 solid var(--gray-200);
|
||||||
|
|
||||||
|
&[href], &[href]:visited {
|
||||||
|
color: var(--body-font-color);
|
||||||
|
}
|
||||||
&[href]:hover {
|
&[href]:hover {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background: var(--gray-100);
|
background: var(--gray-100);
|
||||||
}
|
}
|
||||||
&[href]:visited {
|
|
||||||
color: var(--body-font-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
width: 100%;
|
||||||
display: block;
|
display: block;
|
||||||
object-fit: contain;
|
|
||||||
aspect-ratio: 4 / 3;
|
aspect-ratio: 4 / 3;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
@@ -217,6 +220,36 @@
|
|||||||
.markdown-inner {
|
.markdown-inner {
|
||||||
padding: $padding-16;
|
padding: $padding-16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
figcaption {
|
||||||
|
@extend .markdown-inner;
|
||||||
|
padding: $padding-16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-image {
|
||||||
|
input + img {
|
||||||
|
cursor: zoom-in;
|
||||||
|
transition: transform 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + img {
|
||||||
|
position: fixed;
|
||||||
|
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
|
||||||
|
background: var(--body-background);
|
||||||
|
object-fit: contain;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
z-index: 1;
|
||||||
|
cursor: zoom-out;
|
||||||
|
padding: $padding-16;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.book-hero {
|
.book-hero {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 585 B After Width: | Height: | Size: 585 B |
@@ -3,18 +3,18 @@
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
{{% columns %}}
|
{{% columns %}}
|
||||||
- {{< card image="docs/shortcodes/cards/placeholder.svg" >}}
|
- {{< card image="placeholder.svg" >}}
|
||||||
### Line 1
|
### Line 1
|
||||||
Line 2
|
Line 2
|
||||||
{{< /card >}}
|
{{< /card >}}
|
||||||
|
|
||||||
- {{< card image="docs/shortcodes/cards/placeholder.svg" >}}
|
- {{< card image="placeholder.svg" >}}
|
||||||
This is tab MacOS content.
|
This is tab MacOS content.
|
||||||
{{< /card >}}
|
{{< /card >}}
|
||||||
{{% /columns %}}
|
{{% /columns %}}
|
||||||
|
|
||||||
{{% columns %}}
|
{{% columns %}}
|
||||||
- {{< card href="/" >}}
|
- {{< card href="/docs/shortcodes/cards" >}}
|
||||||
**Markdown**
|
**Markdown**
|
||||||
Suspendisse sed congue orci, eu congue metus. Nullam feugiat urna massa.
|
Suspendisse sed congue orci, eu congue metus. Nullam feugiat urna massa.
|
||||||
{{< /card >}}
|
{{< /card >}}
|
||||||
@@ -28,3 +28,36 @@
|
|||||||
This is tab MacOS content.
|
This is tab MacOS content.
|
||||||
{{< /card >}}
|
{{< /card >}}
|
||||||
{{% /columns %}}
|
{{% /columns %}}
|
||||||
|
|
||||||
|
## Build-in figure shortcode
|
||||||
|
Hugo's built-in figure shortcode is also styled as a card
|
||||||
|
|
||||||
|
{{% columns %}}
|
||||||
|
- ```go-html-template
|
||||||
|
{{</* figure
|
||||||
|
src="placeholder.svg"
|
||||||
|
alt="A placeholder image"
|
||||||
|
link="#"
|
||||||
|
caption="A placeholder image caption"
|
||||||
|
loading="lazy"
|
||||||
|
target="_blank"
|
||||||
|
title="Figure Title"
|
||||||
|
caption="A caption for the figure"
|
||||||
|
attr="An attribution"
|
||||||
|
attrlink="#"
|
||||||
|
*/>}}
|
||||||
|
```
|
||||||
|
|
||||||
|
- {{< figure
|
||||||
|
src="placeholder.svg"
|
||||||
|
alt="A placeholder image"
|
||||||
|
link="#"
|
||||||
|
caption="A placeholder image caption"
|
||||||
|
loading="lazy"
|
||||||
|
target="_blank"
|
||||||
|
title="Figure Title"
|
||||||
|
caption="A caption for the figure"
|
||||||
|
attr="An attribution"
|
||||||
|
attrlink="#"
|
||||||
|
>}}
|
||||||
|
{{% /columns %}}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# Images
|
||||||
|
|
||||||
|
Image shortcode produces an image that can be clicked to expand.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{</* image src="placeholder.svg" alt="A placeholder" title="A placeholder" loading="lazy" */>}}
|
||||||
|
```
|
||||||
|
{{< image src="placeholder.svg" alt="A placeholder" title="A placeholder" loading="lazy" >}}
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
`src` {{< badge style="warning" title="Required" >}}
|
||||||
|
: The link to the image
|
||||||
|
|
||||||
|
`class` {{< badge style="info" title="Optional" >}}
|
||||||
|
: An optional CSS class name that will be applied to the `img` element
|
||||||
|
|
||||||
|
`alt` {{< badge style="info" title="Optional" >}}
|
||||||
|
: An optional alternate text for the image
|
||||||
|
|
||||||
|
`title` {{< badge style="info" title="Optional" >}}
|
||||||
|
: An optional title for the image
|
||||||
|
|
||||||
|
`loading` {{< badge style="info" title="Optional" >}}
|
||||||
|
: Sets `loading` control for the image: `lazy`, `eager` or `auto`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,19 +1,6 @@
|
|||||||
|
{{- $destination := .Destination -}}
|
||||||
{{- if .Page.Site.Params.BookPortableLinks -}}
|
{{- if .Page.Site.Params.BookPortableLinks -}}
|
||||||
{{- template "portable-image" . -}}
|
{{- $destination = partial "docs/links/portable-image" . -}}
|
||||||
{{- else -}}
|
|
||||||
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }}title="{{ . }}"{{ end }}/>
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- define "portable-image" -}}
|
|
||||||
{{- $isRemote := or (in .Destination "://") (strings.HasPrefix .Destination "//") }}
|
|
||||||
{{- if not $isRemote }}
|
|
||||||
{{- $path := print .Page.File.Dir .Destination }}
|
|
||||||
{{- if strings.HasPrefix .Destination "/" }}
|
|
||||||
{{- $path = print "/static" .Destination }}
|
|
||||||
{{- end }}
|
|
||||||
{{- if not (fileExists $path) }}
|
|
||||||
{{- warnf "Image '%s' not found in '%s'" .Destination .Page.File }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }}title="{{ . }}"{{ end }}/>
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
<img src="{{ $destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }}title="{{ . }}"{{ end }}/>
|
||||||
|
{{- /**/ -}}
|
||||||
@@ -1,29 +1,6 @@
|
|||||||
|
{{- $destination := .Destination -}}
|
||||||
{{- if .Page.Site.Params.BookPortableLinks -}}
|
{{- if .Page.Site.Params.BookPortableLinks -}}
|
||||||
{{- template "portable-link" . -}}
|
{{- $destination = partial "docs/links/portable-link" . -}}
|
||||||
{{- else -}}
|
|
||||||
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
{{- define "portable-link" -}}
|
|
||||||
{{- $destination := .Destination }}
|
|
||||||
{{- $isRemote := or (in .Destination ":") (strings.HasPrefix .Destination "//") }}
|
|
||||||
{{- $isFragment := strings.HasPrefix .Destination "#" }}
|
|
||||||
{{- if and (not $isRemote) (not $isFragment) }}
|
|
||||||
{{- $url := urls.Parse .Destination }}
|
|
||||||
{{- $path := strings.TrimSuffix "/_index.md" $url.Path }}
|
|
||||||
{{- $path = strings.TrimSuffix "/_index" $path }}
|
|
||||||
{{- $path = strings.TrimSuffix ".md" $path }}
|
|
||||||
{{- $page := .Page.GetPage $path }}
|
|
||||||
{{- if $page }}
|
|
||||||
{{- $destination = $page.RelPermalink }}
|
|
||||||
{{- if $url.Fragment }}
|
|
||||||
{{- $destination = print $destination "#" $url.Fragment }}
|
|
||||||
{{- end }}
|
|
||||||
{{- else if fileExists (print .Page.File.Dir .Destination) }}
|
|
||||||
<!-- Nothing -->
|
|
||||||
{{- else -}}
|
|
||||||
{{- warnf "Page '%s' not found in '%s'" .Destination .Page.File }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
<a href="{{ $destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
<a href="{{ $destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||||
|
{{- /**/ -}}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{{- $destination := .Destination -}}
|
||||||
|
{{- $url := urls.Parse .Destination -}}
|
||||||
|
|
||||||
|
{{- $isRemote := gt (len $url.Host) 0 -}}
|
||||||
|
{{- $isFragment := strings.HasPrefix .Destination "#" -}}
|
||||||
|
|
||||||
|
{{- if and (not $isRemote) (not $isFragment) -}}
|
||||||
|
{{- $path := strings.TrimPrefix "./" $url.Path -}}
|
||||||
|
{{- $path = strings.TrimPrefix "/assets/" $path -}}
|
||||||
|
|
||||||
|
{{- with (.Page.Resources.Get $path) -}}
|
||||||
|
{{- $destination = .RelPermalink -}}
|
||||||
|
{{- else with (resources.Get $path) -}}
|
||||||
|
{{- $destination = .RelPermalink -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Image reference '%s' not found in '%s'" .Destination .Page.Permalink -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- with $url.RawQuery -}}
|
||||||
|
{{- $destination = print $destination "?" . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $url.Fragment -}}
|
||||||
|
{{- $destination = print $destination "#" . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- return $destination -}}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{{- $destination := .Destination -}}
|
||||||
|
{{- $url := urls.Parse .Destination -}}
|
||||||
|
|
||||||
|
{{- $isRemote := gt (len $url.Host) 0 -}}
|
||||||
|
{{- $isFragment := strings.HasPrefix .Destination "#" -}}
|
||||||
|
|
||||||
|
{{- if and (not $isRemote) (not $isFragment) -}}
|
||||||
|
{{- $path := strings.TrimPrefix "./" $url.Path -}}
|
||||||
|
{{- $path = strings.TrimSuffix ".md" $path -}}
|
||||||
|
{{- $path = strings.TrimSuffix "/_index" $path -}}
|
||||||
|
|
||||||
|
{{- with (.Page.GetPage $path) -}}
|
||||||
|
{{- $destination = .RelPermalink -}}
|
||||||
|
{{- else with (.Page.Resources.Get $path) -}}
|
||||||
|
{{- $destination = .RelPermalink -}}
|
||||||
|
{{- else with (resources.Get $path) -}}
|
||||||
|
{{- $destination = .RelPermalink -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- warnf "Reference '%s' not found in '%s'" .Destination .Page.Permalink -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- with $url.RawQuery -}}
|
||||||
|
{{- $destination = print $destination "?" . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- with $url.Fragment -}}
|
||||||
|
{{- $destination = print $destination "#" . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- return $destination -}}
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
<ul>
|
<ul>
|
||||||
{{ range . }}
|
{{ range . }}
|
||||||
<li>
|
<li>
|
||||||
{{ $local := or (.Page) (strings.HasPrefix .URL "/") }}
|
{{ $isRemote := not (or (.Page) (strings.HasPrefix .URL "/")) }}
|
||||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if not $local }}target="_blank" rel="noopener"{{ end }}>
|
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if $isRemote }}target="_blank" rel="noopener"{{ end }}>
|
||||||
{{- .Pre -}}
|
{{- .Pre -}}
|
||||||
{{ with .Page }}
|
{{ with .Page }}
|
||||||
{{ partial "docs/title" .Page }}
|
{{ partial "docs/title" .Page }}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
{{- /* remove whitespace */ -}}
|
{{- /* remove whitespace */ -}}
|
||||||
{{- if .Get "href" -}}
|
{{- with .Get "href" -}}
|
||||||
<a class="book-card{{ with .Get "class" }} {{ . }}{{ end }}"{{ with .Get "href" }} href="{{ . | relURL }}"{{ end }}>
|
{{- $destination := partial "docs/links/portable-link" (dict "Page" $.Page "Destination" .) -}}
|
||||||
{{- template "book-card-content" . -}}
|
<a class="book-card{{ with $.Get "class" }} {{ . }}{{ end }}" href="{{ $destination | safeURL }}">
|
||||||
|
{{- template "book-card-content" $ -}}
|
||||||
</a>
|
</a>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<div class="book-card{{ with .Get "class" }} {{ . }}{{ end }}">
|
<div class="book-card{{ with .Get "class" }} {{ . }}{{ end }}">
|
||||||
{{- template "book-card-content" . -}}
|
{{- template "book-card-content" $ -}}
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "book-card-content" -}}
|
{{- define "book-card-content" -}}
|
||||||
{{- with .Get "image" -}}
|
{{- with .Get "image" -}}
|
||||||
<img src="{{ . | urls.RelLangURL }}" />
|
{{- $destination := partial "docs/links/portable-image" (dict "Page" $.Page "Destination" .) -}}
|
||||||
|
<img src="{{ $destination | safeURL }}" />
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<div class="markdown-inner">
|
<div class="markdown-inner">
|
||||||
{{ with .InnerDeindent }}{{ . }}{{ end }}
|
{{ with .InnerDeindent }}{{ . }}{{ end }}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{{- /* remove whitespaces */ -}}
|
||||||
|
{{- $destination := partial "docs/links/portable-image" (dict "Page" .Page "Destination" (.Get "src")) -}}
|
||||||
|
<label class="book-image" for="book-image-toggle-{{ .Ordinal }}">
|
||||||
|
<input class="hidden toggle" type="checkbox" id="book-image-toggle-{{ .Ordinal }}" />
|
||||||
|
<img src="{{ $destination | safeURL }}"
|
||||||
|
{{- with .Get "alt"}} alt="{{ . }}"{{ end -}}
|
||||||
|
{{- with .Get "title"}} title="{{ . }}"{{ end -}}
|
||||||
|
{{- with .Get "loading"}} loading="{{ . }}"{{ end -}}
|
||||||
|
{{- with .Get "class"}} class="{{ . }}"{{ end -}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
{{- /* remove whitespaces */ -}}
|
||||||
Reference in New Issue
Block a user