summaryrefslogtreecommitdiff
path: root/src/pyssg
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2021-05-05 00:20:50 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2021-05-05 00:20:50 -0600
commit43ed04c6740a3ac11f7e2fc6d75429951536286e (patch)
tree388bb3f6432dca25000f29295b10a73056bc5fd9 /src/pyssg
parentaf070051c1b9eafdd6e98d207f73c4793587c1f5 (diff)
initial template creation, barebones arg parser
Diffstat (limited to 'src/pyssg')
-rw-r--r--src/pyssg/__init__.py4
-rw-r--r--src/pyssg/__main__.py4
-rw-r--r--src/pyssg/file_discovery.py5
-rw-r--r--src/pyssg/file_structure.py76
-rw-r--r--src/pyssg/pyssg.py34
5 files changed, 123 insertions, 0 deletions
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()