diff options
Diffstat (limited to 'megapixels')
| -rw-r--r-- | megapixels/app/site/builder.py | 10 | ||||
| -rw-r--r-- | megapixels/app/site/parser.py | 5 | ||||
| -rw-r--r-- | megapixels/app/site/s3.py | 9 | ||||
| -rw-r--r-- | megapixels/commands/site/build.py | 14 |
4 files changed, 29 insertions, 9 deletions
diff --git a/megapixels/app/site/builder.py b/megapixels/app/site/builder.py index 895f265b..ff1a0c83 100644 --- a/megapixels/app/site/builder.py +++ b/megapixels/app/site/builder.py @@ -18,6 +18,8 @@ def build_page(fn, research_posts): """ build a single page from markdown into the appropriate template - writes it to site/public/ + - syncs any assets with s3 + - handles certain index pages... """ metadata, sections = parser.read_metadata(fn) @@ -91,3 +93,11 @@ def build_site(): for fn in glob.iglob(os.path.join(cfg.DIR_SITE_CONTENT, "**/*.md"), recursive=True): build_page(fn, research_posts) build_research_index(research_posts) + +def build_file(fn): + """ + build just one page from a filename! =^) + """ + research_posts = parser.read_research_post_index() + fn = os.path.join(cfg.DIR_SITE_CONTENT, fn) + build_page(fn, research_posts) diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py index 6c6ad688..ca6ac77b 100644 --- a/megapixels/app/site/parser.py +++ b/megapixels/app/site/parser.py @@ -55,8 +55,8 @@ def format_metadata(section): return "<section><div class='meta'>{}</div></section>".format(''.join(meta)) def format_applet(section, s3_path): - print(section) - payload = section.strip('```').strip().split('\n') + # print(section) + payload = section.strip('```').strip().strip('```').strip().split('\n') applet = {} print(payload) if ': ' in payload[0]: @@ -213,6 +213,7 @@ def parse_metadata(fn, sections): metadata['sync'] = metadata['sync'] != 'false' metadata['author_html'] = '<br>'.join(metadata['authors'].split(',')) + return metadata, valid_sections def read_research_post_index(): diff --git a/megapixels/app/site/s3.py b/megapixels/app/site/s3.py index 5464d464..18133078 100644 --- a/megapixels/app/site/s3.py +++ b/megapixels/app/site/s3.py @@ -6,13 +6,14 @@ def sync_directory(base_fn, s3_path, metadata): """ Synchronize a local assets folder with S3 """ + if not metadata['sync']: + return + fns = {} for fn in glob.glob(os.path.join(base_fn, 'assets/*')): + # print(fn) fns[os.path.basename(fn)] = True - if not metadata['sync']: - return - remote_path = s3_path + metadata['url'] session = boto3.session.Session() @@ -31,6 +32,7 @@ def sync_directory(base_fn, s3_path, metadata): if 'Contents' in directory: for obj in directory['Contents']: s3_fn = obj['Key'] + # print(s3_fn) fn = os.path.basename(s3_fn) local_fn = os.path.join(base_fn, 'assets', fn) if fn in fns: @@ -52,6 +54,7 @@ def sync_directory(base_fn, s3_path, metadata): for fn in fns: local_fn = os.path.join(base_fn, 'assets', fn) s3_fn = os.path.join(remote_path, 'assets', fn) + print(s3_fn) print("s3 create {}".format(s3_fn)) s3_client.upload_file( local_fn, diff --git a/megapixels/commands/site/build.py b/megapixels/commands/site/build.py index 0a76a9ac..2d344899 100644 --- a/megapixels/commands/site/build.py +++ b/megapixels/commands/site/build.py @@ -4,12 +4,18 @@ Build the static site import click -from app.site.builder import build_site +from app.site.builder import build_site, build_file @click.command() +@click.option('-i', '--input', 'input_file', required=False, + help='File to generate') @click.pass_context -def cli(ctx): +def cli(ctx, input_file): """Build the static site """ - print('Building the site...') - build_site() + if input_file: + print('Building {}'.format(input_file)) + build_file(input_file) + else: + print('Building the site...') + build_site() |
