Skip to content

Commit 83da7a9

Browse files
committed
Pull project title from project file metadata.
1 parent 77775ac commit 83da7a9

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/modules/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ function downloadCode(project) {
918918
// dialog box will happen at some point after this function is executed.
919919
// We also will never know if the save was truly successful, so we
920920
// operate as if it was.
921-
saveAs(blob, projectFilename + '.svg');
921+
saveAs(blob, `${projectFilename}.svg`);
922922

923923
// Save the project into localStorage with a timestamp - if the page is
924924
// simply refreshed, this will allow the project to be reloaded.

src/modules/project/project_io.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export const filestreamToProject = (projectName, rawCode) => {
110110
const projectDesc = getProjectDescriptionFromXML(rawCode);
111111
const projectModified = getProjectModifiedDateFromXML(rawCode, date);
112112
const projectBoardType = getProjectBoardTypeFromXML(rawCode);
113+
let projectNameString = getProjectTitleFromXML(rawCode);
114+
console.log(`Project Title: ${projectNameString}`);
115+
if (projectNameString === '') {
116+
projectNameString = projectName;
117+
}
113118

114119
// Project create date can be missing in some projects. Set it to the
115120
// last modify date as a last-ditch default
@@ -125,7 +130,7 @@ export const filestreamToProject = (projectName, rawCode) => {
125130
}
126131

127132
return new Project(
128-
projectName,
133+
projectNameString,
129134
decodeFromValidXml(projectDesc),
130135
tmpBoardType,
131136
ProjectTypes.PROPC,
@@ -181,6 +186,40 @@ function getProjectBoardTypeFromXML(xml) {
181186
}
182187

183188

189+
190+
/**
191+
* Retrieve the project board type from the raw project XML
192+
* @param {string} xml
193+
* @return {string}
194+
*/
195+
function getProjectTitleFromXML(xml) {
196+
const searchString = `transform="translate(-225,-53)">Title: `;
197+
const index = xml.indexOf(searchString);
198+
199+
if (index === -1) {
200+
return '';
201+
}
202+
203+
const title = xml.substring(
204+
(index + searchString.length),
205+
xml.indexOf('</text>', (index + searchString.length)));
206+
207+
if (! title) {
208+
return '';
209+
}
210+
211+
if (title.endsWith('.svg')) {
212+
return title.substr(0,title.length - 4);
213+
}
214+
215+
if (title.endsWith('.svge')) {
216+
return title.substr(0,title.length - 5);
217+
}
218+
219+
return title;
220+
221+
}
222+
184223
/**
185224
* Parse the xml string to locate and return the project created timestamp
186225
*

0 commit comments

Comments
 (0)