Skip to content

Instantly share code, notes, and snippets.

@nickberens360
Created April 5, 2024 22:00
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 nickberens360/9f256a7541f7c93612ab23840135c9bf to your computer and use it in GitHub Desktop.
Save nickberens360/9f256a7541f7c93612ab23840135c9bf to your computer and use it in GitHub Desktop.
Loads the content of a GitHub Gist
const loadContent = {
gistId: '',
gistFile: '',
contentElementId: '',
content: '',
getServerSideProps: async function() {
const response = await fetch(`https://api.github.com/gists/${this.gistId}`);
console.log(response)
return await response.json();
},
renderContent: function() {
document.getElementById(this.contentElementId).innerHTML = this.content;
},
init: async function() {
try {
const data = await this.getServerSideProps();
this.content = data.files[this.gistFile].content;
this.renderContent();
} catch (error) {
console.error('Error initializing API:', error);
throw error;
}
},
};
export default loadContent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment