Sunday, June 27, 2010

Vim Pagemaking Macro

Today is a high day. I finished making content pages (all the Hydrotherapy stuff) at 2.30 this afternoon. I wondered if it would ever end.
The numbers breakdown is:
Diseases: 202
Effects: 54
Problems: 437
Techniques: 295
Making a grand total of 988 pages.

The Vim pagemaker macro I used was:

/#card^Mf<"ly2f>:sp PageIndex.html^MG$o^[p:wq^Mj^"ty$j"fy$:sp ^Rf^M:read top.h^MG$"tp:read head.h^MkJxG$:read cont.h^MG$:read breadcrumb.h^Mj/<\/p>^Mh"tpG$"tpa</h1>^[^Wwjma/#end^Mkd'a^WWpG$:read rightbox.h^MG$:read badge.h^MG$:read bottom1.h^MG$:read col1.h^MG$:read bottom2.h^MG$:read col2.h^MG$:read bottom3.h^MG$:read col3.h^M/^Rf^M^faa class="here"^[G$:read footer.h^MG:w^M
To tease it out a bit we need to remember that the first three lines of the card "Visceral Congestion" were:
#card @<a href="VisceralCongestion.html">Visceral Congestion</a>
Visceral Congestion

And we need to know that:
"l = register L etc
^M = Enter
^[ = Escape
^W = Ctrl-W (for window navigation with a split screen)
^R = Ctrl-R (reads in the contents of following register)

The macro would start with the cursor in the previous card so:

/#card^Mf<"ly2f>:sp PageIndex.html^MG$o^[p:wq^M

will find the first line of the card, yank the link, <a href="VisceralCongestion.html">Visceral Congestion</a>, to Register L (Link) and append this link to the end of the Page Index file.
j^"ty$j"fy$:sp ^Rf^M

Then moving down to the second line (Visceral Congestion) then yanks it to Register T (Title). Then it moves down to the third line (VisceralCongestion.html), appends it to Register F (Filename) and splits to a window editing the file, VisceralCongestion.html.

:read top.h^MG$"tp:read head.h^MkJxG$:read cont.h^MG$

This starts the Visceral Congestion.html with the DTD and other HTML down to the <title> tag by "reading" in the contents of a file I had previously made called "head.h". It then puts the contents of Register T (Visceral Congestion) and moves to the end of the file (with G$) before reading in the contents of the file "cont.h" which takes us down to the top of the content of the file.

:read breadcrumb.h^Mj/<\/p>^Mh"tpG$"tpa</h1>^[

This reads in the breadcrumb navigation, which I made at the beginning of each section, and places the title at the end then completes the heading of page by placing the title in h1 tags.


Using window navigation we return to the lower window containing the contents of the card, places Mark A (ma) on the first line of the file (just below the filename and searches for the end of the card. It then deletes the card's contents, navigates up a window puts the contents then moves to the end of the file.

:read rightbox.h^MG$:read badge.h^MG$:read bottom1.h^MG$:read col1.h^MG$:read bottom2.h^MG$:read col2.h^MG$:read bottom3.h^MG$:read col3.h^M

A long list of file with various HTML are read in at the end of the file, the last ones containing the site map at the bottom of the page. The "col" files had the contents of the map.

/^Rf^M^faa class="here"^[G$:read footer.h^MG:w^M

Once the contents of the site map were read in, the page's title needed highlighting with the class "here" and the footer file finished off the page.

I then opened the page in Firefox, corrected any obvious problems then validated it with Total Validator (6.3.0) as desktop tool.

Total Validator was great with British English spellchecking and accessibility validation as well as the expected HTML validation.

The whole process for one page without major problems took only a minute.

But now it's finished. Just the main index page and the messy stuff up the top of the site to write now.