1) export from Notion as CSV & Markdown
2) use script below on the folder with .md
files from the export
import glob
import os
slug_replace = [
' ',
',',
]
root = '/path/to/folder/with/md/files/'
output_path = 'path/to/pelican/project/content/articles/category_name/'
list_of_files = glob.glob(f'{root}*.md')
for x in list_of_files:
count += 1
path = x
filename = os.path.basename(os.path.splitext(path)[0])
parts = filename.split(' ')
needed_parts = parts[:-1]
with open(path, 'r', newline='', encoding='UTF-8') as md:
mdreader = md.read()
md_parts = mdreader.split('\n')
title = md_parts[0][2:]
title_raw = title
print(title)
if ' & ' in title:
title = title.replace(' & ', '-')
if ' - ' in title:
title = title.replace(' - ', '-')
if '(' in title:
title = title.replace('(', '')
if ')' in title:
title = title.replace(')', '-')
if ' ' in title:
title = title.replace(' ', '-')
if ',' in title:
title = title.replace(',', '')
if '\‘' in title:
title = title.replace('\‘', '')
if '\'' in title:
title = title.replace('\'', '')
if '\"' in title:
title = title.replace('\"', '')
if title.endswith('.'):
title = title[:-1]
if title.endswith('?'):
title = title[:-1]
slug = title.lower()
if slug.endswith('-'):
slug = slug[:-1]
output_title = f"Title: {title_raw} "
date = f"Date: YYYY-MM-DD "
tags = f"Tags: XXXX "
output_slug = f"Slug: {slug} "
summary = f""
content = md_parts[2:]
content = '\n'.join(content)
content_output = f"{output_title}\n{date}\n{tags}\n{output_slug}\n{summary}\n\n{content}"
with open(f"{output_path}{slug}.md", 'w') as file:
file.write(content_output)
print(slug)
print()
Note: there is probably a better way to slugify the title.
220714 update:
https://pypi.org/project/python-slugify/ seems to be the solution for easy slugifying:
NOTE: pip3 install python-slugify
NOT pip3 install slugify
from slugify import slugify
slug = slugify(title)