const fs = require('fs-extra'); const dirname = require('path').dirname; const Mustache = require('mustache'); const headerHtml = ` {{pageTitle}}

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 MarkdownIt = require('markdown-it'); const markdownIt = new MarkdownIt({ breaks: true, linkify: true, html: true, }); markdownIt.core.ruler.push('checkbox', state => { const tokens = state.tokens; const Token = state.Token; const doneNames = []; const headingTextToAnchorName = (text, doneNames) => { const allowed = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let lastWasDash = true; let output = ''; for (let i = 0; i < text.length; i++) { const c = text[i]; if (allowed.indexOf(c) < 0) { if (lastWasDash) continue; lastWasDash = true; output += '-'; } else { lastWasDash = false; output += c; } } output = output.toLowerCase(); while (output.length && output[output.length - 1] === '-') { output = output.substr(0, output.length - 1); } let temp = output; let index = 1; while (doneNames.indexOf(temp) >= 0) { temp = output + '-' + index; index++; } output = temp; return output; } const createAnchorTokens = anchorName => { const output = []; { const token = new Token('heading_anchor_open', 'a', 1); token.attrs = [ ['name', anchorName], ['href', '#' + anchorName], ['class', 'heading-anchor'], ]; output.push(token); } { const token = new Token('text', '', 0); token.content = '🔗'; output.push(token); } { const token = new Token('heading_anchor_close', 'a', -1); output.push(token); } return output; } let insideHeading = false; let processedFirstInline = false; for (let i = 0; i < tokens.length; i++) { const token = tokens[i]; if (token.type === 'heading_open') { insideHeading = true; processedFirstInline = false; continue; } if (token.type === 'heading_close') { insideHeading = false; processedFirstInline = false; continue; } if (insideHeading && token.type === 'inline') { processedFirstInline = true; const anchorName = headingTextToAnchorName(token.content, doneNames); doneNames.push(anchorName); const anchorTokens = createAnchorTokens(anchorName); token.children = anchorTokens.concat(token.children); } } }); return headerHtml + markdownIt.render(md) + 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://joplinapp.org/$1'); tocHtml_ = markdownIt.render(md); tocHtml_ = '
' + tocHtml_ + '
'; return tocHtml_; } function renderMdToHtml(md, targetPath, params) { // Remove the header because it's going to be added back as HTML md = md.replace(/# Joplin\n/, ''); params.baseUrl = 'https://joplinapp.org'; params.imageBaseUrl = params.baseUrl + '/images'; params.tocHtml = tocHtml(); const title = []; if (!params.title) { title.push('Joplin - an open source note taking and to-do application with synchronisation capabilities'); } else { title.push(params.title); title.push('Joplin'); } params.pageTitle = title.join(' | '); 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_, ''); return md; } async function main() { tocMd(); renderMdToHtml(makeHomePageMd(), rootDir + '/docs/index.html', {}); renderFileToHtml(rootDir + '/readme/changelog.md', rootDir + '/docs/changelog/index.html', { title: 'Changelog (Desktop App)' }); renderFileToHtml(rootDir + '/readme/changelog_cli.md', rootDir + '/docs/changelog_cli/index.html', { title: 'Changelog (CLI App)' }); renderFileToHtml(rootDir + '/readme/clipper.md', rootDir + '/docs/clipper/index.html', { title: 'Web Clipper' }); renderFileToHtml(rootDir + '/readme/debugging.md', rootDir + '/docs/debugging/index.html', { title: 'Debugging' }); renderFileToHtml(rootDir + '/readme/desktop.md', rootDir + '/docs/desktop/index.html', { title: 'Desktop Application' }); renderFileToHtml(rootDir + '/readme/donate.md', rootDir + '/docs/donate/index.html', { title: 'Donate' }); renderFileToHtml(rootDir + '/readme/e2ee.md', rootDir + '/docs/e2ee/index.html', { title: 'End-To-End Encryption' }); renderFileToHtml(rootDir + '/readme/faq.md', rootDir + '/docs/faq/index.html', { title: 'FAQ' }); renderFileToHtml(rootDir + '/readme/mobile.md', rootDir + '/docs/mobile/index.html', { title: 'Mobile Application' }); renderFileToHtml(rootDir + '/readme/spec.md', rootDir + '/docs/spec/index.html', { title: 'Specifications' }); renderFileToHtml(rootDir + '/readme/stats.md', rootDir + '/docs/stats/index.html', { title: 'Statistics' }); renderFileToHtml(rootDir + '/readme/terminal.md', rootDir + '/docs/terminal/index.html', { title: 'Terminal Application' }); renderFileToHtml(rootDir + '/readme/api.md', rootDir + '/docs/api/index.html', { title: 'REST API' }); renderFileToHtml(rootDir + '/readme/prereleases.md', rootDir + '/docs/prereleases/index.html', { title: 'Pre-releases' }); } main().catch((error) => { console.error(error); });