Merge pull request #80 from artis3n/master

feat: add optional response images with cloudinary
This commit is contained in:
Guru Sabarish
2022-12-13 22:42:32 +05:30
committed by GitHub
6 changed files with 46 additions and 2 deletions
+1 -1
View File
@@ -16,4 +16,4 @@ hugo.darwin
hugo.linux hugo.linux
# Temporary lock file while building # Temporary lock file while building
/.hugo_build.lock .hugo_build.lock
+5
View File
@@ -62,6 +62,11 @@ params:
# Note the lack of "" in true, it should be of boolean type. # Note the lack of "" in true, it should be of boolean type.
useBootstrapCDN: false useBootstrapCDN: false
# If you want to load dynamically responsive images from Cloudinary
# This requires your images to be uploaded + hosted on Cloudinary
# Uncomment and change YOUR_CLOUD_NAME to the Cloud Name in your Cloudinary console
# cloudinary_cloud_name: "YOUR_CLOUD_NAME"
# Whether the fade animations on the home page will be enabled # Whether the fade animations on the home page will be enabled
animate: true animate: true
+22
View File
@@ -51,3 +51,25 @@ Hugo ships with several [Built-in Shortcodes](https://gohugo.io/content-manageme
<br> <br>
{{< youtube w7Ft2ymGmfc >}} {{< youtube w7Ft2ymGmfc >}}
<br> <br>
## Theme Custom Shortcodes
These shortcodes are not Hugo built-ins, but are provided by the theme.
### Responsive Images with Cloudinary
You can learn more about this [here](https://cloudinary.com/documentation/responsive_images).
Set the `cloudinary_cloud_name` parameter in your site config to use this shortcode.
```
{{</* dynamic-img src="/my/image/on/cloudinary" title="A title for the image" */>}}
```
Note that you do not include the file extension (e.g. `.png`) in the `src` parameter, as the shortcode will automatically determine the best quality and format for the user's device.
Optionally, you can customize the general CSS styles for the image:
```
{{</* dynamic-img src="/my/image/on/cloudinary" title="A title for the image" style="max-width:60%" */>}}
```
+1
View File
@@ -1,6 +1,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Accept-CH" content="DPR, Viewport-Width, Width">
<link rel="icon" href={{ .Site.Params.favicon | default "/fav.png" }} type="image/gif"> <link rel="icon" href={{ .Site.Params.favicon | default "/fav.png" }} type="image/gif">
<!-- Fonts --> <!-- Fonts -->
+11
View File
@@ -66,3 +66,14 @@
{{ if not (.Site.Params.navbar.disableSearch | default false) }} {{ if not (.Site.Params.navbar.disableSearch | default false) }}
<script src="/js/search.js"></script> <script src="/js/search.js"></script>
{{ end }} {{ end }}
{{ if (.Site.Params.cloudinary_cloud_name | default false) }}
{{ "<!-- cloudinary -->" | safeHTML }}
<script src="https://unpkg.com/cloudinary-core@2.13.0/cloudinary-core-shrinkwrap.js" integrity="sha384-0bQduxVhZMs6xfvcPH9osdUIw44hjF8EahHuQBdyN6Rryk8tgyFO80Yz5d14F+5d" crossorigin="anonymous"></script>
<script type="text/javascript">
var cl = cloudinary.Cloudinary.new({cloud_name: "{{- .Site.Params.cloudinary_cloud_name }}"});
cl.responsive();
</script>
{{ end }}
+5
View File
@@ -0,0 +1,5 @@
{{ $image := .Get "src" }}
{{ $alt := .Get "title" }}
{{ $width := .Get "width" | default "w_auto" }}
{{ $style := .Get "style" | default "max-width:80%" }}
<img alt="{{ $alt }}" title="{{ $alt }}" data-src="https://res.cloudinary.com/{{ $.Site.Params.cloudinary_cloud_name }}/{{ $width }},c_scale,f_auto,q_auto,dpr_auto{{ $image}}" class="cld-responsive" style="padding-bottom: 16px; display: block; margin: auto; {{ $style }}">