|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os.path |
| 3 | + |
| 4 | +from sys import argv |
| 5 | + |
| 6 | +# Build directory name will be the name of Makefile recipe |
| 7 | +BUILD_DIR = argv[1] |
| 8 | + |
| 9 | +# Paths of source files |
| 10 | +MANUAL_INPUT_PATH = './manual.html' |
| 11 | +CLOUD_INPUT_PATH = './cloud.html' |
| 12 | +DRIVERS_INPUT_PATH = './drivers.html' |
| 13 | +TOOLS_INPUT_PATH = './tools.html' |
| 14 | + |
| 15 | +# Path of the output files |
| 16 | +LANDING_OUTPUT_PATH = os.path.join(BUILD_DIR, 'landing', 'index.html') |
| 17 | +CLOUD_OUTPUT_PATH = os.path.join(BUILD_DIR, 'cloud', 'index.html') |
| 18 | +TOOLS_OUTPUT_PATH = os.path.join(BUILD_DIR, 'tools', 'index.html') |
| 19 | + |
| 20 | +# Order of which all cards will show on the main landing page |
| 21 | +RENDER_ORDER = (MANUAL_INPUT_PATH, CLOUD_INPUT_PATH, |
| 22 | + DRIVERS_INPUT_PATH, TOOLS_INPUT_PATH) |
| 23 | + |
| 24 | + |
| 25 | +def build_all(template): |
| 26 | + """Build the main landing page for docs.mongodb.com""" |
| 27 | + html = '' |
| 28 | + |
| 29 | + # Read each file and concatenate the HTML |
| 30 | + fragments = [] |
| 31 | + for f in RENDER_ORDER: |
| 32 | + with open(f) as in_file: |
| 33 | + fragments.append(in_file.read()) |
| 34 | + html = '\n'.join(fragments) |
| 35 | + |
| 36 | + # Substitute the template placeholder w/ HTML |
| 37 | + file_contents = template.replace('{0}', html) |
| 38 | + |
| 39 | + # Write the output file |
| 40 | + with open(LANDING_OUTPUT_PATH, 'w') as out_file: |
| 41 | + out_file.write(file_contents) |
| 42 | + |
| 43 | + |
| 44 | +def build_individual(template, input_path, output_path): |
| 45 | + """Build a landing page from a single source file |
| 46 | + pyfe.g., Cloud landing page, Tools...""" |
| 47 | + html = '' |
| 48 | + |
| 49 | + # Read the source file |
| 50 | + with open(input_path, 'r') as in_file: |
| 51 | + html = in_file.read() |
| 52 | + |
| 53 | + # Substitute the template placeholder w/ HTML |
| 54 | + file_contents = template.replace('{0}', html) |
| 55 | + |
| 56 | + # Write the output file |
| 57 | + with open(output_path, 'w') as out_file: |
| 58 | + out_file.write(file_contents) |
| 59 | + |
| 60 | + |
| 61 | +def main(): |
| 62 | + # Read the template |
| 63 | + with open('./index.html', 'r') as in_file: |
| 64 | + template = in_file.read() |
| 65 | + |
| 66 | + # Build each landing page using the template |
| 67 | + build_all(template) |
| 68 | + build_individual(template, CLOUD_INPUT_PATH, CLOUD_OUTPUT_PATH) |
| 69 | + build_individual(template, TOOLS_INPUT_PATH, TOOLS_OUTPUT_PATH) |
| 70 | + |
| 71 | +if __name__ == '__main__': |
| 72 | + main() |
0 commit comments