const fs = require('fs-extra'); const dirname = require('path').dirname; const marked = require('marked'); const Mustache = require('mustache'); const headerHtml = ` Joplin - an open source note taking and to-do application with synchronisation capabilities

oplin

An open source note taking and to-do application with synchronisation capabilities.

{{{tocHtml}}} `; const footerHtml = ` `; // const screenshotHtml = ` // // // // // // // // // //
// 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 ☀
// 			
//
// `; const scriptHtml = ` `; const rootDir = dirname(__dirname); function markdownToHtml(md) { const renderer = new marked.Renderer(); let output = marked(md, { gfm: true, break: true, renderer: renderer, }); return headerHtml + output + scriptHtml + footerHtml; } let tocMd_ = null; let tocHtml_ = null; const tocRegex_ = /([^]*)/ function tocMd() { if (tocMd_) return tocMd_; const md = fs.readFileSync(rootDir + '/README.md', 'utf8'); const toc = md.match(tocRegex_); tocMd_ = toc[1]; return tocMd_; } function tocHtml() { if (tocHtml_) return tocHtml_; const MarkdownIt = require('markdown-it'); const markdownIt = new MarkdownIt(); let md = tocMd(); md = md.replace(/# Table of contents/, ''); md = md.replace(/https:\/\/github.com\/laurent22\/joplin\/blob\/master\/readme\/(.*)\.md/g, 'https://joplin.cozic.net/$1'); tocHtml_ = markdownIt.render(md); tocHtml_ = '
' + tocHtml_ + '
'; return tocHtml_; } function renderMdToHtml(md, targetPath, params) { params.baseUrl = 'https://joplin.cozic.net'; params.imageBaseUrl = params.baseUrl + '/images'; params.tocHtml = tocHtml(); const html = Mustache.render(markdownToHtml(md), params); fs.writeFileSync(targetPath, html); } function renderFileToHtml(sourcePath, targetPath, params) { const md = fs.readFileSync(sourcePath, 'utf8'); return renderMdToHtml(md, targetPath, params); } function makeHomePageMd() { let md = fs.readFileSync(rootDir + '/README.md', 'utf8'); md = md.replace(tocRegex_, ''); // Remove the header because it's going to be added back as HTML md = md.replace(/# Joplin/, ''); return md; } async function main() { tocMd(); // renderFileToHtml(rootDir + '/README.md', rootDir + '/docs/index.html', { // selectedHome: 'selected', // }); // renderFileToHtml(rootDir + '/readme/terminal.md', rootDir + '/docs/terminal/index.html', { // selectedTerminal: 'selected', // }); // renderFileToHtml(rootDir + '/readme/desktop.md', rootDir + '/docs/desktop/index.html', { // selectedDesktop: 'selected', // }); // let readmeMd = fs.readFileSync(rootDir + '/README.md', 'utf8'); renderMdToHtml(makeHomePageMd(), rootDir + '/docs/index.html', {}); // renderFileToHtml(rootDir + '/README.md', rootDir + '/docs/index.html', {}); renderFileToHtml(rootDir + '/readme/terminal.md', rootDir + '/docs/terminal/index.html', {}); renderFileToHtml(rootDir + '/readme/desktop.md', rootDir + '/docs/desktop/index.html', {}); renderFileToHtml(rootDir + '/readme/mobile.md', rootDir + '/docs/mobile/index.html', {}); renderFileToHtml(rootDir + '/readme/e2ee.md', rootDir + '/docs/e2ee/index.html', {}); renderFileToHtml(rootDir + '/readme/spec.md', rootDir + '/docs/spec/index.html', {}); renderFileToHtml(rootDir + '/readme/stats.md', rootDir + '/docs/stats/index.html', {}); renderFileToHtml(rootDir + '/readme/changelog.md', rootDir + '/docs/changelog/index.html', {}); renderFileToHtml(rootDir + '/readme/donate.md', rootDir + '/docs/donate/index.html', {}); } main().catch((error) => { console.error(error); });