Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add a non-javascript script tag to the head #538

Closed
3 tasks done
wynksaiddestroy opened this issue Feb 15, 2022 · 0 comments
Closed
3 tasks done

Can't add a non-javascript script tag to the head #538

wynksaiddestroy opened this issue Feb 15, 2022 · 0 comments
Labels
bug: pending triage Maybe a bug, waiting for confirmation

Comments

@wynksaiddestroy
Copy link
Contributor

Describe the bug

I want to add structured data to my app. Therefore I have to insert some JSON-LD to the head of my page layout as follows

<html>
  <head>
    <script type="application/ld+json">
      {
      "@context": "https://json-ld.org/contexts/person.jsonld",
      "@id": "http://dbpedia.org/resource/John_Lennon",
      "name": "John Lennon",
      "born": "1940-10-09",
      "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
    }
  </script>
  ...

According to the documentation and the linked source this is how it is done:

module.exports = {
  head: [
    ['script', { type: 'application/ld+json' }, '{"@context": "https://json-ld.org/contexts/person.jsonld", "@id": "http://dbpedia.org/resource/John_Lennon", "name": "John Lennon", "born": "1940-10-09", "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"}']
  ]
}

But this will fail with the following message:

✖ rendering pages...
build error:
 Error: Transform failed with 1 error:
inline-script.js:1:11: error: Expected ";" but found ":"
    at failureErrorWithLog (/home/raymond/Sites/website-next/node_modules/esbuild/lib/main.js:1493:15)
    at /home/raymond/Sites/website-next/node_modules/esbuild/lib/main.js:1282:29
    at /home/raymond/Sites/website-next/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/home/raymond/Sites/website-next/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/home/raymond/Sites/website-next/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23) {
  errors: [
    {
      detail: undefined,
      location: [Object],
      notes: [],
      pluginName: '',
      text: 'Expected ";" but found ":"'
    }
  ],
  warnings: [],
  frame: '\n' +
    '\x1B[33mExpected ";" but found ":"\x1B[39m\n' +
    '1  |  {"@context": "https://json-ld.org/contexts/person.jsonld", "@id": "http://dbpedia.org/resource/John_Lennon", "name": "John Lennon", "born": "1940-10-09", "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"}\n' +
    '   |             ^\n',
  loc: {
    column: 11,
    file: 'inline-script.js',
    length: 1,
    line: 1,
    lineText: '{"@context": "https://json-ld.org/contexts/person.jsonld", "@id": "http://dbpedia.org/resource/John_Lennon", "name": "John Lennon", "born": "1940-10-09", "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"}',
    namespace: '',
    suggestion: ''
  }
}
error Command failed with exit code 1.

Reproduction

Try to add a <script> tag the head that consists of non-javascript content. For example:

module.exports = {
  head: [
    ['script', { type: 'application/ld+json' }, '{ "foo": "bar" }']
  ]
}

Expected behavior

I expect that the defined <script> tag will be added to my sites head.

System Info

System:
  OS: Linux 5.13 Ubuntu 20.04.3 LTS (Focal Fossa)
  CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Memory: 10.35 GB / 23.13 GB
  Container: Yes
  Shell: 5.8 - /usr/bin/zsh
Binaries:
  Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
  Yarn: 1.22.17 - ~/Sites/website-next/node_modules/.bin/yarn
  npm: 6.14.15 - ~/.nvm/versions/node/v14.18.3/bin/npm
Browsers:
  Chromium: 98.0.4758.80
  Firefox: 97.0
npmPackages:
  vitepress: ^0.21.6 => 0.21.6

Additional context

I already proposed a bug fix: #517

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@wynksaiddestroy wynksaiddestroy added the bug: pending triage Maybe a bug, waiting for confirmation label Feb 15, 2022
@wynksaiddestroy wynksaiddestroy changed the title Can't add a non-javascript style tag to the head Can't add a non-javascript script tag to the head Feb 15, 2022
fi3ework added a commit to fi3ework/vitepress that referenced this issue Feb 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: pending triage Maybe a bug, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

1 participant