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

Error While Injecting Script Tag into Head #585

Closed
sno2 opened this issue Jan 12, 2020 · 1 comment
Closed

Error While Injecting Script Tag into Head #585

sno2 opened this issue Jan 12, 2020 · 1 comment

Comments

@sno2
Copy link

sno2 commented Jan 12, 2020

Error While Injecting Script Tag into Head

I am trying to manipulate the head of my website using the head attribute inside of the export default function on my post layout inside of my Saber Vue.js static site generated website (https://saber.land). Whenever I try to add in my script tag and the Adsense code using the head attribute, none of the main.js code is running. I know that an error is happening because the title of the website changes from the formatted one to the exact URL of the website. Here is my post.vue (layout) script tag code:

import 'prismjs/themes/prism-twilight.css'
import Navbar from '../components/Navbar.vue'
import Footer from '../components/Footer.vue'

export default {
    components: {
        Navbar,
        Footer
    },
    props: ['page'],
    head() {
        return {
            title: `${this.page.title} - ${this.$siteConfig.title}`
        }
    },
    methods: {
        formatDate(v) {
        const date = new Date(v)
        return `${date.getMonth()+1}/${date.getDate()}/${date.getFullYear()}`
        }
    },
    head: {
      script: [{
        "src": "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
        "async": "true",
        "data-ad-client": "ca-pub-1485901785138606"
      }],
      script: [{
        "src": "/main.js"
      }]
    }
}

View the stackoverflow version of this issue at this link https://stackoverflow.com/questions/59701037/error-while-adding-script-tag-into-saber-static-site-generator

@krmax44
Copy link
Contributor

krmax44 commented Jan 12, 2020

Your default export has the key head twice, which is probably causing the error.

Try:

...
head() {
  return {
    title: '...',
    script: [{ src: 'script1' }, { src: 'script2' }]
  }
},
...

@sno2 sno2 closed this as completed Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants