Skip to content

Programmatic site generation #118

Answered by ElMassimo
gilesbutler asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Giles! I'll provide a quick answer now, if you share a repo with an example I can be more specific.

Where do you recommend we make the call so we can pass the json down to each page before it gets rendered?

Although enhanceApp will be called every time the Vue app is created (standard practice when doing SSR is to create a fresh app for each render), you can leverage ES modules to ensure you fetch the data outside the hook, ensuring it runs only once.

A great place to do that is src/site.ts:

const data = await fetchSiteJSON()

export default {
  title: data.name, // Used by default to render meta tags and page titles
  ...data,
}

This data would be available as $site in templates, or s…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants