mlissner / michaeljaylissner.com

The Blog

Home Page:http://michaeljaylissner.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Date-based URLs now the norm; Time to switch

mlissner opened this issue · comments

Current URLs are almost all of the form:

http://michaeljaylissner.com/blog/trim-your-dead-feeds

These should switch to:

http://michaeljaylissner.com/2014/03/12/trim-your-dead-feeds/

Major points to hit:

  • Trailing slash.
  • No .html crap.
  • Date-based index pages that work.
  • 300-series responses in old locations.
  • Make old slugs get used, not the title
  • /posts/ is now weird, but rest seems to be working. It seems to depend on silent loading of index.html files, which I find perplexing. Headway though.
  • Pagination pages are still a mess, going to index2.html. Boo.

Used the following script inside the content directory to create redirects for all of the items. It's kludgy but effective:

for f in os.listdir('.'):
    print "Processing: %s" % f
    dir_name_arr = f.rsplit('.', 1)
    if len(dir_name_arr) == 2:
        dir_name = dir_name_arr[0]
        os.mkdir('blog/%s' % dir_name)
    else:
        continue
    with open(f, 'r') as article:
        # Get the date
        for line in article:
            if line.startswith('Date:'):
                d = dateutil.parser.parse(re.sub('Date: ', '', line))
                new_path = '//michaeljaylissner.com/posts/%d/%02d/%02d/%s/' % (d.year, d.month, d.day, (dir_name.lower()))
    with open('blog/%s/index.html' % dir_name, 'w') as out:
        out.write(t % new_path)