Created
April 5, 2024 22:00
-
-
Save nickberens360/9f256a7541f7c93612ab23840135c9bf to your computer and use it in GitHub Desktop.
Loads the content of a GitHub Gist
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
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