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

Remove whitespace #32

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 2 additions & 5 deletions layouts/partials/images/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,8 @@
{{- $figureClass := default "figure" $siteParams.figure_class_name }}
{{- $figureCaptionClass := default "figure-caption" $siteParams.figure_caption_class_name }}
{{- $figureImgClass := default "figure-img" $siteParams.figure_image_class_name }}
<figure class="{{ $figureClass }} {{ $wrapperClass }}">
{{ partial "images/picture" (merge $ctx (dict "className" (printf "%s %s" $figureImgClass $className))) }}
<figcaption class="{{ $figureCaptionClass }}">{{ $caption }}</figcaption>
</figure>
<figure class="{{ $figureClass }} {{ $wrapperClass }}">{{ partial "images/picture" (merge $ctx (dict "className" (printf "%s %s" $figureImgClass $className))) }}<figcaption class="{{ $figureCaptionClass }}">{{ $caption }}</figcaption></figure>
{{- else }}
{{ partial "images/picture" (merge $ctx (dict "wrapperClass" $wrapperClass)) }}
{{ partial "images/picture" (merge $ctx (dict "wrapperClass" $wrapperClass)) }}
{{- end }}
{{- end -}}
18 changes: 4 additions & 14 deletions layouts/partials/images/picture.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<picture{{ with .wrapperClass }} class="{{ . }}"{{ end }}>
{{- range .sources }}
<source srcset="{{ .srcset }}" type="{{ .type }}" />
{{- end }}
<img
class="{{ .className }}"
src="{{ .src }}"
alt="{{ .alt }}"
{{ if .lazyLoading }}loading="lazy"{{ end }}
{{ with .naturalHeight }}height="{{ . }}"{{ end }}
{{ with .naturalWidth }}width="{{ . }}"{{ end }}
{{ with .style }}{{ printf `style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}
{{ if and .original .originalSrc }}data-src="{{ .originalSrc }}"{{ end }}
{{ if and .original .originalWidth }}data-width="{{ .originalWidth }}"{{ end }}
{{ if and .original .originalHeight }}data-height="{{ .originalHeight }}"{{ end }} />
{{- range .sources }}
<source srcset="{{ .srcset }}" type="{{ .type }}" />
{{- end }}
<img class="{{ .className }}" src="{{ .src }}" alt="{{ .alt }}"{{ if .lazyLoading }} loading="lazy"{{ end }}{{ with .naturalHeight }} height="{{ . }}"{{ end }}{{ with .naturalWidth }} width="{{ . }}"{{ end }}{{ with .style }}{{ printf ` style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}{{ if and .original .originalSrc }} data-src="{{ .originalSrc }}"{{ end }}{{ if and .original .originalWidth }} data-width="{{ .originalWidth }}"{{ end }}{{ if and .original .originalHeight }} data-height="{{ .originalHeight }}"{{ end }} />
Copy link
Member

@razonyang razonyang Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this neccessary? If not, please do not inline it, it's hard to read (review) and maintain the code.
Hugo has --minify flag to minify the HTML codes, we don't need to take care of this manually (extra whitespaces line break etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with this code:

<picture{{ with .wrapperClass }} class="{{ . }}"{{ end }}>
{{- range .sources }}
<source srcset="{{ .srcset }}" type="{{ .type }}" />
{{- end }}
<img class="{{ .className }}"
  src="{{ .src }}"
  alt="{{ .alt }}"
  {{ if .lazyLoading }}loading="lazy"{{ end }}
  {{ with .naturalHeight }}height="{{ . }}"{{ end }}
  {{ with .naturalWidth }}width="{{ . }}"{{ end }}
  {{ with .style }}{{ printf ` style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}
  {{ if and .original .originalSrc }}data-src="{{ .originalSrc }}"{{ end }}
  {{ if and .original .originalWidth }} data-width="{{ .originalWidth }}"{{ end }}
  {{ if and .original .originalHeight }} data-height="{{ .originalHeight }}"{{ end }} />
</picture>

In this code, I only removed HTML tag indentation.

But this will leave /> appear in render result.

1

I also removed two whitespace in front of src=, alt= etc. but that didn't make any difference.

I think every whitespace and line break must be removed to prevent this kind of problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please share your use case (how do you use it and reproduce), not sure what cause this.

</picture>