Last active
February 9, 2022 13:39
-
-
Save brillout/6b91504fe744e38ba8a0f23030bbc120 to your computer and use it in GitHub Desktop.
vps-ssg-demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// travis-framework.config.ts | |
// Code written by user | |
export default { | |
graphqlServer: { | |
url: 'graphql.shopify.dev' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- pages/posts.vue --> | |
<!-- Code written by user --> | |
<template> | |
<ul> | |
<li v-for="post in posts" :key="post.id">{{ post.title }}</li> | |
</ul> | |
</template> | |
<script lang="ts"> | |
const pageProps = ['posts'] | |
export default { props: pageProps } | |
</script> | |
<script lang="ts" setup> | |
export const graphqlQquery = `query { posts { id, title, handle } }` | |
import { useData } from 'travis-framework' | |
const { data } = useData() | |
const posts = computed(() => data.posts) | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node_modules/travis-framework/renderer/_default.page.server.ts | |
// Code written by us | |
export async function onBeforeRender(pageContext) { | |
const { graphqlQuery } = pageContext.pageExports | |
const data = await runGraphqlQuery(graphqlQuery) | |
return { | |
pageContext: { | |
data | |
} | |
} | |
} | |
async function runGraphqlQuery() { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node_modules/travis-framework/useData.ts | |
// Code written by us | |
// Hook providing `pageContext.data` | |
export function useData() { | |
/* Similar implementation than | |
https://github.com/brillout/vite-plugin-ssr/blob/master/boilerplates/boilerplate-vue-ts/renderer/usePageContext.ts | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment