Skip to content

Commit e26b797

Browse files
committed
Working import and export of .md files
1 parent 8aa8a97 commit e26b797

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/clients/github.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function buildGistFromProject(project) {
108108
language: 'JavaScript',
109109
};
110110
}
111+
if (trim(project.readme)) {
112+
files['README.md'] = {
113+
content: project.readme,
114+
language: 'Markdown',
115+
};
116+
}
111117
if (project.enabledLibraries.length || project.hiddenUIComponents.length) {
112118
files['popcode.json'] = {
113119
content: createPopcodeJson(project),

src/records/Project.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ export default class Project extends Record({
1414
enabledLibraries: new Set(),
1515
hiddenUIComponents: new Set(),
1616
updatedAt: null,
17+
readme: '',
1718
}) {
1819
static fromJS({
1920
projectKey = null,
2021
sources = {},
2122
enabledLibraries = [],
2223
hiddenUIComponents = [],
2324
updatedAt = null,
25+
readme = '',
2426
}) {
2527
return new Project({
2628
projectKey,
2729
sources: new Sources(sources),
2830
enabledLibraries: new Set(enabledLibraries),
2931
hiddenUIComponents: new Set(hiddenUIComponents),
3032
updatedAt,
33+
readme,
3134
});
3235
}
3336
}

src/reducers/projects.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function unhideComponent(state, projectKey, component, timestamp) {
2828
).setIn([projectKey, 'updatedAt'], timestamp);
2929
}
3030

31+
function contentForLanguage(files, language) {
32+
return map(filter(files, {language}), 'content').join('\n\n');
33+
}
34+
3135
function importGist(state, projectKey, gistData) {
3236
const files = values(gistData.files);
3337
const popcodeJsonFile = find(files, {filename: 'popcode.json'});
@@ -39,12 +43,12 @@ function importGist(state, projectKey, gistData) {
3943
projectKey,
4044
sources: {
4145
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'),
46+
css: contentForLanguage(files, 'CSS'),
47+
javascript: contentForLanguage(files, 'JavaScript'),
4548
},
4649
enabledLibraries: popcodeJson.enabledLibraries || [],
4750
hiddenUIComponents: popcodeJson.hiddenUIComponents || [],
51+
readme: contentForLanguage(files, 'Markdown'),
4852
},
4953
);
5054
}

0 commit comments

Comments
 (0)