2019-09-19 23:51:18 +02:00
|
|
|
require('app-module-path').addPath(`${__dirname}/../ReactNativeClient`);
|
2019-02-03 20:58:44 +02:00
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const dirname = require('path').dirname;
|
|
|
|
const { fileExtension, basename } = require('lib/path-utils.js');
|
|
|
|
const markdownUtils = require('lib/markdownUtils.js');
|
|
|
|
|
|
|
|
const rootDir = dirname(__dirname);
|
2019-09-19 23:51:18 +02:00
|
|
|
const welcomeDir = `${rootDir}/readme/welcome`;
|
2019-02-03 20:58:44 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
const createdDate = new Date('2018-06-22T12:00:00Z');
|
2019-02-23 17:47:29 +02:00
|
|
|
|
2019-02-03 22:19:17 +02:00
|
|
|
const itemMetadata_ = {
|
|
|
|
'1_welcome_to_joplin.md': {
|
|
|
|
id: '8a1556e382704160808e9a7bef7135d3',
|
2019-05-22 17:38:53 +02:00
|
|
|
// tags: 'markdown,organising',
|
2019-02-03 22:19:17 +02:00
|
|
|
},
|
|
|
|
'2_importing_and_exporting_notes.md': {
|
|
|
|
id: 'b863cbc514cb4cafbae8dd6a4fcad919',
|
2019-05-22 17:38:53 +02:00
|
|
|
// tags: 'importing,exporting',
|
2019-02-03 22:19:17 +02:00
|
|
|
},
|
|
|
|
'3_synchronising_your_notes.md': {
|
|
|
|
id: '25b656aac0564d1a91ab98295aa3cc58',
|
2019-05-22 17:38:53 +02:00
|
|
|
// tags: 'synchronising',
|
2019-02-03 22:19:17 +02:00
|
|
|
},
|
|
|
|
'4_tips.md': {
|
|
|
|
id: '2ee48f80889447429a3cccb04a466072',
|
2019-05-22 17:38:53 +02:00
|
|
|
// tags: 'attachment,search',
|
2019-02-03 22:19:17 +02:00
|
|
|
},
|
2020-03-06 01:36:28 +02:00
|
|
|
'5_privacy.md': {
|
|
|
|
id: '5ec2e7505ec2e7505ec2e7505ec2e750',
|
|
|
|
// tags: 'privacy',
|
|
|
|
},
|
2019-02-03 22:19:17 +02:00
|
|
|
'AllClients.png': { id: '5c05172554194f95b60971f6d577cc1a' },
|
|
|
|
'SubNotebooks.png': { id: '3a851ab0c0e849b7bc9e8cd5c4feb34a' },
|
|
|
|
'folder_Welcome': { id: '9bb5d498aba74cc6a047cfdc841e82a1' },
|
2019-02-08 01:17:58 +02:00
|
|
|
'WebClipper.png': { id: '30cf9214f5054c4da3b23eed7211a6e0' },
|
2019-02-23 17:47:29 +02:00
|
|
|
|
|
|
|
'markdown': { id: '79cc5ef0f6c24f138033ce48928c2cba' },
|
|
|
|
'organising': { id: 'c83be0495b5d4f1ab655c5c6dfed6804' },
|
|
|
|
'importing': { id: 'b5adb734bb0044f2a572a729266b610d' },
|
|
|
|
'exporting': { id: 'bed34e2e3ab74b45af8ba473a05f56f9' },
|
|
|
|
'synchronising': { id: 'c442fa3b2b2b4389b160c15eb73f35c9' },
|
|
|
|
'attachment': { id: '22c94167b6e94a92b560ffc31a7f4b1d' },
|
|
|
|
'search': { id: '83eae47427df4805905103d4a91727b7' },
|
2019-02-03 22:19:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function itemMetadata(path) {
|
2019-02-03 20:58:44 +02:00
|
|
|
const f = basename(path);
|
2019-02-03 22:19:17 +02:00
|
|
|
const md = itemMetadata_[f];
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!md) throw new Error(`No metadata for: ${path}`);
|
2019-02-03 22:19:17 +02:00
|
|
|
return md;
|
|
|
|
}
|
|
|
|
|
|
|
|
function noteTags(path) {
|
|
|
|
const md = itemMetadata(path);
|
2019-05-22 17:38:53 +02:00
|
|
|
if (!md.tags) return [];
|
2019-02-03 22:19:17 +02:00
|
|
|
return md.tags.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemIdFromPath(path) {
|
|
|
|
const md = itemMetadata(path);
|
2019-09-19 23:51:18 +02:00
|
|
|
if (!md.id) throw new Error(`No ID for ${path}`);
|
2019-02-03 22:19:17 +02:00
|
|
|
return md.id;
|
2019-02-03 20:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function fileToBase64(filePath) {
|
|
|
|
const content = fs.readFileSync(filePath);
|
|
|
|
return Buffer.from(content).toString('base64');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function parseNoteFile(filePath) {
|
|
|
|
const n = basename(filePath);
|
|
|
|
const number = n.split('_')[0];
|
|
|
|
const body = fs.readFileSync(filePath, 'utf8');
|
2019-09-19 23:51:18 +02:00
|
|
|
const title = `${number}. ${body.split('\n')[0].substr(2)}`;
|
2019-02-03 20:58:44 +02:00
|
|
|
const resources = {};
|
|
|
|
|
|
|
|
const imagePaths = markdownUtils.extractImageUrls(body);
|
|
|
|
|
|
|
|
for (let i = 0; i < imagePaths.length; i++) {
|
|
|
|
const imagePath = imagePaths[i];
|
2019-09-19 23:51:18 +02:00
|
|
|
const fullImagePath = `${welcomeDir}/${imagePath}`;
|
2019-02-03 20:58:44 +02:00
|
|
|
const base64 = fileToBase64(fullImagePath);
|
|
|
|
|
|
|
|
resources[imagePath] = {
|
|
|
|
id: itemIdFromPath(fullImagePath),
|
|
|
|
body: base64,
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2019-02-03 20:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: itemIdFromPath(filePath),
|
|
|
|
title: title,
|
|
|
|
body: body,
|
2019-02-03 22:19:17 +02:00
|
|
|
tags: noteTags(filePath),
|
2019-02-03 20:58:44 +02:00
|
|
|
resources: resources,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const notes = [];
|
2019-02-23 17:47:29 +02:00
|
|
|
const tagIdsToTag = {};
|
2019-02-03 20:58:44 +02:00
|
|
|
const filenames = fs.readdirSync(welcomeDir);
|
|
|
|
|
|
|
|
const rootFolder = {
|
|
|
|
id: itemIdFromPath('folder_Welcome'),
|
2019-02-08 01:27:50 +02:00
|
|
|
title: 'Welcome!',
|
2019-02-03 20:58:44 +02:00
|
|
|
};
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-02-03 20:58:44 +02:00
|
|
|
for (let i = 0; i < filenames.length; i++) {
|
|
|
|
const f = filenames[i];
|
|
|
|
const ext = fileExtension(f);
|
|
|
|
|
|
|
|
if (ext === 'md') {
|
2019-09-19 23:51:18 +02:00
|
|
|
const note = await parseNoteFile(`${welcomeDir}/${f}`);
|
2019-02-03 20:58:44 +02:00
|
|
|
note.parent_id = rootFolder.id;
|
2019-02-23 17:47:29 +02:00
|
|
|
|
|
|
|
for (let j = 0; j < note.tags.length; j++) {
|
|
|
|
const tagTitle = note.tags[j];
|
|
|
|
const tagId = itemIdFromPath(tagTitle);
|
|
|
|
if (!tagIdsToTag[tagId]) tagIdsToTag[tagId] = {
|
|
|
|
id: tagId,
|
|
|
|
title: tagTitle,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:58:44 +02:00
|
|
|
notes.push(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 17:47:29 +02:00
|
|
|
const tags = [];
|
|
|
|
for (let n in tagIdsToTag) {
|
|
|
|
if (!tagIdsToTag.hasOwnProperty(n)) continue;
|
|
|
|
tags.push(tagIdsToTag[n]);
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:58:44 +02:00
|
|
|
const folders = [];
|
|
|
|
folders.push(rootFolder);
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
const content = { notes: notes, folders: folders, tags: tags, timestamp: createdDate.getTime() };
|
2019-02-03 20:58:44 +02:00
|
|
|
const jsonContent = JSON.stringify(content, null, 4);
|
2019-09-19 23:51:18 +02:00
|
|
|
const jsContent = `module.exports = ${jsonContent}`;
|
|
|
|
fs.writeFileSync(`${rootDir}/ReactNativeClient/lib/welcomeAssets.js`, jsContent, { encoding: 'utf8' });
|
2019-02-03 20:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error(error);
|
2019-02-03 22:19:17 +02:00
|
|
|
process.exit(1);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|