Hello, I am looking at your Jamstack new template Vue SSG
https://vue-ssg.jamstacks.net/
I like it a lot!
Looking at the blog posts example (using Markdown) and how the list of posts is also generated on publish.
Trying to get my head around this, and if it is possible if we were getting the posts from an API instead of Markdown files…
If I follow what you have done and try to adapt it:
In the page plugin, we can use dynamic routes using [id]
We can make an API call in vite-ssg
It shows some code like this:
// main.ts
import { ViteSSG } from 'vite-ssg'
import App from './App.vue'
export const createApp = ViteSSG(
App,
{ routes },
({ app, router, initialState }) => {
// ...
},
)
export async function includedRoutes(paths, routes) {
// Sensitive key is managed by Vite - this would not be available inside
// vite.config.js as it runs before the environment has been populated.
const apiClient = new MyApiClient(import.meta.env.MY_API_KEY)
return Promise.all(
routes.flatMap(async route => {
return route.name === 'Blog'
? (await apiClient.fetchBlogSlugs()).map(slug => `/blog/${slug}`)
: route.path
})
)
}
Of course the API call will NOT be from the api project but from an ANOTHER ServiceStack project
That seems possible so far.
But in the [Post].Vue or [Slug].Vue file, if we are doing an API call, it would NOT be done during the publish / generation of the HTML? or would vue-SSG do this magic?
Have you look at this when building your template? I cannot see anyone mentioning this.
I will eventually try to code it, but looking if someone already tried it or has some pointers.
Thank you