Skip to content

Commit

Permalink
⚡ update image render hook (embed, inline svg images)
Browse files Browse the repository at this point in the history
📄 README.MD update
  • Loading branch information
colinwilson committed Aug 9, 2023
1 parent 5afc9d3 commit 18f6d35
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Check out the demo site [https://lotusdocs.dev/docs](https://lotusdocs.dev/docs)
* [ ] [Open Graph](https://ogp.me/)
* [ ] [Mermaid](https://mermaid.js.org/) Support
* [ ] Math equations powered by [KaTeX](https://katex.org/)
* [ ] Feedback widget

## Getting Started

Expand Down
6 changes: 5 additions & 1 deletion assets/docs/scss/custom/structure/_general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ a {
}
p {
line-height: 1.6;
}
}
img {
width: 100%;
height: auto;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/landing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hero:

image:
path: "images" # path to image under configured assets directory. default 'images'
filename: "Lotus Docs Screenshot.png" # filename of your hero image (including file extension)
filename: "lotus_docs_screenshot.png" # filename of your hero image (including file extension)
alt: "Lotus Docs Screenshot" # Optional but recommended
boxShadow: true # default 'false' (excludes .svg images)
rounded: true # round the image corners? default 'false' (excludes .svg images)
Expand Down
29 changes: 27 additions & 2 deletions layouts/docs/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
{{ $dest := .Destination }}
{{ $text := .PlainText }}
{{ $url := urls.Parse $dest }}

{{ $image := newScratch }}
{{ with $url.Scheme }}
{{ $image.Set "resource" (resources.GetRemote $dest) }}
{{ else }}
{{ $image.Set "resource" (resources.Get $dest) }}
{{ end }}

{{ if .Title }}
<figure>
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" loading="lazy">
{{ with ($image.Get "resource") }}
{{ if eq .MediaType.SubType "svg" }}
{{ .Content | safeHTML }}
{{ else }}
<img src="{{ .RelPermalink | safeURL }}" alt="{{ $text }}" width="{{ .Width }}" height="{{ .Height }}" loading="lazy">
{{ end }}
{{ else }}
<img src="{{ .Destination | safeURL }}" alt="{{ $text }}" width="{{ .Width }}" height="{{ .Height }}" loading="lazy">
{{ end }}
<figcaption>{{ .Title | markdownify }}</figcaption>
</figure>
{{ else }}
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" loading="lazy">
{{ with ($image.Get "resource") }}
{{ if eq .MediaType.SubType "svg" }}
{{ .Content | safeHTML }}
{{ else }}
<img src="{{ .RelPermalink | safeURL }}" alt="{{ $text }}" width="{{ .Width }}" height="{{ .Height }}" loading="lazy">
{{ end }}
{{ end }}
{{ end }}

0 comments on commit 18f6d35

Please sign in to comment.