diff options
-rwxr-xr-x | strike.py | 25 | ||||
-rw-r--r-- | template | 5 |
2 files changed, 16 insertions, 14 deletions
diff --git a/strike.py b/strike.py index 3ca1e19..e3e5e52 100755 --- a/strike.py +++ b/strike.py @@ -1,29 +1,26 @@ #!/usr/bin/env python3 from os import listdir, mkdir from sys import exit -from inspect import cleandoc -def get_output(content): - return cleandoc(f''' - i am a template - with some stuff, - {content}, - and some more stuff - ''') +def get_output(content, template="{content}"): + return template.format(content = content) def main(): src = 'blog' dest = 'output' + template = 'template' try: mkdir(dest) except FileExistsError: pass - for file in listdir(src): - with open(src + '/' + file, 'r') as fin: - file_contents = fin.read() - output = get_output(file_contents) - with open(dest + '/' + file, 'w') as fout: - fout.write(output) + with open(template) as t: + template_contents = t.read() + for file in listdir(src): + with open(src + '/' + file, 'r') as fin: + file_contents = fin.read() + output = get_output(file_contents, template=template_contents) + with open(dest + '/' + file, 'w') as fout: + fout.write(output) if __name__ == '__main__': exit(main()) diff --git a/template b/template new file mode 100644 index 0000000..0c58203 --- /dev/null +++ b/template @@ -0,0 +1,5 @@ +i am a template +with some stuff, +{content}, +and some more stuff +that has been modified |