GEOUNIVERSAL .:.


pages - photos - log

site, webmaster .:.

2021 06 27

log.py:

import markdown
md = markdown.Markdown(extensions = ['meta', 'attr_list'])
import os

def convertlog(log, pagename):
  file = open(logpath + log, 'r')
  body = md.convert(file.read())
  print(log,pagename)
  file.close()

  body = makestamp(pagename) + '<hr>' + body

  if 'tags' in md.Meta:
    tags = md.Meta['tags'][0].split(', ')
    body = makelinktags(tags) + ' ' + body

  body = '\n<section>' + body + '\n</section>'
  return body

def makelinktags(tags):
  anchor_tag = '<a href="/log/{0}.html">{0}</a>'
  taglist = [anchor_tag.format(tag) for tag in tags]
  tagline = ', '.join(taglist)
  return tagline

def makestamp(pagename): # permalink for that entry
  return '<a href="/log/' + pagename + '.html">.:.</a>'

def makepage(body):
  file = open('../templates/header.txt', 'r')
  header = file.read()
  file.close()

  file = open('../templates/footer.txt', 'r')
  footer = file.read()
  file.close

  html = header + body + footer
  return html

def savefile(html, savepath):
  savefile = open(savepath, 'w')
  savefile.write(html)
  savefile.close()

logpath = '../md/log/'
logpile = sorted(os.listdir(logpath))
logbook = {}
logpages = []

# convert each log

for log in logpile:
  fullpath = os.path.join(logpath, log)

  if os.path.isdir(fullpath): 
    continue
  else: 
    filetype = log.split('.')[-1]
    pagename = log.split('.')[0]

  if filetype == 'txt' or filetype == 'md':
    logbook[pagename] = convertlog(log, pagename)

# make each individual page

for page in logbook:
  html = makepage(logbook[page])
  logpages.append(logbook[page])
  savepath = '../html/log/' + page + '.html'
  savefile(html, savepath)
  print(savepath)

# make one page for all entries

logpages.reverse()
logindex = makepage('\n'.join(logpages))
savepath = '../html/log/index.html'
savefile(logindex, savepath)