Fixing the Lower-Case Mistake

After writing The Lower-Case Mistake this morning, that basically convinced me that I had to move back to having CamelCase file-names for Cardigan Bay.

So … a burst of activity this afternoon, and the automatic lower-casing of file-names is gone.

If you create a page called HelloWorld, it will be in a file called HelloWorld.md

The GitHub / GitLab repos are now updated and this is now the official behaviour of Cardigan Bay.

Obviously it’s a breaking change. Because if you were using it yesterday and your HelloWorld page was in file called helloworld.md the new version of the code can’t see it.

The default Bedrock Wiki pages that come with Cardigan Bay have now been fixed. But I’m afraid you’ll have to change any other page names yourself.

I wrote a simple script to help me convert the ThoughtStorms page-base (of over 5000 pages)

It wasn’t perfect, but it did enough of them that I’m happy to commit to making the change. (I’ll clean up the problem cases by hand)

Here’s the code to fix the names. It basically searches all the links in pages to find CamelCase names. Then prints a list of “git mv” commands that would turn the lower-cased version of those named files back into CamelCased ones. You just have to pipe that output to a shell script file and run it and it will do the changes.

Like I say, not perfect, but took a couple of minutes to write, and does the bulk of the job.

from fsquery import FSQuery
import re

fsq = FSQuery("pages/").Ext("md").NoFollow(".work").FileOnly()


d = {}

def grepFiles() :
    for f in fsq :
        for l in f.open_file() :
            l =l.strip()
            sqrwiki = re.compile("(\[\[(\S+?)\]\])")
            allnames = [x[1] for x in sqrwiki.findall(l)]
            for n in allnames :
                if ":" in n : continue
                if ">" in n : continue
                #if not n.islower() : continue
                d[n.lower()] = n
     

    for k,v in d.items() :
        print("git mv '%s.md' '%s.md'" % (k,v))

def searchDir() :
    for f in fsq :
        r = f.relative().strip("/")
        if r.islower() :
            print("git mv '%s' '%s'" % (r,r))


#searchDir()
grepFiles()

 

You’ll have to fiddle with it a bit, and make sure you have https://github.com/interstar/FSQuery installed. But like I say, it does the bulk of the work.

If you have problems (eg. a big investment in Cardigan Bay data but can’t do this migration yourself), leave me a message and I’ll see what I can do to help.