Commit ba59e91f authored by Chris Lamb's avatar Chris Lamb 💬

Drop "migrate-blog-posts" script

parent 9e32740d
#!/usr/bin/env python3
import os
import re
import sys
import glob
import click
import shutil
from dateutil import parser
re_date = re.compile(r'^\[\[!meta date="([^\"]+)"\]\]$', re.MULTILINE)
re_meta = re.compile(r'^\[\[!(meta|tag) .*\]\]$', re.MULTILINE)
re_tabs = re.compile(r'\t')
re_links = re.compile(r'\[\[(?P<text>[^\|]+)\|(?P<url>[^\]]+)\]\]')
re_plugins = re.compile(r'\[\[!(?P<key>\S+)\s+(?P<value>[^\]]+)\]\]', re.MULTILINE)
re_filename = re.compile(r'/(?P<week>\d+).mdwn$')
@click.argument('target_dir', default='_blog/posts')
def main(original_blog_dir, target_dir):
log("Removing and recreating {}".format(target_dir))
shutil.rmtree(target_dir, ignore_errors=True)
for x in glob.glob(os.path.join(original_blog_dir, 'posts', '*.mdwn')):
m =
if m is None:
log("Ignoring file {}".format(x))
week = int('week'))
generate_week(x, os.path.join(target_dir, '{}.md'.format(week)), week)
def generate_week(src, dst, week):
with open(src, 'r') as f:
body =
m =
if m is None:
raise ValueError("Could not parse date date from {}".format(src))
date =
metadata = (
('layout', 'blog'),
('week', week),
('published', parser.parse(date).strftime('%Y-%m-%d %H:%m:%S')),
for x, y in (
# Strip leading meta
(re_meta, ''),
# We don't have plugins in Jekyll
(re_plugins, re_plugins_callback),
# We don't have [[text|target]] links in Jekyll. Last in list)
(re_links, re_links_callback),
# Replace tabs
(re_tabs, ' '),
body = x.sub(y, body)
with open(dst, 'w') as f:
print("---", file=f)
print('\n'.join('{}: {}'.format(x, y) for x, y in metadata), file=f)
print("---\n", file=f)
print(body.strip(), file=f)
log("Wrote {}".format(dst))
def log(*args, **kwargs):
print("I: {}".format(*args, **kwargs), file=sys.stderr)
def re_links_callback(m):
return '<a href="{}">{}</a>'.format('url'),'text'),
def re_plugins_callback(m):
url, value = {
'bug': ('{}', '#{}'),
'pkg': ('{}', '{}'),
'patch': ('{}', '#{}'),
'issue': ('{}_issue.html', '{}'),
'pkgset': ('{}.html', '{}'),
return '[{}]({})'.format(
if __name__ == '__main__':
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment