(gistId)
| 58 | * Load and convert gist files to playground format |
| 59 | */ |
| 60 | export const loadGist = async (gistId) => { |
| 61 | try { |
| 62 | console.log(`loading gist: ${gistId}`); |
| 63 | const response = await fetch(`${NETLIFY_BASE_URL}/github-get-gist?id=${gistId}`, { |
| 64 | method: 'GET', |
| 65 | headers: { |
| 66 | 'Content-Type': 'application/json' |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | if (!response.ok) { |
| 71 | throw new Error(`failed to load gist: ${response.status}`); |
| 72 | } |
| 73 | |
| 74 | const gist = await response.json(); |
| 75 | console.log(`gist loaded: ${gist.description}`, Object.keys(gist.files)); |
| 76 | |
| 77 | // convert gist files to playground format |
| 78 | const playgroundFiles = {}; |
| 79 | Object.keys(gist.files).forEach(filename => { |
| 80 | const gistFile = gist.files[filename]; |
| 81 | playgroundFiles[filename] = { |
| 82 | name: filename, |
| 83 | content: gistFile.content, |
| 84 | hidden: filename === 'playground-support.js' |
| 85 | }; |
| 86 | }); |
| 87 | |
| 88 | console.log('converted playground files:', Object.keys(playgroundFiles)); |
| 89 | return playgroundFiles; |
| 90 | } catch (error) { |
| 91 | console.error('failed to load gist:', error); |
| 92 | throw error; |
| 93 | } |
| 94 | }; |
no test coverage detected
searching dependent graphs…