saberland/saber

Error While Injecting Script Tag into Head #585

sno2 posted onGitHub

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


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

Try:

...
head() {
  return {
    title: '...',
    script: [{ src: 'script1' }, { src: 'script2' }]
  }
},
...
posted by krmax44 about 5 years ago

Fund this Issue

$0.00
Funded

Pull requests