From 43ed04c6740a3ac11f7e2fc6d75429951536286e Mon Sep 17 00:00:00 2001
From: David Luevano Alvarado <david@luevano.xyz>
Date: Wed, 5 May 2021 00:20:50 -0600
Subject: initial template creation, barebones arg parser

---
 src/pyssg/__init__.py       |  4 +++
 src/pyssg/__main__.py       |  4 +++
 src/pyssg/file_discovery.py |  5 +++
 src/pyssg/file_structure.py | 76 +++++++++++++++++++++++++++++++++++++++++++++
 src/pyssg/pyssg.py          | 34 ++++++++++++++++++++
 5 files changed, 123 insertions(+)
 create mode 100644 src/pyssg/__main__.py
 create mode 100644 src/pyssg/file_discovery.py
 create mode 100644 src/pyssg/file_structure.py
 create mode 100644 src/pyssg/pyssg.py

(limited to 'src')

diff --git a/src/pyssg/__init__.py b/src/pyssg/__init__.py
index e69de29..074ae72 100644
--- a/src/pyssg/__init__.py
+++ b/src/pyssg/__init__.py
@@ -0,0 +1,4 @@
+from .pyssg import main
+
+
+__all__ = ['main']
diff --git a/src/pyssg/__main__.py b/src/pyssg/__main__.py
new file mode 100644
index 0000000..01dbe3c
--- /dev/null
+++ b/src/pyssg/__main__.py
@@ -0,0 +1,4 @@
+from .pyssg import main
+
+
+main()
diff --git a/src/pyssg/file_discovery.py b/src/pyssg/file_discovery.py
new file mode 100644
index 0000000..9b3a57d
--- /dev/null
+++ b/src/pyssg/file_discovery.py
@@ -0,0 +1,5 @@
+import os
+
+
+def get_md_files(directory: str) -> list:
+    return os.listdir(directory)
diff --git a/src/pyssg/file_structure.py b/src/pyssg/file_structure.py
new file mode 100644
index 0000000..f349fed
--- /dev/null
+++ b/src/pyssg/file_structure.py
@@ -0,0 +1,76 @@
+import os
+
+
+def create_structure(directory: str):
+    # get initial working directory
+    iwd = os.getcwd()
+
+    # create main dir
+    os.mkdir(directory)
+    os.chdir(directory)
+
+    # create templates dir
+    os.mkdir('templates')
+    os.chdir('templates')
+
+    # create article (blog) barebones template
+    os.mkdir('article')
+    with open('article/header.html', 'w+') as f:
+        f.write('<!DOCTYPE html>\n')
+        f.write('<html lang=$$LANG>\n')
+        f.write('<head>\n')
+        f.write('<meta charset="utf-8">\n')
+        f.write('<title>$$TITLE</title>\n')
+        f.write('$$EXTRAHEAD\n')
+        f.write('</head>\n')
+        f.write('<body>\n')
+
+    with open('article/footer.html', 'w+') as f:
+        f.write('</body>\n')
+        f.write('</html>\n')
+
+    with open('article/index_header.html', 'w+') as f:
+        f.write('')
+
+    with open('article/tag_list_header.html', 'w+') as f:
+        f.write('<p>Tags:')
+
+    with open('article/tag_entry.html', 'w+') as f:
+        f.write('<a href="$$URL">$$NAME</a>')
+
+    with open('article/tag_separator.html', 'w+') as f:
+        f.write(', ')
+
+    with open('article/tag_list_footer.html', 'w+') as f:
+        f.write('</p>\n')
+
+    with open('article/article_list_header.html', 'w+') as f:
+        f.write('<h2>Articles</h2>\n')
+        f.write('<ul>\n')
+
+    with open('article/article_entry.html', 'w+') as f:
+        f.write('<li><a href="$$URL">$$DATE $$TITLE</a></li>\n')
+
+    with open('article/article_separator.html', 'w+') as f:
+        f.write('')
+
+    with open('article/article_list_footer.html', 'w+') as f:
+        f.write('</ul>\n')
+
+    with open('article/index_footer.html', 'w+') as f:
+        f.write('')
+
+    with open('article/tag_index_header.html', 'w+') as f:
+        f.write('')
+
+    with open('article/tag_index_footer.html', 'w+') as f:
+        f.write('')
+
+    with open('article/article_header.html', 'w+') as f:
+        f.write('<h1>$$TITLE</h1>')
+
+    with open('article/article_footer.html', 'w+') as f:
+        f.write('')
+
+    # return to initial working directory
+    os.chdir(iwd)
diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py
new file mode 100644
index 0000000..6d0df3a
--- /dev/null
+++ b/src/pyssg/pyssg.py
@@ -0,0 +1,34 @@
+import os
+from argparse import ArgumentParser, Namespace
+
+from .file_discovery import get_md_files
+from .file_structure import create_structure
+
+
+def get_options() -> Namespace:
+    parser = ArgumentParser(prog='pyssg',
+                            description='''Static Site Generator that reads
+                            Markdown files and creates HTML files.''')
+    parser.add_argument('-d', '--directory',
+                        default='.',
+                        type=str,
+                        help='''root directory for all site files,
+                        defaults to "." (cwd), uses relative or absolute
+                        resolution''')
+    parser.add_argument('-i', '--init',
+                        action='store_true',
+                        help='''initialize the directory structure where -d
+                        specifies''')
+
+    return parser.parse_args()
+
+
+def main():
+    opts = vars(get_options())
+    directory = opts['directory']
+
+    if opts['init']:
+        create_structure(directory)
+
+    os.chdir(directory)
+    root_dir = os.getcwd()
-- 
cgit v1.2.3-70-g09d2