SandDance/scripts
Dan Marshall 45167abf8b
Publish compare (#665)
* add publish script

* logging optional

* don't use lerna.json
2023-06-26 15:42:18 -07:00
..
copy_inuitcss.js add sass-mq to website 2019-04-15 14:15:02 -07:00
publish.mjs Publish compare (#665) 2023-06-26 15:42:18 -07:00
readme.js Refactor data-inference as package (#661) 2023-06-22 16:44:44 -07:00
vega-version.mjs Refactor data-inference as package (#661) 2023-06-22 16:44:44 -07:00
version.js Added version & system info (#83) 2019-09-03 17:17:17 -07:00

readme.js

const fs = require('fs');
const path = require('path');
const { marked } = require('marked');
const tree = require('../docs/_data/tree.json');

function liquid(layout, title) {
    return `---\nlayout: ${layout}\ntitle: '${title}'\n---\n\n`;
}

function convertHomePage() {
    const readmeMarkdown = fs.readFileSync('./README.md', 'UTF8');
    const html = liquid('page', 'Home') + rewriteURLs(marked(readmeMarkdown));
    fs.writeFileSync('./docs/index.html', html, 'UTF8');
}

const map = {
    'https://microsoft.github.io': '',
    'dev.md': 'https://github.com/Microsoft/SandDance/blob/master/dev.md',
    'packages/sanddance/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='sanddance')[0].url}/`,
    'packages/sanddance-specs/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='sanddance-specs')[0].url}/`,
    'packages/sanddance-react/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='sanddance-react')[0].url}/`,
    'packages/sanddance-explorer/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='sanddance-explorer')[0].url}/`,
    'packages/sanddance-embed/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='sanddance-embed')[0].url}/`,
    'packages/vega-deck.gl/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='vega-deck.gl')[0].url}/`,
    'packages/vega-morphcharts/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='vega-morphcharts')[0].url}/`,
    'packages/data-inference/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='data-inference')[0].url}/`,
    'packages/chart-types/README.md': `/SandDance${tree.Components.filter(c=>c.tree==='chart-types')[0].url}/`,
};

//https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
function escapeRegExp(str) {
    return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

function rewriteURLs(html) {
    for (var key in map) {
        var value = map[key];
        var re = new RegExp(escapeRegExp(key), 'g');
        html = html.replace(re, value);
    }
    return html;
}

convertHomePage();