From d16632e8b5e7e314021a86d2c80855380d122810 Mon Sep 17 00:00:00 2001 From: Starfall Date: Fri, 29 Oct 2021 17:47:28 -0500 Subject: strike: process files in subdirectories --- sample/html/subdir/index.html | 15 +++++++++++++++ sample/strike.ini | 2 -- strike.py | 18 +++++++++--------- 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 sample/html/subdir/index.html diff --git a/sample/html/subdir/index.html b/sample/html/subdir/index.html new file mode 100644 index 0000000..bdeaad0 --- /dev/null +++ b/sample/html/subdir/index.html @@ -0,0 +1,15 @@ + + +index + + + + + +
+ This file in a subdirectory of the input directory should also be processed. + +
+ diff --git a/sample/strike.ini b/sample/strike.ini index 4ccc027..86bc8c3 100644 --- a/sample/strike.ini +++ b/sample/strike.ini @@ -1,7 +1,6 @@ [Input] # Directory with all of the markup files that you want Strike to process. # Location should be relative to this config file. -# For now, Strike will only process files in this directory and not in any subdirectories. directory = blog # Files in the input directory to exclude. # Location should be relative to the default input directory. @@ -14,7 +13,6 @@ default = template.html [Output] # Directory to put the output into. -# When Strike processes subdirectories, this will become the base directory - output will be placed into the same subdirectory relative to this as it was to the input directory. directory = html # That's all for now. In the future, we hope to allow the use of multiple templates, diff --git a/strike.py b/strike.py index 8faeab3..9f04a20 100755 --- a/strike.py +++ b/strike.py @@ -53,16 +53,16 @@ def main(): template = default_template.read_text() output_dir = basedir/config['Output']['directory'] - output_dir.mkdir(parents=True, exist_ok=True) - for file in os.listdir(input_dir): - if (input_dir/file).is_dir(): - continue - if file in exclusions: - continue - contents, meta = handle_file(input_dir/file) - output = apply_template(contents, meta, template) - (output_dir/file).write_text(output) + for path, _, files in os.walk(input_dir): + loc = os.path.relpath(path, input_dir) + (output_dir/loc).mkdir(parents=True, exist_ok=True) + for file in files: + if file in exclusions: + continue + contents, meta = handle_file(input_dir/loc/file) + output = apply_template(contents, meta, template) + (output_dir/loc/file).write_text(output) if __name__ == '__main__': import sys -- cgit