@@ -4,6 +4,7 @@ import filter from 'lodash/filter';
44import find from 'lodash/find' ;
55import get from 'lodash/get' ;
66import map from 'lodash/map' ;
7+ import sortBy from 'lodash/sortBy' ;
78import values from 'lodash/values' ;
89
910import { Project } from '../records' ;
@@ -28,6 +29,14 @@ function unhideComponent(state, projectKey, component, timestamp) {
2829 ) . setIn ( [ projectKey , 'updatedAt' ] , timestamp ) ;
2930}
3031
32+ function contentForLanguage ( files , language ) {
33+ const filesForLanguage = sortBy (
34+ filter ( files , { language} ) ,
35+ file => file . filename ,
36+ ) ;
37+ return map ( filesForLanguage , 'content' ) . join ( '\n\n' ) ;
38+ }
39+
3140function importGist ( state , projectKey , gistData ) {
3241 const files = values ( gistData . files ) ;
3342 const popcodeJsonFile = find ( files , { filename : 'popcode.json' } ) ;
@@ -39,12 +48,12 @@ function importGist(state, projectKey, gistData) {
3948 projectKey,
4049 sources : {
4150 html : get ( find ( files , { language : 'HTML' } ) , 'content' , '' ) ,
42- css : map ( filter ( files , { language : 'CSS' } ) , 'content' ) . join ( '\n\n' ) ,
43- javascript : map ( filter ( files , { language : 'JavaScript' } ) , 'content' ) .
44- join ( '\n\n' ) ,
51+ css : contentForLanguage ( files , 'CSS' ) ,
52+ javascript : contentForLanguage ( files , 'JavaScript' ) ,
4553 } ,
4654 enabledLibraries : popcodeJson . enabledLibraries || [ ] ,
4755 hiddenUIComponents : popcodeJson . hiddenUIComponents || [ ] ,
56+ instructions : contentForLanguage ( files , 'Markdown' ) ,
4857 } ,
4958 ) ;
5059}
0 commit comments