python and javascript with html generation
<p>On a website that I manage, we have JSON files which contain page data. We then create the page using this JSON.</p>

<p>The data looks roughly like this (except a lot more complex).</p>

<pre><code>[
  {"title": "Hello world", "content": "World, hello to you!"},
  {"title": "Hello world Part II", "content": "The sequel to hello world."},
  ...
]
</code></pre>

<p>This data is then parsed into HTML. Now, here lies the issue: we need two versions of the HTML.</p>

<p>One needs to be static, outputted in the format of <code>file-0.html</code> which would be formatted with a title of <code>Hello World</code> and content of <code>World, hello to you!</code> and <code>file-1.html</code> (title=<code>Hello World Part II</code>, content=<code>The sequel to hello world</code>).</p>

<p>The second needs to be just a plain page <code>file-all.html</code> which includes a JavaScript that pulls the JSON via AJAX when its needed and creates a container for each page which includes subpages that have the content/titles for everything in the JSON.</p>

<p>Right now, we use Python to generate the HTML for the <code>file-0.html</code> static pages, and then JavaScript for the AJAX pages. While this works, it means there is a lot of code duplication for a pretty small project—every time we want to change the class of the <code>&lt;h1&gt;</code> title is wrapped in, we have to change two places with slightly different syntax.</p>

<p>Is there any good way of fixing this issue, so that all the code for generating page (or as much as possible) is in one language? (This would probably have to be JavaScript, since bandwidth is an issue—we'd like to avoid transferring <code>HTML</code> via AJAX if possible.)</p>
