From 43ed04c6740a3ac11f7e2fc6d75429951536286e Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Wed, 5 May 2021 00:20:50 -0600 Subject: initial template creation, barebones arg parser --- AUTHORS | 2 + ChangeLog | 6 ++ example/templates/article/article_entry.html | 1 + example/templates/article/article_footer.html | 0 example/templates/article/article_header.html | 1 + example/templates/article/article_list_footer.html | 1 + example/templates/article/article_list_header.html | 2 + example/templates/article/article_separator.html | 0 example/templates/article/footer.html | 2 + example/templates/article/header.html | 8 +++ example/templates/article/index_footer.html | 0 example/templates/article/index_header.html | 0 example/templates/article/tag_entry.html | 1 + example/templates/article/tag_index_footer.html | 0 example/templates/article/tag_index_header.html | 0 example/templates/article/tag_list_footer.html | 1 + example/templates/article/tag_list_header.html | 1 + example/templates/article/tag_separator.html | 1 + setup.cfg | 13 ++-- 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 ++++++++++ 24 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 AUTHORS create mode 100644 ChangeLog create mode 100644 example/templates/article/article_entry.html create mode 100644 example/templates/article/article_footer.html create mode 100644 example/templates/article/article_header.html create mode 100644 example/templates/article/article_list_footer.html create mode 100644 example/templates/article/article_list_header.html create mode 100644 example/templates/article/article_separator.html create mode 100644 example/templates/article/footer.html create mode 100644 example/templates/article/header.html create mode 100644 example/templates/article/index_footer.html create mode 100644 example/templates/article/index_header.html create mode 100644 example/templates/article/tag_entry.html create mode 100644 example/templates/article/tag_index_footer.html create mode 100644 example/templates/article/tag_index_header.html create mode 100644 example/templates/article/tag_list_footer.html create mode 100644 example/templates/article/tag_list_header.html create mode 100644 example/templates/article/tag_separator.html 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 diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..d7cd106 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +David Luevano Alvarado +David Luevano Alvarado diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e404d77 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,6 @@ +CHANGES +======= + +* Prepare barebones package info +* Update readme +* Initial commit diff --git a/example/templates/article/article_entry.html b/example/templates/article/article_entry.html new file mode 100644 index 0000000..6e6befd --- /dev/null +++ b/example/templates/article/article_entry.html @@ -0,0 +1 @@ +
  • $$DATE $$TITLE
  • diff --git a/example/templates/article/article_footer.html b/example/templates/article/article_footer.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/article_header.html b/example/templates/article/article_header.html new file mode 100644 index 0000000..d2954d9 --- /dev/null +++ b/example/templates/article/article_header.html @@ -0,0 +1 @@ +

    $$TITLE

    \ No newline at end of file diff --git a/example/templates/article/article_list_footer.html b/example/templates/article/article_list_footer.html new file mode 100644 index 0000000..3d3a44c --- /dev/null +++ b/example/templates/article/article_list_footer.html @@ -0,0 +1 @@ + diff --git a/example/templates/article/article_list_header.html b/example/templates/article/article_list_header.html new file mode 100644 index 0000000..7b504ea --- /dev/null +++ b/example/templates/article/article_list_header.html @@ -0,0 +1,2 @@ +

    Articles

    +
      diff --git a/example/templates/article/article_separator.html b/example/templates/article/article_separator.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/footer.html b/example/templates/article/footer.html new file mode 100644 index 0000000..308b1d0 --- /dev/null +++ b/example/templates/article/footer.html @@ -0,0 +1,2 @@ + + diff --git a/example/templates/article/header.html b/example/templates/article/header.html new file mode 100644 index 0000000..48adfef --- /dev/null +++ b/example/templates/article/header.html @@ -0,0 +1,8 @@ + + + + +$$TITLE +$$EXTRAHEAD + + diff --git a/example/templates/article/index_footer.html b/example/templates/article/index_footer.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/index_header.html b/example/templates/article/index_header.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/tag_entry.html b/example/templates/article/tag_entry.html new file mode 100644 index 0000000..3a7aaad --- /dev/null +++ b/example/templates/article/tag_entry.html @@ -0,0 +1 @@ +$$NAME \ No newline at end of file diff --git a/example/templates/article/tag_index_footer.html b/example/templates/article/tag_index_footer.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/tag_index_header.html b/example/templates/article/tag_index_header.html new file mode 100644 index 0000000..e69de29 diff --git a/example/templates/article/tag_list_footer.html b/example/templates/article/tag_list_footer.html new file mode 100644 index 0000000..8ce77e5 --- /dev/null +++ b/example/templates/article/tag_list_footer.html @@ -0,0 +1 @@ +

      diff --git a/example/templates/article/tag_list_header.html b/example/templates/article/tag_list_header.html new file mode 100644 index 0000000..7a57395 --- /dev/null +++ b/example/templates/article/tag_list_header.html @@ -0,0 +1 @@ +

      Tags: \ No newline at end of file diff --git a/example/templates/article/tag_separator.html b/example/templates/article/tag_separator.html new file mode 100644 index 0000000..c3a6e48 --- /dev/null +++ b/example/templates/article/tag_separator.html @@ -0,0 +1 @@ +, \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 38d0126..8bebc17 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,13 +1,13 @@ [metadata] name = pyssg author = David Luevano Alvarado -author-email = david@luevano.xyz +author_email = david@luevano.xyz maintainer = David Luevano Alvarado -maintainer-email = david@luevano.xyz +maintainer_email = david@luevano.xyz summary = A Static Site Generator using markdown files -description-file = README.md +description_file = README.md license = GPLv3 -home-page = https://github.com/luevano/pyssg +home_page = https://github.com/luevano/pyssg classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: GNU General Public License v3 (GPLv3) @@ -20,7 +20,6 @@ keywords = site generator markdown - minimalist [files] packages = @@ -29,6 +28,10 @@ packages = [bdist_wheel] universal = 0 +[entry_points] +console_scripts = + pyssg = pyssg:main + [options] package_dir = = 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('\n') + f.write('\n') + f.write('\n') + f.write('\n') + f.write('$$TITLE\n') + f.write('$$EXTRAHEAD\n') + f.write('\n') + f.write('\n') + + with open('article/footer.html', 'w+') as f: + f.write('\n') + f.write('\n') + + with open('article/index_header.html', 'w+') as f: + f.write('') + + with open('article/tag_list_header.html', 'w+') as f: + f.write('

      Tags:') + + with open('article/tag_entry.html', 'w+') as f: + f.write('$$NAME') + + with open('article/tag_separator.html', 'w+') as f: + f.write(', ') + + with open('article/tag_list_footer.html', 'w+') as f: + f.write('

      \n') + + with open('article/article_list_header.html', 'w+') as f: + f.write('

      Articles

      \n') + f.write('
        \n') + + with open('article/article_entry.html', 'w+') as f: + f.write('
      • $$DATE $$TITLE
      • \n') + + with open('article/article_separator.html', 'w+') as f: + f.write('') + + with open('article/article_list_footer.html', 'w+') as f: + f.write('
      \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('

      $$TITLE

      ') + + 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