Is it possible to use Hugo Pipes to replace some content, for example convert some spaces to non-breakable ones, or have I to keep this kind of tasks in say Gulp (parsing all html files)?
See gulpfile example.
Is it possible to use Hugo Pipes to replace some content, for example convert some spaces to non-breakable ones, or have I to keep this kind of tasks in say Gulp (parsing all html files)?
See gulpfile example.
You could use the replace
or replaceRE
functions in your templates
I saw these functions, but how can I pass the whole page as the INPUT of the function?
You can pass the content using .Content
Try it out and see
Yes Iβll try tomorrow, thank you!
This should help me too:
https://discourse.gohugo.io/t/refactor-multiple-replace-statements/9994
Do you have any idea why
{{ replace .Content "A" "B" | safeHTML }}
is working, but
{{ .Content | replace "A" "B" | safeHTML }}
returns
A
?
I think both are working, but work in another way as you expect.
{{ replace .Content "A" "B" }}
Replaces every βAβ inside .Content with βBβ
But {{ .Content | replace "A" "B" }}
Replaces every occurrence of βBβ it finds in βAβ with the value of .Content. And as it does not find any B in βAβ it could replace, it leaves it as βAβ.
So the following two will do the Same:
{{ replace "ABC" "A" "X" }} outputs XBC
{{ "X" | replace "ABC" "A"}} outputs XBC
Indeed thank you for pointing this out!
However then I canβt pipe multiple replace
on .Content
β¦
I think I will keep this kind of replacement in my gulpfile
You could do it like this
{{ $content := replace .Content "A" "B" }}
{{ $content = replace $content "C" "D" }}
...
{{ $content }}
This works, thank you!