// Mobile // | //// Command line // | //
---|---|
// // | //
//
// joplin:/My notebook$ ls -n 12
// [ ] 8am conference call ☎
// [ ] Make vet appointment
// [ ] Go pick up parcel
// [ ] Pay flat rent 💸
// [X] Book ferry 🚢
// [X] Deploy Joplin app
// Open source stuff
// Swimming pool time table 🏊
// Grocery shopping list 📝
// Work itinerary
// Tuesday random note
// Vacation plans ☀
//
// |
//
${tocHtml_}
`;
return tocHtml_;
}
function renderMdToHtml(md, targetPath, templateParams) {
// Remove the header because it's going to be added back as HTML
md = md.replace(/# Joplin\n/, '');
templateParams.baseUrl = 'https://joplinapp.org';
templateParams.imageBaseUrl = `${templateParams.baseUrl}/images`;
templateParams.tocHtml = tocHtml();
const title = [];
if (!templateParams.title) {
title.push('Joplin - an open source note taking and to-do application with synchronisation capabilities');
} else {
title.push(templateParams.title);
title.push('Joplin');
}
md = replaceGitHubByJoplinAppLinks(md);
templateParams.pageTitle = title.join(' | ');
const html = markdownToHtml(md, templateParams);
const folderPath = dirname(targetPath);
fs.mkdirpSync(folderPath);
fs.writeFileSync(targetPath, html);
}
async function readmeFileTitle(sourcePath) {
const md = await fs.readFile(sourcePath, 'utf8');
const r = md.match(/(^|\n)# (.*)/);
if (!r) {
throw new Error('Could not determine title for Markdown file: ', sourcePath);
} else {
return r[2];
}
}
function renderFileToHtml(sourcePath, targetPath, templateParams) {
const md = fs.readFileSync(sourcePath, 'utf8');
return renderMdToHtml(md, targetPath, templateParams);
}
function makeHomePageMd() {
let md = fs.readFileSync(`${rootDir}/README.md`, 'utf8');
md = md.replace(tocRegex_, '');
// HACK: GitHub needs the \| or the inline code won't be displayed correctly inside the table,
// while MarkdownIt doesn't and will in fact display the \. So we remove it here.
md = md.replace(/\\\| bash/g, '| bash');
return md;
}
async function main() {
await fs.remove(`${rootDir}/docs`);
await fs.copy(`${rootDir}/Modules/WebsiteAssets`, `${rootDir}/docs`);
renderMdToHtml(makeHomePageMd(), `${rootDir}/docs/index.html`, { sourceMarkdownFile: 'README.md' });
const mdFiles = glob.sync(`${rootDir}/readme/**/*.md`, {
ignore: [
// '**/node_modules/**',
],
}).map(f => f.substr(rootDir.length + 1));
const sources = [];
for (const mdFile of mdFiles) {
const title = await readmeFileTitle(`${rootDir}/${mdFile}`);
const targetFilePath = `${mdFile.replace(/\.md/, '').replace(/readme\//, 'docs/')}/index.html`;
sources.push([mdFile, targetFilePath, { title: title }]);
}
const path = require('path');
for (const source of sources) {
source[2].sourceMarkdownFile = source[0];
source[2].sourceMarkdownName = path.basename(source[0], path.extname(source[0]));
renderFileToHtml(`${rootDir}/${source[0]}`, `${rootDir}/${source[1]}`, source[2]);
}
}
main().catch((error) => {
console.error(error);
});