Preface: This is another of the hacks that I had contributed to the O'Reilly Blog Hacks
projects until it was pulled from production. An addendum has been added to update the piece.
One of the major aspects to Movable Type's smart system design is that its content is rendered when created or modified to static files. It makes a great deal of sense when you consider weblog content is created often, but is infrequently updated or modified other then the index or archives. Static files can be served much faster and with less system resources then dynamic content. Even index files and archive indices may only change once every couple of hours on the busiest weblog.
Static rendering of content is generally good in maximizing response times and getting the most out of your server's resources however, there is a catch if you want to incorporate some content that updates frequently such as an RSS feed. MT only renders content when manually told to do so by an author using their browser. In the case of an RSS feed, links would not appear in your MT weblog until you make another entry or decide to execute a rebuild. Content is likely to shown long after its been published or perhaps could be skipped over entirely if a feed is active enough.
Using Movable Type's Object-Oriented Perl API I developed a hack to rebuild templates, or even your whole weblog, on a regularly scheduled automatic basis using Unix's cron utility.
I've package up this functionality into a script, dubbed mt-rebuild, that is available under the Artistic license here.
The script comes with embedded documentation that covers the full range of features and options, but we'll cover a few of its most common uses below. Before we do that, you will need to know the ID of the weblog you want to automatically rebuild.
In these examples, I use a weblog with a system ID of 0, which is only for demonstration purposes. A weblog cannot have an ID of 0 in MT. It's likely that the ID of your weblog would be 2 or higher as MT creates a sample weblog with an ID of 1 at installation. Most users delete this weblog. To determine the ID of your weblog, log into the MT CMS tool, click Manage Weblog
and look at your browsers URL for a string like blog_id=(some number). That number is this weblog's ID.
Now that we have that covered, lets look at a few common uses of mt-rebuild.
To rebuild an entire weblog use a directive like this:
mt-rebuild.pl -mode="all" -blog_id=0
Rebuilding an entire weblog is system intensive especially if your weblog is of any size. One way to trim back the amount of processing is to selectively rebuild a specific archive, index or entry. Let's say we want to just rebuild the Category archives in order to refresh some content that is included in that template. We'd use the following directive:
mt-rebuild.pl -mode="archive" -blog_id=0 -archive_type="Category"
Note that the archive_type must be one of the following values and is case sensitive: Individual, Daily, Weekly, Monthly, Category.
If you wanted to rebuild a specific Movable Type index template, say your main index page, you could do that with the following:
mt-rebuild.pl -mode="index" -blog_id="0" -template="Main Index"
Like the archive_type argument in the example above, the template name is case sensitive.
The script also allows for you to rebuild a specific entry and apply other advanced options. See the embedded documentation in mt-rebuild for more details.
If you have content that appears through out your site and is constantly updated, you should consider placing that piece in a separate index template and use a little bit of server side scripting technology such as XSSI or PHP to include the content generated from that template. While the advantage of static rendering is lost, the impact of this type of dynamic rendering is marginal. The big savings is that it only requires you to regularly rebuild one file and not your entire weblog.
Addendum
Since this piece was first written a new version of mt-rebuild (v 0.2) has been released. With this new version all weblogs in the system can be rebuilt with this directive:
mt-rebuild.pl -all
This is a very resource intensive operation that, depending on the number and size of the weblogs on your system, could take a long time to fully run. However, if you are managing multiple weblogs that share content or templates, this new option can save you a lot of hassle of rebuilding each individually.
<p><em><strong>Preface:</strong> This is another of the hacks that I had contributed to the <a href="http://www.timaoutloud.org/archives/000274.html">O'Reilly <q>Blog Hacks</q></a> projects until it was <a href="http://www.timaoutloud.org/archives/000287.html">pulled from production</a>. An addendum has been added to update the piece.</em></p>
<p>One of the major aspects to Movable Type's smart system design is that its content is rendered when created or modified to static files. It makes a great deal of sense when you consider weblog content is created often, but is infrequently updated or modified other then the index or archives. Static files can be served much faster and with less system resources then dynamic content. Even index files and archive indices may only change once every couple of hours on the busiest weblog.</p>
<p>Static rendering of content is generally good in maximizing response times and getting the most out of your server's resources however, there is a catch if you want to incorporate some content that updates frequently such as an RSS feed. MT only renders content when manually told to do so by an author using their browser. In the case of an RSS feed, links would not appear in your MT weblog until you make another entry or decide to execute a rebuild. Content is likely to shown long after its been published or perhaps could be skipped over entirely if a feed is active enough.</p>
<p>Using Movable Type's Object-Oriented Perl API I developed a hack to rebuild templates, or even your whole weblog, on a regularly scheduled automatic basis using Unix's <code>cron</code> utility.</p>
<p>I've package up this functionality into a script, dubbed mt-rebuild, that is available under the Artistic license <a href="http://www.timaoutloud.org/files/mt-plugins/#mt-rebuild">here</a>.</p>
<p>The script comes with embedded documentation that covers the full range of features and options, but we'll cover a few of its most common uses below. Before we do that, you will need to know the ID of the weblog you want to automatically rebuild.</p>
<p>In these examples, I use a weblog with a system ID of 0, which is only for demonstration purposes. A weblog cannot have an ID of 0 in MT. It's likely that the ID of your weblog would be 2 or higher as MT creates a sample weblog with an ID of 1 at installation. Most users delete this weblog. To determine the ID of your weblog, log into the MT CMS tool, click <q>Manage Weblog</q> and look at your browsers URL for a string like <code>blog_id=(some number)</code>. That number is this weblog's ID.</p>
<p>Now that we have that covered, lets look at a few common uses of mt-rebuild. </p>
<p>To rebuild an entire weblog use a directive like this:</p>
<pre><code>
mt-rebuild.pl -mode="all" -blog_id=0
</code></pre>
<p>Rebuilding an entire weblog is system intensive especially if your weblog is of any size. One way to trim back the amount of processing is to selectively rebuild a specific archive, index or entry. Let's say we want to just rebuild the Category archives in order to refresh some content that is included in that template. We'd use the following directive:</p>
<pre><code>
mt-rebuild.pl -mode="archive" -blog_id=0 -archive_type="Category"
</code></pre>
<p>Note that the archive_type must be one of the following values and is case sensitive: Individual, Daily, Weekly, Monthly, Category.</p>
<p>If you wanted to rebuild a specific Movable Type index template, say your main index page, you could do that with the following:</p>
<pre><code>
mt-rebuild.pl -mode="index" -blog_id="0" -template="Main Index"
</code></pre>
<p>Like the <code>archive_type</code> argument in the example above, the template name is case sensitive.</p>
<p>The script also allows for you to rebuild a specific entry and apply other advanced options. See the embedded documentation in mt-rebuild for more details.</p>
<p>If you have content that appears through out your site and is constantly updated, you should consider placing that piece in a separate index template and use a little bit of server side scripting technology such as XSSI or PHP to include the content generated from that template. While the advantage of static rendering is lost, the impact of this type of dynamic rendering is marginal. The big savings is that it only requires you to regularly rebuild one file and not your entire weblog.</p>
<h3><a id="Addendum"></a>Addendum</h3>
<p>Since this piece was first written a new version of mt-rebuild (v 0.2) has been released. With this new version all weblogs in the system can be rebuilt with this directive:</p>
<pre><code>
mt-rebuild.pl -all
</code></pre>
<p>This is a very resource intensive operation that, depending on the number and size of the weblogs on your system, could take a long time to fully run. However, if you are managing multiple weblogs that share content or templates, this new option can save you a lot of hassle of rebuilding each individually.</p>

Leave a comment