Exemplo n.º 1
0
def main():

    folders = get_args()

    for folder in folders:

        # Get translate info for folder-specific files
        translate_static = translate.get_translate_static(folder)
        translate_filename_url, translate_redirects = (
            translate.get_translate_filename_url(folder))

        # Get paths of all html files in {folder}/raw/
        paths_html = get_paths_html(folder)

        # Check if paths are in translate_filename_url (update if necessary)
        paths_html = check_translate(folder, paths_html, translate_filename_url)

        # Check if there are directories to redirect
        check_redirects(folder, translate_redirects)

        # Check if {folder}/published/* corresp. to translate_filename_url
        check_published_subdirectories(folder, translate_filename_url)

        # (1) Make body.html and config.json for each html file 
        for path_html in paths_html:

            # Get published files directory url (and name, they are the same!)
            file_html = os.path.split(path_html)[1]
            dir_url = translate_filename_url[file_html]
            
            # Get published tree for this html file
            tree_includes = make_tree([folder, 'published', 'includes', dir_url])
            
            # Get soup and split <body> and <head>
            soup = get_soup(path_html)
            body, head = get_body_head(soup) 

            # Translate 'href' and 'src' in body 
            body, paths_image = translate.translate(body,path_html,dir_url,
                                                    translate_static,
                                                    translate_filename_url)

            # Get config info from head
            config = make_config.make_config(head, path_html, tree_includes)

            # Update <body> !
            body = update_body.update_body(body)

            # Overwrite body.html and config.json leaves
            overwrite_leaves(tree_includes,
                             [(body, 'body.html'),
                              (config, 'config.json')])

            # (2) Copy images in the appropriate published/ subdirectories
            tree_images = make_tree([folder,
                                     'published',
                                     'static',
                                     'images',
                                     dir_url])
            copy_leaves(tree_images,paths_image)

            status.log(NAME,'---- done with `{}`\n'.format(dir_url))

        # (3) Make/print folder-wide urls, redirects and sitemaps files
        make_urls.make_urls(folder, translate_filename_url)
        make_redirects.make_redirects(folder, translate_redirects)
        make_sitemaps.make_sitemaps(folder, translate_filename_url)