EN VI

Javascript - How do I add structured data json script to Pug JS?

2024-03-09 23:00:11
Javascript - How do I add structured data json script to Pug JS

I am trying to add in a script of json that is structured data for SEO into my Pug JS file. I am doing it the same way I do JavaScript with type="text/javascript", but it does not compile and I keep getting errors. Is it a syntax issue? Please tell me what I am doing wrong, thank you.

script(type="application/ld+json"{ "@context": "https://schema.org", "@graph": [ { "@type": "WebPage", "@id": "https://www.example.io/some-page/", "url": "https://www.example.io/some-page/", "name": "Access Example's Knowledge Base", "isPartOf": { "@id": "https://www.example.io/#website" })
Unexpected character : expected `=`
Details:
    code: PUG:INVALID_KEY_CHARACTER
    msg: Unexpected character : expected `=`
    line: 14
    column: 53
Syntax Error: Unexpected token
Details:
    code: PUG:SYNTAX_ERROR
    msg: Syntax Error: Unexpected token
    line: 14
    column: 38

Solution:

Try this one:

script(type='application/ld+json').
{
"@context": "https://schema.org",
"@graph": [
  {
    "@type": "WebPage",
    "@id": "https://www.example.io/some-page/",
    "url": "https://www.example.io/some-page/",
    "name": "Access Example's Knowledge Base",
    "isPartOf": {
      "@id": "https://www.example.io/#website"
    }
  }
 ]
}
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login