File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,32 @@ async function getGist({ id, version }) {
52
52
return { id, version, files } ;
53
53
}
54
54
55
+ const placeholderValues = {
56
+ js : '// your query' ,
57
+ html : '<!-- your markup -->' ,
58
+ json : '{}' ,
59
+ } ;
60
+
61
+ function ensureContent ( files ) {
62
+ for ( let name of Object . keys ( files ) ) {
63
+ if ( files [ name ] . content . length === 0 ) {
64
+ files [ name ] . content = placeholderValues [ name . split ( '.' ) . pop ( ) ] || 'o.O' ;
65
+ }
66
+ }
67
+
68
+ return files ;
69
+ }
70
+
55
71
/**
56
72
* @param id {string}
57
73
* @param description {string}
58
74
* @param files { object.<string, { content: string }> }
59
75
* @returns {Promise<{id: *, version: *, url: string}> }
60
76
*/
61
77
async function saveGist ( { id, description, files } ) {
78
+ // we can't save empty files to github gists. So we'll make sure they ain't empty.
79
+ ensureContent ( files ) ;
80
+
62
81
// if the id is given, we assume an update and thereby just correct the method.
63
82
const response = await fetch ( [ ENDPOINT , id ] . filter ( Boolean ) . join ( '/' ) , {
64
83
method : id ? 'PATCH' : 'POST' ,
You can’t perform that action at this time.
0 commit comments