about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2021-10-29 17:47:28 -0500
committerStarfall <us@starfall.systems>2023-12-05 10:01:01 -0600
commitd16632e8b5e7e314021a86d2c80855380d122810 (patch)
treee0d8f9a3f59b062c19e083fa5fe6c64b6a49296f
parent1a3398dcf36d4d2f972844cabeb4d98d0555a98b (diff)
strike: process files in subdirectories
-rw-r--r--sample/html/subdir/index.html15
-rw-r--r--sample/strike.ini2
-rwxr-xr-xstrike.py18
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