Created
February 28, 2020 16:20
-
-
Save bblanchon/46a6455c9284384449da6d9d1b8237e6 to your computer and use it in GitHub Desktop.
Add redirect_from to all Jekyll posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
for file in Path('_posts').glob('*.md'): | |
print(file.name) | |
year = file.name[0:4] | |
month = file.name[5:7] | |
day = file.name[8:10] | |
title = file.name[11:-3] | |
oldurl = f'/{year}/{month}/{day}/{title}/' | |
print(oldurl) | |
content = file.read_text(encoding='utf-8').replace('---\ntitle:', f'---\nredirect_from: {oldurl}\ntitle:') | |
file.write_text(content, encoding='utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment