dokuwiki-to-hugo/src/hugo_file_config.py

28 lines
672 B
Python
Raw Normal View History

2017-01-30 16:09:23 +01:00
import os.path
import time
2017-01-15 12:24:26 +01:00
class HugoFileConfig:
def filename(self, location):
return location.split('/')[-1][0:-4]
def strip_extension(self, filename):
if '.' in filename:
return filename[0:len(filename) - 4]
return filename
def create(self, file_location):
title = self.filename(file_location)
tags = list(map(self.strip_extension, file_location.split('/')))
date = time.strftime('%Y-%m-%d', time.gmtime(os.path.getmtime(file_location)))
return """+++
title = "%s"
draft = false
tags = [
%s
]
date = "%s"
2017-01-30 16:09:23 +01:00
+++""" % (title, ',\n'.join(map(lambda tag: ' "' + tag + '"', tags)), date)