In response to a post by Ron C. Johnson to the Author-it users’ group, I wrote a Visual Basic script to generate an HTML file that contains a list of all topics and their last modification date.

  • Step one: Modify the custom HTML template to pass the information the VB script will need. Add this to the very top of your HTML topic template:
 <!--
 Topic
 <pagetitle>
 <authorit:SYS_MODIFIED>
 -->
  • Step two: Add the VB script as an additional file on the book template object. This ensures that the script is copied into the publish folder each time you publish.
  • Step three: Call the VB script from the AfterPublish.bat file. To do this, add this line:
wscript _CreateLastModifiedList.vbs

Once these steps are completed, a file named _ModifiedFiles.htm is created each time you publish. To incorporate this file into your TOC, create a placeholder topic that publishes with the same name; the VB script will overwrite it with the new file.

The output is extremely raw, but it should be easy to incorporate your own styles and formatting.

We don’t use this in our shipping help, but our Quality Assurance team seems to appreciate it very much.

Download: CreateLastModifiedList.vbs (zip file)

Contents of VBScript follow after the jump.

Const FOR_READING = 1
Const ForAppending = 8
set filesys=CreateObject("Scripting.FileSystemObject")
PublishFolder = filesys.GetAbsolutePathName(".")

set objDeleteFSO = CreateObject("Scripting.FileSystemObject")
objDeleteFSO.DeleteFile(PublishFolder & "\_ModifiedFiles.htm")

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace (PublishFolder)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(PublishFolder & "\_ModifiedFiles.htm", ForAppending, True)

objTextFile.WriteLine("<html><head></head><body><h1>Topics by last modified</h1><table><Script>var aFile = new Array();")
dim counter
counter =0
For Each objFile in objFolder.Items

  If Right(objFile.Name, 4) = ".htm" then
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objTS = objFS.OpenTextFile(objFile.Name, FOR_READING)

    If objTS.AtEndOfStream <> true then
      line0 = Trim(objTS.Readline)
    End If
    If objTS.AtEndOfStream <> true then
      line1 = Trim(objTS.Readline)
    End If
    If objTS.AtEndOfStream <> true then
      line2 = Trim(objTS.Readline)
    End If
    If objTS.AtEndOfStream <> true then
      line3 = Trim(objTS.Readline)
    End If        

      If line1 = "Topic" then
        objTextFile.WriteLine("aFile[" & counter & "] = {'date':Date.parse('" & line3 & "'), 'title':'" & line2 & "', 'pagename':'" & objFile.Name & "', 'modified':'" & line3 & "'};")
        counter = counter +1
      End If

    End If

Next

objTextFile.WriteLine("function bymodified(a,b){return a.date-b.date;}")
objTextFile.WriteLine("aFile.sort(bymodified).reverse();")

objTextFile.WriteLine("for ( var i=0; i<" & counter & "; ++i ){")
objTextFile.WriteLine("   document.write('<tr><td><a href=' + aFile[i].pagename + '>' + aFile[i].title + '</a></td><td>' + aFile[i].modified + '</td></tr>');")
objTextFile.WriteLine("}</script>")
objTextFile.WriteLine("</table></body></html>');")
objTextFile.Close