Editing 15 Homepages at Once in vim

by Mike Levin

Thursday, May 05, 2022

Let’s edit 15 homepages at once! So I start out with the file that creates my all.sh file that lets me edit 15 journal.md files at once (which gets sliced & diced into these blogs using pip install blogslicer)…

import shutil
from pathlib import Path
from subprocess import run

# SET ROOT OF RELEASE SYSTEM
ghp = "/mnt/c/Users/mikle/github/"

# FOLDERS WHICH MUST EXIST PER SITE
ensure_folders = '''_data
_includes
_layouts
_posts
_sass
assets/css
assets/images'''.split('\n')

# DELETE OLD HELPERS BECAUSE APPEND
if Path('all.sh').exists():
    Path('all.sh').unlink()

with open('sites.txt', 'r') as fh:
    with open('all.sh', 'a') as fw:
        fw.write(f"vim ./journal/journal.txt ")

        for i, site in enumerate(fh):
            site = site.rstrip()
            print(i + 1, site)
            fw.write(f" ./{site}/journal.md")

            # Ensure existence of each Jekyll folder
            for afolder in ensure_folders:
                afullpath = f'{ghp}{site}/{afolder}'
                # print(afullpath)
                Path(f'{afullpath}').mkdir(parents=True, exist_ok=True)

            # Optional do-once items
            shutil.copy(f'{ghp}helpers/templates/default.html', f'{ghp}{site}/_layouts/default.html')

with open('all.sh', 'a') as fw:
    fw.write(f" ~/.vimrc")
    fw.write(f" ./helpers/make_helpers.py")
    fw.write(f" ./blast.sh")

run(["git", "commit", "-am", "Updated all.sh"], cwd=f"{ghp}/helpers/")

with open('gaids.txt') as fh:
    for site in fh:
        if site:
            gaids = site.rstrip().split()
            code = gaids[0]
            apex = gaids[1]
            title = ' '.join(gaids[2:])
            title = f'{title} | {gaids[1]}'
            aconfig = f'''plugins:
  - jekyll-feed
theme: jekyll-theme-hacker
author: Mike Levin
permalink: /:slug/
gaid: {code}
title: {title}
description: Welcome to {title}
apex: {apex}'''
            print(aconfig)
            print()
            with open(f'../{apex}/_config.yml', 'w') as fw:
                fw.write(aconfig)

And here’s the revised one that outputs a hps.sh that will load the 15 sites into vim. Easy peasy! So I ought to do something with this newfound ability.

import shutil
from pathlib import Path
from subprocess import run

# SET ROOT OF RELEASE SYSTEM
ghp = "/mnt/c/Users/mikle/github/"

# FOLDERS WHICH MUST EXIST PER SITE
ensure_folders = '''_data
_includes
_layouts
_posts
_sass
assets/css
assets/images'''.split('\n')

# DELETE OLD HELPERS BECAUSE APPEND
for helper in ['all.sh', 'hps.sh']:
    if Path(helper).exists():
        Path(helper).unlink()

with open('sites.txt', 'r') as fh:
    with open('hps.sh', 'a') as fw:
        fw.write(f"vim")
        for i, site in enumerate(fh):
            fw.write(f" ./{site.rstrip()}/index.md")

with open('sites.txt', 'r') as fh:
    with open('all.sh', 'a') as fw:
        fw.write(f"vim ./journal/journal.txt")

        for i, site in enumerate(fh):
            site = site.rstrip()
            print(i + 1, site)
            fw.write(f" ./{site}/journal.md")

            # Ensure existence of each Jekyll folder
            for afolder in ensure_folders:
                afullpath = f'{ghp}{site}/{afolder}'
                # print(afullpath)
                Path(f'{afullpath}').mkdir(parents=True, exist_ok=True)

            # Optional do-once items
            shutil.copy(f'{ghp}helpers/templates/default.html', f'{ghp}{site}/_layouts/default.html')

with open('all.sh', 'a') as fw:
    fw.write(f" ~/.vimrc")
    fw.write(f" ./helpers/make_helpers.py")
    fw.write(f" ./blast.sh")

run(["git", "commit", "-am", "Updated all.sh"], cwd=f"{ghp}/helpers/")

with open('gaids.txt') as fh:
    for site in fh:
        if site:
            gaids = site.rstrip().split()
            code = gaids[0]
            apex = gaids[1]
            title = ' '.join(gaids[2:])
            title = f'{title} | {gaids[1]}'
            aconfig = f'''plugins:
  - jekyll-feed
theme: jekyll-theme-hacker
author: Mike Levin
permalink: /:slug/
gaid: {code}
title: {title}
description: Welcome to {title}
apex: {apex}'''
            print(aconfig)
            print()
            with open(f'../{apex}/_config.yml', 'w') as fw:
                fw.write(aconfig)