diff options
-rw-r--r-- | sample/html/subdir/index.html | 15 | ||||
-rw-r--r-- | sample/strike.ini | 2 | ||||
-rwxr-xr-x | strike.py | 18 |
3 files changed, 24 insertions, 11 deletions
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 @@ +<!DOCTYPE html> +<html lang=en-US dir=ltr> +<title>index</title> +<meta charset=UTF-8> +<meta name=robots content="noindex, nofollow"> +<meta name=viewport content="width=device-width, initial-scale=1"> +<meta http-equiv=last-modified content="Fri, 29 Oct 2021 22:31:45 GMT"> + +<section> + This file in a subdirectory of the input directory should also be processed. + +</section> +<footer> + <p>This page was generated by <a href=https://git.starfall.systems/strike>Strike</a>. +</footer> 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 |