docs/build.js
function compileTemplates() {
  const mainHtml = fs.readFileSync(path.resolve(docsDir, 'src/template.html'), {
    encoding: 'utf8',
  });
  const mainTemplate = Handlebars.compile(mainHtml);

  function createPage(fileName, tab, content) {
    const html = mainTemplate({
      tabs: [{
        title: 'Get started',
        url: 'get-started.html',
        selected: tab === 'get-started',
      }, {
        title: 'Components',
        url: 'components.html',
        selected: tab === 'components',
      }],
      content,
      luiVersion: LUI_VERSION,
    });
    fileUtil.writeFile(path.resolve(docsDir, 'dist', fileName), html);
  }

  function createIndexPage() {
    const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/index.html'), {
      encoding: 'utf8',
    });
    const template = Handlebars.compile(content);
    const html = template();
    return createPage('index.html', 'index', html);
  }

  function createGetStartedPage() {
    const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/get-started.html'), {
      encoding: 'utf8',
    });
    const template = Handlebars.compile(content);
    const html = template({
      luiVersion: LUI_VERSION,
    });
    return createPage('get-started.html', 'get-started', html);
  }

  function createComponentPage(templateName, template, tab, content) {
    return createPage(templateName, tab, template({
      content,
      sections: sections.map(section => ({
        name: section.name,
        pages: section.pages.map(page => ({
          name: page.name,
          template: page.template,
          selected: page.template === templateName,
        })),
      })),
    }));
  }

  function createComponentPages() {
    const componentHtml = fs.readFileSync(path.resolve(docsDir, 'src/component-template.html'), {
      encoding: 'utf8',
    });
    const componentTemplate = Handlebars.compile(componentHtml);

    sections.forEach((section) => {
      section.pages.forEach((page) => {
        const file = `src/pages/${page.template}`;
        const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
          encoding: 'utf8',
        });

        const template = Handlebars.compile(fileContent);
        const html = template();

        createComponentPage(page.template, componentTemplate, 'components', html);
      });
    });

    const file = 'src/pages/components.html';
    const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
      encoding: 'utf8',
    });
    createComponentPage('components.html', componentTemplate, 'components', fileContent);
  }

  createIndexPage();
  createGetStartedPage();
  createComponentPages();
}
function compileTemplates() {
  const mainHtml = fs.readFileSync(path.resolve(docsDir, 'src/template.html'), {
    encoding: 'utf8',
  });
  const mainTemplate = Handlebars.compile(mainHtml);

  function createPage(fileName, tab, content) {
    const html = mainTemplate({
      tabs: [{
        title: 'Get started',
        url: 'get-started.html',
        selected: tab === 'get-started',
      }, {
        title: 'Components',
        url: 'components.html',
        selected: tab === 'components',
      }],
      content,
      luiVersion: LUI_VERSION,
    });
    fileUtil.writeFile(path.resolve(docsDir, 'dist', fileName), html);
  }

  function createIndexPage() {
    const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/index.html'), {
      encoding: 'utf8',
    });
    const template = Handlebars.compile(content);
    const html = template();
    return createPage('index.html', 'index', html);
  }

  function createGetStartedPage() {
    const content = fs.readFileSync(path.resolve(docsDir, 'src/pages/get-started.html'), {
      encoding: 'utf8',
    });
    const template = Handlebars.compile(content);
    const html = template({
      luiVersion: LUI_VERSION,
    });
    return createPage('get-started.html', 'get-started', html);
  }

  function createComponentPage(templateName, template, tab, content) {
    return createPage(templateName, tab, template({
      content,
      sections: sections.map(section => ({
        name: section.name,
        pages: section.pages.map(page => ({
          name: page.name,
          template: page.template,
          selected: page.template === templateName,
        })),
      })),
    }));
  }

  function createComponentPages() {
    const componentHtml = fs.readFileSync(path.resolve(docsDir, 'src/component-template.html'), {
      encoding: 'utf8',
    });
    const componentTemplate = Handlebars.compile(componentHtml);

    sections.forEach((section) => {
      section.pages.forEach((page) => {
        const file = `src/pages/${page.template}`;
        const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
          encoding: 'utf8',
        });

        const template = Handlebars.compile(fileContent);
        const html = template();

        createComponentPage(page.template, componentTemplate, 'components', html);
      });
    });

    const file = 'src/pages/components.html';
    const fileContent = fs.readFileSync(path.resolve(docsDir, file), {
      encoding: 'utf8',
    });
    createComponentPage('components.html', componentTemplate, 'components', fileContent);
  }

  createIndexPage();
  createGetStartedPage();
  createComponentPages();
}
function compileTemplates ( ) { const mainHtml = fs . readFileSync ( path . resolve ( docsDir , 'src/template.html' ) , { encoding : 'utf8' , } ) ; const mainTemplate = Handlebars . compile ( mainHtml ) ; function createPage ( fileName , tab , content ) { const html = mainTemplate ( { tabs : [ { title : 'Get started' , url : 'get-started.html' , selected : tab === 'get-started' , } , { title : 'Components' , url : 'components.html' , selected : tab === 'components' , } ] , content , luiVersion : LUI_VERSION , } ) ; fileUtil . writeFile ( path . resolve ( docsDir , 'dist' , fileName ) , html ) ; } function createIndexPage ( ) { const content = fs . readFileSync ( path . resolve ( docsDir , 'src/pages/index.html' ) , { encoding : 'utf8' , } ) ; const template = Handlebars . compile ( content ) ; const html = template ( ) ; return createPage ( 'index.html' , 'index' , html ) ; } function createGetStartedPage ( ) { const content = fs . readFileSync ( path . resolve ( docsDir , 'src/pages/get-started.html' ) , { encoding : 'utf8' , } ) ; const template = Handlebars . compile ( content ) ; const html = template ( { luiVersion : LUI_VERSION , } ) ; return createPage ( 'get-started.html' , 'get-started' , html ) ; } function createComponentPage ( templateName , template , tab , content ) { return createPage ( templateName , tab , template ( { content , sections : sections . map ( section => ( { name : section . name , pages : section . pages . map ( page => ( { name : page . name , template : page . template , selected : page . template === templateName , } ) ) , } ) ) , } ) ) ; } function createComponentPages ( ) { const componentHtml = fs . readFileSync ( path . resolve ( docsDir , 'src/component-template.html' ) , { encoding : 'utf8' , } ) ; const componentTemplate = Handlebars . compile ( componentHtml ) ; sections . forEach ( ( section ) => { section . pages . forEach ( ( page ) => { const file = ` ${ page . template } ` ; const fileContent = fs . readFileSync ( path . resolve ( docsDir , file ) , { encoding : 'utf8' , } ) ; const template = Handlebars . compile ( fileContent ) ; const html = template ( ) ; createComponentPage ( page . template , componentTemplate , 'components' , html ) ; } ) ; } ) ; const file = 'src/pages/components.html' ; const fileContent = fs . readFileSync ( path . resolve ( docsDir , file ) , { encoding : 'utf8' , } ) ; createComponentPage ( 'components.html' , componentTemplate , 'components' , fileContent ) ; } createIndexPage ( ) ; createGetStartedPage ( ) ; createComponentPages ( ) ; }
Compile Handlebars templates
Compile Handlebars templates