Giter VIP home page Giter VIP logo

Comments (5)

Abbe98 avatar Abbe98 commented on June 12, 2024

The first stab looks like this but it fails to render URLs correctly because of golangs html/template security model(and rightfully so), it should probably be fixed upstream by exposing RDF URIs as template.URL although it might not be a good solution it seems: https://play.golang.org/p/carDm1O3l26

Alternativity a child one should be able to a typed string to a child template somehow. Dead end

<script type="application/ld+json">
{{ $global := metadata }}
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "description": "{{ .orgDescription }}}",
  {{ if .email }}"email": "{{ replace .email "mailto:" "" 1 }}",{{ end }}
  "additionalType": "{{ .type }}",
  "url": "{{ $global.root_url }}/{{ .countryURL }}/{{ .qid }}/",
  "sameAs": [{{ if $socialAccounts }}{{ range $socialAccounts }}"{{ .url }}",{{ end }}{{ end }}"http://wikidata.org/entity/{{ .qid }}"],
  "name": "{{ .orgLabel }}"
}
</script>

from website.

Abbe98 avatar Abbe98 commented on June 12, 2024

Two new things to test:

  1. casting to template.URL
  2. casting to template.JS

from website.

Abbe98 avatar Abbe98 commented on June 12, 2024

golang/go#17894 (comment)
https://github.com/gohugoio/hugo/blob/3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673/tpl/safe/safe.go#L40

from website.

Abbe98 avatar Abbe98 commented on June 12, 2024

One way seems to be to trick the template into believing that it's not performing rendering inside of a script tag:

{{"<script"}} type="application/ld+json">
{{- $socialAccounts := query "account-data" .qid.String -}}
{{- $global := metadata }}
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "description": "{{ .orgDescription }}",
  {{- if .email -}}"email": "{{ replace .email "mailto:" "" 1 }}",{{- end }}
  "additionalType": "{{ .type }}",
  "url": "{{ $global.root_url }}{{ template "get-country-url.html" .country }}/{{ .qid }}",
  "sameAs": [{{ if $socialAccounts }}{{ range $socialAccounts }}"{{ html .url}}",{{ end }}{{ end }}"http://wikidata.org/entity/{{ .qid }}"],
  "name": "{{ .orgLabel }}"
}
</script>

Go templates still however escapes the {{"<script"}} part...

from website.

Abbe98 avatar Abbe98 commented on June 12, 2024

Closed by b37e1c2

from website.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.