Skip to main content
edited tags
Link
Jeff Schaller
  • 68.9k
  • 35
  • 122
  • 268
Source Link

generate html table of content from multiple html files

This is not specifically a Linux question. But I was wondering if I can get this done in BASH. I have multiple HTML files in a folder and I want to generate a HTML table of content. So for file1.html and file2.html, I want to generate a file like this :

<html>
   <body>
    <h1>Table of Contents</h1>
    <p style="text-indent:0pt">
       <a href="file1.html">file1</a><br/>
        <a href="file2.html">file2</a><br/>
     </p>
   </body>
 </html>

The process is simple but can get tedious and confusing when you have more than ten files with long names. I use the table of content file to convert the HTML files to an ebook format using Calibre. If it can be done automatically it'll save a lot of trouble.

Thank you for your time. Any help would be appreciated.