Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix floating images and add clearfix shortcode #897

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions exampleSite/content/docs/image-processing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,33 @@ For example: `![Center](/featured-sample.webp#center)`.

### Float Start

![Float Start](/featured-sample.webp?height=120px#float-start)
{{% clearfix %}}
![Float Start](featured-sample.webp?height=120px#float-start) Adding the `#float-start` fragment for floating images to the start, we have to wrap it inside `clearfix` shortcode to avoid breaking the layout.

Adding the `#float-start` fragment for floating images to the start.
Please note that use `%%` instead of `<>` to render content as Markdown fully.
{{% /clearfix %}}

For example: `![Float Start](/featured-sample.webp#float-start)`.
For example.

````
{{/% clearfix %/}}
![Float Start](/featured-sample.webp#float-start) TEXTS AROUNDS THE IMAGE.
{{/% /clearfix %/}}
````

### Float End

![Float End](/featured-sample.webp?height=120px#float-end)
{{% clearfix %}}
![Float End](/featured-sample.webp?height=120px#float-end) Similarly, we can also float images to the end by adding the `#float-end` fragment.
{{% /clearfix %}}

Similarly, we can also float images to the end by adding the `#float-end` fragment.
For example.

For example: `![Float End](/featured-sample.webp#float-end)`.
````
{{/% clearfix %/}}
![Float End](/featured-sample.webp#float-end) TEXTS AROUNDS THE IMAGE.
{{/% /clearfix %/}}
````

## Caption

Expand Down
9 changes: 8 additions & 1 deletion layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{{ partial "helpers/image" (dict "filename" .Destination "alt" .Text "title" .Title "class" "img-fluid" "resources" .Page.Resources "page" .Page) }}
{{ partial "helpers/image" (dict
"filename" .Destination
"alt" .Text
"title" .Title
"class" "img-fluid"
"resources" .Page.Resources
"page" .Page)
}}
9 changes: 0 additions & 9 deletions layouts/partials/helpers/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,18 @@
{{- end -}}
{{- $className := default "img-fluid" .class -}}
{{- $posClassName := "" -}}
{{- $clearfix := false -}}
{{- if eq $url.Fragment "center" -}}
{{- $posClassName = "mx-auto d-block" -}}
{{- else if or (eq $url.Fragment "floatleft") (eq $url.Fragment "float-start") -}}
{{- if eq $url.Fragment "floatleft" }}
{{- warnf "The floatleft fragment is deprecated, will be removed in the future, please use float-start instead." }}
{{- end }}
{{- $posClassName = "float-start me-2" -}}
{{- $clearfix = true -}}
{{- else if or (eq $url.Fragment "floatright") (eq $url.Fragment "float-end") -}}
{{- if eq $url.Fragment "floatright" }}
{{- warnf "The floatright fragment is deprecated, will be removed in the future, please use float-end instead." }}
{{- end }}
{{- $posClassName = "float-end ms-2" -}}
{{- $clearfix = true -}}
{{- end -}}

{{- if and $pageResource $resizable $img }}
Expand Down Expand Up @@ -125,9 +122,6 @@

{{- $caption := and (default false .page.Site.Params.post.imageTitleAsCaption) .title }}

{{- if $clearfix }}
<div class="clearfix">
{{- end }}
{{- if $caption -}}
{{- $className = printf "%s figure-img" $className -}}
<figure class="figure{{ with $posClassName }} {{ . }}{{ end }}">
Expand All @@ -150,6 +144,3 @@
<figcaption class="figure-caption">{{ .title }}</figcaption>
</figure>
{{- end }}
{{- if $clearfix }}
</div>
{{- end -}}
3 changes: 3 additions & 0 deletions layouts/shortcodes/clearfix.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="clearfix mb-1">
{{ .Inner }}
</div>