chore: move to vite/
icyphox icyph0x@protonmail.com
Wed, 21 Mar 2018 13:22:03 +0530
D
example/build/test_page1/index.html
@@ -1,24 +0,0 @@
-<!DOCTYPE html> -<html> -<header> - some header - <title> - test site - </title> -</header> - -<body> - <h1>hey i'm a test page</h1> - -<p>here's some text</p> - -<p><em>here's some more</em></p> - -<p><strong>bold text</strong></p> - -</body> - -<footer> - copyright icy - <p> © icy </p> -<footer>
D
example/config.py
@@ -1,7 +0,0 @@
-# config.py - Vite's configuration script - -title = 'test site' -author = 'icy' -header = 'some header' -footer = 'copyright icy' -
D
example/pages/test_page1.md
@@ -1,7 +0,0 @@
-# hey i'm a test page - -here's some text - -_here's some more_ - -**bold text**
D
example/templates/index.html
@@ -1,17 +0,0 @@
-<!DOCTYPE html> -<html> -<header> - {{ header }} - <title> - {{ title }} - </title> -</header> - -<body> - {{ body }} -</body> - -<footer> - {{ footer }} - <p> © {{ author }} </p> -<footer>
D
make.py
@@ -1,56 +0,0 @@
-#!/usr/bin/env python3 - -from markdown2 import markdown_path -import os -import sys -import jinja2 -import time - -# import config file -try: - sys.path.append(os.getcwd()) - import config -except ModuleNotFoundError: - print('Error: config.py not found') - -# constants -PAGES_PATH = 'pages/' -BUILD_PATH = 'build/' -TEMPL_PATH = 'templates' - - -# jinja2 -def jinja_render(html_text, template_file): - template_loader = jinja2.FileSystemLoader('./') - env = jinja2.Environment(loader=template_loader) - template = env.get_template(template_file) - output = template.render(title=config.title, - author=config.author, - header=config.header, - footer=config.footer, - body=html_text) - return output - - -def markdown_render(filename): - html_text = markdown_path(PAGES_PATH + filename) - return html_text - - -def main(): - start = time.process_time() - template_file = TEMPL_PATH + '/index.html' - for page in os.listdir(PAGES_PATH): - html_text = markdown_render(page) - html_path = os.path.splitext(os.path.join(BUILD_PATH, page))[0] - if not os.path.exists(html_path): - os.mkdir(html_path) - output = jinja_render(html_text, template_file) - with open(os.path.join(html_path, 'index.html'), 'w') as f: - f.write(output) - print('Rendered %s' % (page)) - print('Done in %0.5fs' % (time.process_time() - start)) - - -if __name__ == "__main__": - main()
D
templates/index.html
@@ -1,17 +0,0 @@
-<!DOCTYPE html> -<html> -<header> - {{ header }} - <title> - {{ title }} - </title> -</header> - -<body> - {{ body }} -</body> - -<footer> - {{ footer }} - <p> © {{ author }} </p> -<footer>
D
vite.py
@@ -1,74 +0,0 @@
-#! /usr/bin/env python3 - -""" -Vite - A simple and minimal static site generator. -""" - -import sys -import argparse -import pathlib -import os -import importlib - -parser = argparse.ArgumentParser(description=""" - A simple and minimal static site generator. - """) -parser.add_argument('action', choices=['new', 'build']) -# TODO: add help for each action -parser.add_argument('path', nargs='*') - -if len(sys.argv) == 1: - parser.print_help() - sys.exit(1) - -try: - args = parser.parse_args() - project_path = args.path[0] -except IndexError: - parser.print_help() - sys.exit(1) - - -def create_project(path): - try: - abs_path = pathlib.Path(path).resolve() - cur_path = pathlib.Path('.').resolve() - os.makedirs(os.path.join(path, 'build')) - os.mkdir(os.path.join(path, 'pages')) - os.mkdir(os.path.join(path, 'templates')) - create_config(path) - os.symlink(os.path.join(cur_path, 'make.py'), - os.path.join(abs_path, 'make.py')) - print('Created project directory at %s.' % (abs_path)) - except FileExistsError: - print('Error: specified path exists') - - -def create_config(path): - with open(path + '/config.py', 'w') as f: - f.write("""# config.py - Vite's configuration script - -title = '' -author = '' -header = '' -footer = '' - """) - - -def build_project(path): - try: - os.chdir(path) - importlib.import_module('make') - except FileNotFoundError as e: - print('Error: no such file or directory: %s' % (path)) - - -def main(): - if args.action == 'new': - create_project(project_path) - elif args.action == 'build': - build_project(project_path) - - -if __name__ == "__main__": - main()