git @ Cat's Eye Technologies Chrysoberyl / master script / update-html5-installations
master

Tree @master (Download .tar.gz)

update-html5-installations @masterraw · history · blame

#!/usr/bin/env python3

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

from feedmark.checkers import Schema
from feedmark.formats.markdown import feedmark_markdownize
from feedmark.loader import read_document_from


def construct_banner_image_map():
    banner_image_map = {}
    for source_article in ('article/Gewgaws.md', 'article/Games.md', 'article/Automata.md', 'article/Platforms.md', 'article/Languages.md'):
        source_doc = read_document_from(source_article)
        for section in source_doc.sections:
            if section.title in banner_image_map:
                continue
            if section.images:
                image_url = section.images[0]["source"]
                banner_image_map[section.title] = image_url
    return banner_image_map


def main():
    banner_image_map = construct_banner_image_map()

    installations_doc = read_document_from('article/HTML5 Installations.md')

    for section in installations_doc.sections:
        if section.title in banner_image_map:
            image_url = banner_image_map[section.title]
            section.properties["banner-image"] = image_url
            print(f"{section.title} -> {image_url}")

    schema_document = read_document_from("schema/HTML5 Installation.md")
    schema = Schema(schema_document)
    text = feedmark_markdownize(installations_doc, schema=schema)
    with open(installations_doc.filename, 'w') as f:
        f.write(text)


if __name__ == '__main__':
    main()