From a1225abef233e7d0c3e75076d10e9124082866e4 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 22 Jan 2014 09:13:22 +0000 Subject: [PATCH] Move more into utils --- mkdocs/build.py | 37 +++---------------------------------- mkdocs/utils.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/mkdocs/build.py b/mkdocs/build.py index c14c9d45..365d6eca 100644 --- a/mkdocs/build.py +++ b/mkdocs/build.py @@ -1,7 +1,6 @@ #coding: utf-8 -from mkdocs.utils import copy_file, write_file, get_html_path -from mkdocs.utils import is_html_file, is_markdown_file +from mkdocs.utils import copy_media_files, write_file, get_html_path import collections import jinja2 import markdown @@ -30,36 +29,6 @@ class PathToURL(object): return 'a href="%s"' % path_to_url(path, self.config) -def build_theme(config): - """ - Copies the theme files into the build directory. - """ - for (source_dir, dirnames, filenames) in os.walk(config['theme_dir']): - relative_path = os.path.relpath(source_dir, config['theme_dir']) - output_dir = os.path.normpath(os.path.join(config['build_dir'], relative_path)) - - for filename in filenames: - if not is_markdown_file(filename) and not is_html_file(filename): - source_path = os.path.join(source_dir, filename) - output_path = os.path.join(output_dir, filename) - copy_file(source_path, output_path) - - -def build_statics(config): - """ - Copies any documentation static files into the build directory. - """ - for (source_dir, dirnames, filenames) in os.walk(config['docs_dir']): - relative_path = os.path.relpath(source_dir, config['docs_dir']) - output_dir = os.path.normpath(os.path.join(config['build_dir'], relative_path)) - - for filename in filenames: - if not is_markdown_file(filename) and not is_html_file(filename): - source_path = os.path.join(source_dir, filename) - output_path = os.path.join(output_dir, filename) - copy_file(source_path, output_path) - - def build_pages(config): """ Builds all the pages and writes them into the build directory. @@ -251,6 +220,6 @@ def build(config): """ Perform a full site build. """ - build_theme(config) - build_statics(config) + copy_media_files(config['theme_dir'], config['build_dir']) + copy_media_files(config['docs_dir'], config['build_dir']) build_pages(config) diff --git a/mkdocs/utils.py b/mkdocs/utils.py index 60940bd0..af8cb302 100644 --- a/mkdocs/utils.py +++ b/mkdocs/utils.py @@ -24,6 +24,21 @@ def write_file(content, output_path): open(output_path, 'w').write(content) +def copy_media_files(from_dir, to_dir): + """ + Recursively copy all files except markdown and HTML into another directory. + """ + for (source_dir, dirnames, filenames) in os.walk(from_dir): + relative_path = os.path.relpath(source_dir, from_dir) + output_dir = os.path.normpath(os.path.join(to_dir, relative_path)) + + for filename in filenames: + if not is_markdown_file(filename) and not is_html_file(filename): + source_path = os.path.join(source_dir, filename) + output_path = os.path.join(output_dir, filename) + copy_file(source_path, output_path) + + def get_html_path(path): """ Map a source file path to an output html path.