Skip to content

Instantly share code, notes, and snippets.

@SebbeJohansson
Created August 30, 2022 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebbeJohansson/b8c966658e78b3d4b5b48adaa6ba8d42 to your computer and use it in GitHub Desktop.
Save SebbeJohansson/b8c966658e78b3d4b5b48adaa6ba8d42 to your computer and use it in GitHub Desktop.
Nuxt3 Github Gist Embed component
<script setup lang="ts">
const props = defineProps({
gistId: {
type: String,
required: true,
},
file: {
type: String,
required: false,
default: '',
},
});
const gistUrl: string = 'https://gist.github.com/';
const gistErr: boolean = false;
const { data: result } = await useAsyncData(
`gist-${props.gistId}-${props.file}`,
() => {
const params = props.file.length > 0 ? `?file=${props.file}` : '';
return $fetch(`${gistUrl}${props.gistId}.json${params}`);
},
);
</script>
<template>
<div>
<div v-if="gistErr">
<img
id="notFound"
height="100%"
width="100%"
src="https://user-images.githubusercontent.com/883233/102043641-d4817580-3d89-11eb-885d-2786373932d4.png"
alt="404"
>
</div>
<div v-else v-html="result.div" />
</div>
</template>
<style scoped>
@import url("https://github.githubassets.com/assets/gist-embed-4ac6018bcc05457cde2f66d2e7299d11.css");
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
</style>
@SebbeJohansson
Copy link
Author

SebbeJohansson commented Aug 30, 2022

This was made using vue-embed-gist's VueGist.vue as a base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment