From adf46f90d0eaa05dfe9ea40dd23d73f24c91f8f7 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Fri, 31 Dec 2021 07:16:35 +0100 Subject: [PATCH] fix: [layout] render-image hack allowing custom styles on img --- content/hackathon.md | 21 ++--- layouts/_default/_markup/render-image.html | 100 ++++++++++++++++++++- 2 files changed, 110 insertions(+), 11 deletions(-) diff --git a/content/hackathon.md b/content/hackathon.md index 4cc7c4e..47f554d 100644 --- a/content/hackathon.md +++ b/content/hackathon.md @@ -8,7 +8,8 @@ featured: /img/stack.jpg # Open Source Security hackathon - Monday 25th October 2021 and Tuesday 26th October 2021 -![](/img/stack.jpg) +![stack](/img/stack.jpg "{class='img-responsive'}") + [CIRCL](https://www.circl.lu/) in collaboration with the [MISP Project](https://www.misp-project.org/) is organising the 5th Open Source Security Software Hackathon, which will take place over two days, on Monday 25th October 2021 and Tuesday 26th October 2021. @@ -70,16 +71,16 @@ The location for the in-person hackathon taking place in New York City is suppor The projects listed are merely examples and you’re more than welcome to propose other open source projects you would like to work on. -[![MISP](/img/misp-small.png)](https://www.misp-project.org/) +[![MISP](/img/misp-small.png)](https://www.misp-project.org/ ) [![D4 Project](https://www.d4-project.org/assets/images/logo.png)](https://www.d4-project.org/) [![cve-search](https://www.cve-search.org/images/cve-search.png)](https://www.cve-search.org) -[![AIL](https://www.ail-project.org/assets/img/logonav.png)](https://www.ail-project.org/) -[![OWASP Zap Proxy](https://pbs.twimg.com/profile_images/935515807949434880/T8RuttbQ_400x400.jpg)](https://www.zaproxy.org/) -[![OWASP ModSecurity Core Rule Set](https://owasp.org/www-project-modsecurity-core-rule-set/assets/images/CRS-logo-full_size-512x257.png)](https://coreruleset.org/) +[![AIL](https://www.ail-project.org/assets/img/logonav.png "{ width='250px'}")](https://www.ail-project.org/) +[![OWASP Zap Proxy](https://pbs.twimg.com/profile_images/935515807949434880/T8RuttbQ_400x400.jpg "{ width='250px'}")](https://www.zaproxy.org/) +[![OWASP ModSecurity Core Rule Set](https://owasp.org/www-project-modsecurity-core-rule-set/assets/images/CRS-logo-full_size-512x257.png "{ width='250px'}")](https://coreruleset.org/) [![Cerebrate project](https://avatars.githubusercontent.com/u/60326167?s=200&v=4)](https://github.com/cerebrate-project/) -[![Lookyloo icon](https://github.com/Lookyloo/lookyloo/raw/main/website/web/static/lookyloo.jpeg){: width="250" }](https://www.lookyloo.eu/) -[![IntelMQ Logo](https://raw.githubusercontent.com/certtools/intelmq/develop/docs/_static/Logo_Intel_MQ.png){: width="250" }](https://github.com/certtools/intelmq) -[![WHIDS Logo](https://raw.githubusercontent.com/0xrawsec/whids/master/doc/img/logo.png){: width="250"}](https://github.com/0xrawsec/whids) +[![Lookyloo icon](https://github.com/Lookyloo/lookyloo/raw/main/website/web/static/lookyloo.jpeg "{ width='250px'}")](https://www.lookyloo.eu/) +[![IntelMQ Logo](https://raw.githubusercontent.com/certtools/intelmq/develop/docs/_static/Logo_Intel_MQ.png "{ width='250px'}")](https://github.com/certtools/intelmq) +[![WHIDS Logo](https://raw.githubusercontent.com/0xrawsec/whids/master/doc/img/logo.png "{ width='250px'}")](https://github.com/0xrawsec/whids) [![MONARC](https://raw.githubusercontent.com/monarc-project/monarc-training/master/common_pictures/logo-monarc.png)](https://www.monarc.lu) -[![MOSP](https://raw.githubusercontent.com/CASES-LU/MOSP/master/mosp/static/img/logo-large.png){: width="250"}](https://github.com/CASES-LU/MOSP) -[![MWDB Core](https://raw.githubusercontent.com/CERT-Polska/mwdb-core/master/mwdb/web/src/assets/logo.png){: width="250"}](https://github.com/CERT-Polska/mwdb-core) +[![MOSP](https://raw.githubusercontent.com/CASES-LU/MOSP/master/mosp/static/img/logo-large.png "{ width='250px'}")](https://github.com/CASES-LU/MOSP) +[![MWDB Core](https://raw.githubusercontent.com/CERT-Polska/mwdb-core/master/mwdb/web/src/assets/logo.png "{ width='250px'}")](https://github.com/CERT-Polska/mwdb-core) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 9738dd2..aac36c0 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1 +1,99 @@ -{{ .Text }} +{{- /* + +Expecting: +!["alt text"](src "figcaption{Attrs}") + +More info: https://discourse.gohugo.io/t/is-it-possible-to-use-attribute-lists-with-render-hooks/31374/9?u=bep +Plus added some fixes (\w+ => [\w-]+) + +*/ -}} + + +{{- $isLocal := false -}} +{{- $src := .Destination -}} +{{- $srcSize := false -}} +{{- $placeholderSrc := false -}} + +{{- /* First, Try Local, Current Page Resource */ -}} +{{- $res := $.Page.Resources.GetMatch .Destination -}} + +{{- /* Try Local, Other page Resource */ -}} +{{- if and ( fileExists ( .Destination | safeURL ) ) ( not $res ) -}} + {{- $page := false -}} + {{ $path := ( split ( .Destination | safeURL ) "/" ) }} + {{- range $i, $p := $path -}} + {{- $subpath := (slice) -}} + {{- range seq $i -}} + {{ $subpath = $subpath | append ( slice ( index $path . )) -}} + {{- end -}} + {{- $subpath = delimit $subpath "/" -}} + {{- with $.Page.Site.GetPage ( print ( $subpath | safeURL ) ) -}} + {{- $page = . -}} + {{- end -}} + {{- end -}} + + {{- if $page -}} + {{- $resPath := strings.Replace .Destination ( $page.Path | path.Dir ) "" -}} + {{- $resPath = replaceRE `^//` `` $resPath -}} + {{- $res = $page.Resources.GetMatch $resPath -}} + {{- end -}} +{{- end -}} + +{{- /* Try Local, Asset Resource */ -}} +{{- /* TODO */ -}} + +{{- with $res -}} + {{- $src = .Permalink -}} + + {{- if eq .ResourceType "image" -}} + {{- /* Image */ -}} + {{- $placeholderSrc = ( .Resize "10x" ).Permalink -}} + {{- $srcSize = dict "width" $res.Width "height" $res.Height -}} + {{- $maxWidth := "none" -}} + {{- $maxHeight := "none" -}} + {{- else if eq .ResourceType "mp4" -}} + {{- /* Video */ -}} + {{- end -}} +{{- end -}} + +{{- $figcaption := replaceRE `{.*}$` `` .Title -}} + +{{- /* Parse attributes */ -}} +{{- $attrs := split ( trim ( index (findRE `{.*}` .Title ) 0 ) "{}" ) " " -}} +{{- $attributes := (dict) -}} +{{ range $attrs -}} + {{- if index (findRE `(\#)(.+)` .) 0 -}} + {{- /* IDs */ -}} + {{- $attributes = merge $attributes ( dict "id" (slice ( trim . "#" )) ) -}} + {{- else if index (findRE `(\.)(.+)` .) 0 -}} + {{- /* Classes */ -}} + {{- $class := slice ( trim . "." ) -}} + {{- $current := index $attributes "class" | default (slice) -}} + {{- $attributes = merge $attributes ( dict "class" ( append $current $class ) ) -}} + {{- else if index (findRE `([\w-]+)=(['"]?[\w-]+["']?)` . ) 0 -}} + {{- /* Attributes */ -}} + {{- $attr := replaceRE `([\w-]+)=(['"]?[\w-]+["']?)` `$1` . -}} + {{- $val := split ( replaceRE `([\w-]+)=(['"]?([\w-]+)["']?)` `$3` . ) " " -}} + {{- $current := index $attributes $attr | default (slice) -}} + {{- $attributes = merge $attributes ( dict $attr ( append $current $val ) ) -}} + {{- else if index (findRE `([\w-]+)` . ) 0 -}} + {{/* Booleans */}} + {{- $attributes = merge $attributes ( dict . true ) -}} + {{- end -}} +{{- end -}} + +{{ .Text }}