#!/usr/bin/python3
"""═════════════ Site generator ═════════════-
Python, pandoc static site generator
# USE
- Run: `./gen.py build` on a ./src directory containing directories of markdown files.
- keep a ./src/index.md file which will be the home page.
- and optionally ./src/about.md which will be an about page.
- Build, upload and git upload : `make all`
# TODO
- Make index and about page compilation use template
- only generate edited posts *
- keep track of time edited to avoid this changing when repo is pulled to another machine.
- Neaten and improve efficiency *
- Move to pandoc ... -s, standalone tag, to include table of contents.
╚═════════════════════════════════════════════"""
import os, re, time, yaml, sys
# Globals
pages_list="
\n"
domain="example.com" # Add the site domain here
rss_title='Open source cookery book.'
rss_description='My virtual scrapbook.'
if os.path.exists('config.yml'): # Load yaml config
with open('config.yml','r') as file:
config_file=yaml.safe_load(file)
server=config_file['server_name']
domain=config_file['domain']
destdir=config_file['destdir']
rss="\n\n\t\n\t\t"+rss_title+"\n\t\thttps://"+domain+"\n\t\t"+rss_description+"\n\t\t"+time.strftime('%a, %d %b %Y %H:%M:%S %Z', time.localtime())+"\n\t\t15" # RSS XML channel preamble
m_pattern = r"^[^#~]+.md$"
h_pattern = r"^.+.html$|^.+.txt$"
# t_pattern = r"^.+.txt$"
p = re.compile(m_pattern) # md file regex
hp = re.compile(h_pattern) # html file regex
#tp = re.compile(t_pattern) # txt file regex
posts={} # file list dictionary
foot = "