def generate_html(dirname, outdir, title='images'):
    if (not os.path.exists(outdir)):
        os.makedirs(outdir)
    doc = document(title=title)
    with doc.head:
        tags.style(style)
    with doc:
        with tags.ul(id='myUL'):
            for category in os.listdir(dirname):
                tags.li(tags.a(category, href=category))
    with open(os.path.join(outdir, 'index.html'), 'w') as f:
        f.write(doc.render())
    pbar1 = tqdm(os.listdir(dirname), dynamic_ncols=False)
    for category in pbar1:
        pbar1.set_description(category)
        if (not os.path.exists(os.path.join(outdir, category))):
            os.makedirs(os.path.join(outdir, category))
        subdoc = document(title=category)
        with subdoc.head:
            tags.style(style)
        with subdoc:
            tags.a('back', href='..')
            with tags.ul(id='myUL'):
                for subcat in os.listdir(os.path.join(dirname, category)):
                    tags.li(tags.a(subcat, href=subcat))
        with open(os.path.join(outdir, category, 'index.html'), 'w') as f:
            f.write(subdoc.render())
        pbar2 = tqdm(os.listdir(os.path.join(dirname, category)), dynamic_ncols=False)
        for subcat in pbar2:
            pbar2.set_description(subcat)
            if (not os.path.exists(os.path.join(outdir, category, subcat))):
                os.makedirs(os.path.join(outdir, category, subcat))
            ssubdoc = document(title=subcat)
            with ssubdoc.head:
                tags.style(style2)
            imgs = []
            pbar3 = tqdm(os.listdir(os.path.join(dirname, category, subcat)), dynamic_ncols=False)
            for img in pbar3:
                pbar3.set_description(img)
                imgpng = img.replace('.pdf', '.png')
                imgs.append(imgpng)
                runcommand('convert -density 150 {} -quality 100 {}'.format(os.path.join(dirname, category, subcat, img), os.path.join(outdir, category, subcat, imgpng)))
            with ssubdoc:
                tags.a('back', href='..')
                ncols = 3
                for idx in range(0, len(imgs), ncols):
                    with tags.div(_class='row'):
                        final = (idx + ncols)
                        if (final > (len(imgs) - 1)):
                            final = (len(imgs) - 1)
                        for sidx in range(idx, final):
                            with tags.div(_class='column'):
                                tags.img(src=imgs[sidx], alt=os.path.splitext(imgs[sidx])[0], style='height:500px')
            with open(os.path.join(outdir, category, subcat, 'index.html'), 'w') as f:
                f.write(ssubdoc.render())
def generate_html(dirname, outdir, title='images'):
    if (not os.path.exists(outdir)):
        os.makedirs(outdir)
    doc = document(title=title)
    with doc.head:
        tags.style(style)
    with doc:
        with tags.ul(id='myUL'):
            for category in os.listdir(dirname):
                tags.li(tags.a(category, href=category))
    with open(os.path.join(outdir, 'index.html'), 'w') as f:
        f.write(doc.render())
    pbar1 = tqdm(os.listdir(dirname), dynamic_ncols=False)
    for category in pbar1:
        pbar1.set_description(category)
        if (not os.path.exists(os.path.join(outdir, category))):
            os.makedirs(os.path.join(outdir, category))
        subdoc = document(title=category)
        with subdoc.head:
            tags.style(style)
        with subdoc:
            tags.a('back', href='..')
            with tags.ul(id='myUL'):
                for subcat in os.listdir(os.path.join(dirname, category)):
                    tags.li(tags.a(subcat, href=subcat))
        with open(os.path.join(outdir, category, 'index.html'), 'w') as f:
            f.write(subdoc.render())
        pbar2 = tqdm(os.listdir(os.path.join(dirname, category)), dynamic_ncols=False)
        for subcat in pbar2:
            pbar2.set_description(subcat)
            if (not os.path.exists(os.path.join(outdir, category, subcat))):
                os.makedirs(os.path.join(outdir, category, subcat))
            ssubdoc = document(title=subcat)
            with ssubdoc.head:
                tags.style(style2)
            imgs = []
            pbar3 = tqdm(os.listdir(os.path.join(dirname, category, subcat)), dynamic_ncols=False)
            for img in pbar3:
                pbar3.set_description(img)
                imgpng = img.replace('.pdf', '.png')
                imgs.append(imgpng)
                runcommand('convert -density 150 {} -quality 100 {}'.format(os.path.join(dirname, category, subcat, img), os.path.join(outdir, category, subcat, imgpng)))
            with ssubdoc:
                tags.a('back', href='..')
                ncols = 3
                for idx in range(0, len(imgs), ncols):
                    with tags.div(_class='row'):
                        final = (idx + ncols)
                        if (final > (len(imgs) - 1)):
                            final = (len(imgs) - 1)
                        for sidx in range(idx, final):
                            with tags.div(_class='column'):
                                tags.img(src=imgs[sidx], alt=os.path.splitext(imgs[sidx])[0], style='height:500px')
            with open(os.path.join(outdir, category, subcat, 'index.html'), 'w') as f:
                f.write(ssubdoc.render())