Skip to content

Commit ae4e4f9

Browse files
committed
support non-state gists
1 parent bea0933 commit ae4e4f9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,18 @@ <h2>Output:</h2>
158158
fetch(`https://api.github.com/gists/${parameters.get('gist')}`)
159159
.then((r) => r.json())
160160
.then((data) => {
161-
const state = JSON.parse(data.files['state.json'].content);
162-
mode.value = state.mode;
163-
features = new Set(state.features);
164-
const file = data.files[`code.${state.mode === 'script' ? 'js' : 'mjs'}`];
161+
let content;
162+
if (data.files['state.json']) {
163+
const state = JSON.parse(data.files['state.json'].content);
164+
mode.value = state.mode;
165+
features = new Set(state.features);
166+
content = data.files[`code.${state.mode === 'script' ? 'js' : 'mjs'}`].content;
167+
} else {
168+
const fileName = Object.keys(data.files)[0];
169+
content = data.files[fileName].content;
170+
}
165171
respawn();
166-
editor.setValue(file.content);
172+
editor.setValue(content);
167173
});
168174
} else {
169175
editor.setValue('print(\'Hello, World!\');');

0 commit comments

Comments
 (0)