fix: [layout] render-image hack allowing custom styles on img

pull/56/head
Christophe Vandeplas 2021-12-31 07:16:35 +01:00
parent 3c32371018
commit adf46f90d0
2 changed files with 110 additions and 11 deletions

View File

@ -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 youre 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)

View File

@ -1 +1,99 @@
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" class="img-responsive" />
{{- /*
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 -}}
<img src="{{ $src }}"
{{ if $srcSize }}
{{ print `src-size=` ( $srcSize | jsonify ) | safeHTMLAttr }}
{{ end }}
{{ if $placeholderSrc }}
placeholder-src="{{ $placeholderSrc }}"
{{ end }}
alt="{{ .Text }}"
{{- range $attr, $val := $attributes -}}
{{- if eq $val true -}}
{{ print $attr ` ` | safeHTMLAttr }}
{{- else -}}
{{ print $attr `="` (delimit $val ` ` ) `"` | safeHTMLAttr }}
{{- end -}}
{{- end -}} />