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
|
||||
.book-menu-content,
|
||||
.book-toc-content,
|
||||
.book-page,
|
||||
.book-header aside,
|
||||
.markdown {
|
||||
.book-toc-content {
|
||||
transition: 0.2s ease-in-out;
|
||||
transition-property: transform, margin, opacity, visibility;
|
||||
will-change: transform, margin, opacity;
|
||||
|
||||
@@ -200,9 +200,6 @@
|
||||
|
||||
figure {
|
||||
margin: $padding-16 0;
|
||||
figcaption p {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+40
-7
@@ -120,6 +120,7 @@
|
||||
.book-badge {
|
||||
display: inline-block;
|
||||
font-size: $font-size-14;
|
||||
font-weight: $body-font-weight;
|
||||
vertical-align: middle;
|
||||
border-radius: $border-radius;
|
||||
overflow: hidden;
|
||||
@@ -149,6 +150,8 @@
|
||||
|
||||
// {{< steps >}}
|
||||
.book-steps {
|
||||
position: relative;
|
||||
|
||||
>ol {
|
||||
counter-reset: steps;
|
||||
list-style: none;
|
||||
@@ -191,25 +194,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
// {{< card >}}
|
||||
.book-card {
|
||||
display: block;
|
||||
// {{< card >}}, {{< figure >}}
|
||||
.book-card, figure {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
border-radius: $border-radius;
|
||||
border: $padding-1 solid var(--gray-200);
|
||||
|
||||
&[href], &[href]:visited {
|
||||
color: var(--body-font-color);
|
||||
}
|
||||
&[href]:hover {
|
||||
text-decoration: none;
|
||||
background: var(--gray-100);
|
||||
}
|
||||
&[href]:visited {
|
||||
color: var(--body-font-color);
|
||||
}
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
aspect-ratio: 4 / 3;
|
||||
object-fit: cover;
|
||||
}
|
||||
@@ -217,6 +220,36 @@
|
||||
.markdown-inner {
|
||||
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 {
|
||||
|
||||
|
Before Width: | Height: | Size: 585 B After Width: | Height: | Size: 585 B |
@@ -3,18 +3,18 @@
|
||||
## Example
|
||||
|
||||
{{% columns %}}
|
||||
- {{< card image="docs/shortcodes/cards/placeholder.svg" >}}
|
||||
- {{< card image="placeholder.svg" >}}
|
||||
### Line 1
|
||||
Line 2
|
||||
{{< /card >}}
|
||||
|
||||
- {{< card image="docs/shortcodes/cards/placeholder.svg" >}}
|
||||
- {{< card image="placeholder.svg" >}}
|
||||
This is tab MacOS content.
|
||||
{{< /card >}}
|
||||
{{% /columns %}}
|
||||
|
||||
{{% columns %}}
|
||||
- {{< card href="/" >}}
|
||||
- {{< card href="/docs/shortcodes/cards" >}}
|
||||
**Markdown**
|
||||
Suspendisse sed congue orci, eu congue metus. Nullam feugiat urna massa.
|
||||
{{< /card >}}
|
||||
@@ -28,3 +28,36 @@
|
||||
This is tab MacOS content.
|
||||
{{< /card >}}
|
||||
{{% /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 -}}
|
||||
{{- template "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 }}/>
|
||||
{{- $destination = partial "docs/links/portable-image" . -}}
|
||||
{{- end -}}
|
||||
<img src="{{ $destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }}title="{{ . }}"{{ end }}/>
|
||||
{{- /**/ -}}
|
||||
@@ -1,29 +1,6 @@
|
||||
{{- $destination := .Destination -}}
|
||||
{{- if .Page.Site.Params.BookPortableLinks -}}
|
||||
{{- template "portable-link" . -}}
|
||||
{{- else -}}
|
||||
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
||||
{{- $destination = partial "docs/links/portable-link" . -}}
|
||||
{{- 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 -}}
|
||||
{{- /**/ -}}
|
||||
@@ -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>
|
||||
{{ range . }}
|
||||
<li>
|
||||
{{ $local := or (.Page) (strings.HasPrefix .URL "/") }}
|
||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if not $local }}target="_blank" rel="noopener"{{ end }}>
|
||||
{{ $isRemote := not (or (.Page) (strings.HasPrefix .URL "/")) }}
|
||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if $isRemote }}target="_blank" rel="noopener"{{ end }}>
|
||||
{{- .Pre -}}
|
||||
{{ with .Page }}
|
||||
{{ partial "docs/title" .Page }}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
{{- /* remove whitespace */ -}}
|
||||
{{- if .Get "href" -}}
|
||||
<a class="book-card{{ with .Get "class" }} {{ . }}{{ end }}"{{ with .Get "href" }} href="{{ . | relURL }}"{{ end }}>
|
||||
{{- template "book-card-content" . -}}
|
||||
{{- with .Get "href" -}}
|
||||
{{- $destination := partial "docs/links/portable-link" (dict "Page" $.Page "Destination" .) -}}
|
||||
<a class="book-card{{ with $.Get "class" }} {{ . }}{{ end }}" href="{{ $destination | safeURL }}">
|
||||
{{- template "book-card-content" $ -}}
|
||||
</a>
|
||||
{{- else -}}
|
||||
<div class="book-card{{ with .Get "class" }} {{ . }}{{ end }}">
|
||||
{{- template "book-card-content" . -}}
|
||||
{{- template "book-card-content" $ -}}
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
{{- define "book-card-content" -}}
|
||||
{{- with .Get "image" -}}
|
||||
<img src="{{ . | urls.RelLangURL }}" />
|
||||
{{- $destination := partial "docs/links/portable-image" (dict "Page" $.Page "Destination" .) -}}
|
||||
<img src="{{ $destination | safeURL }}" />
|
||||
{{- end }}
|
||||
<div class="markdown-inner">
|
||||
{{ 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