Move more into utils

This commit is contained in:
Tom Christie
2014-01-22 09:13:22 +00:00
parent a4c5fe672b
commit a1225abef2
2 changed files with 18 additions and 34 deletions

View File

@@ -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)

View File

@@ -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.