mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Move more into utils
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user