summaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task_create_bundles.py
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/task_create_bundles.py')
-rw-r--r--nikola/plugins/task_create_bundles.py49
1 files changed, 47 insertions, 2 deletions
diff --git a/nikola/plugins/task_create_bundles.py b/nikola/plugins/task_create_bundles.py
index d024636..95f10c2 100644
--- a/nikola/plugins/task_create_bundles.py
+++ b/nikola/plugins/task_create_bundles.py
@@ -51,6 +51,8 @@ class BuildBundles(LateTask):
'output_folder': self.site.config['OUTPUT_FOLDER'],
'cache_folder': self.site.config['CACHE_FOLDER'],
'theme_bundles': get_theme_bundles(self.site.THEMES),
+ 'themes': self.site.THEMES,
+ 'files_folders': self.site.config['FILES_FOLDERS'],
}
def build_bundle(output, inputs):
@@ -74,8 +76,11 @@ class BuildBundles(LateTask):
for name, files in kw['theme_bundles'].items():
output_path = os.path.join(kw['output_folder'], name)
dname = os.path.dirname(name)
- file_dep = [os.path.join('output', dname, fname) for fname in
- files]
+ file_dep = [get_asset_path(
+ os.path.join(dname, fname), kw['themes'], kw['files_folders'])
+ for fname in files
+ ]
+ file_dep = filter(None, file_dep) # removes missing files
task = {
'file_dep': file_dep,
'basename': str(self.name),
@@ -95,6 +100,46 @@ class BuildBundles(LateTask):
}
+def get_asset_path(path, themes, files_folders={'files': ''}):
+ """Checks which theme provides the path with the given asset,
+ and returns the "real" path to the asset, relative to the
+ current directory.
+
+ If the asset is not provided by a theme, then it will be checked for
+ in the FILES_FOLDERS
+
+ >>> get_asset_path('assets/css/rst.css', ['site','default'])
+ 'nikola/data/themes/default/assets/css/rst.css'
+
+ >>> get_asset_path('assets/css/theme.css', ['site','default'])
+ 'nikola/data/themes/site/assets/css/theme.css'
+
+ >>> get_asset_path('nikola.py',['site','default'],{'nikola':''})
+ 'nikola/nikola.py'
+
+ >>> get_asset_path('nikola/nikola.py',['site','default'],{'nikola':'nikola'})
+ 'nikola/nikola.py'
+
+ """
+ for theme_name in themes:
+ candidate = os.path.join(
+ utils.get_theme_path(theme_name),
+ path
+ )
+ if os.path.isfile(candidate):
+ return os.path.relpath(candidate, os.getcwd())
+ for src, rel_dst in files_folders.items():
+ candidate = os.path.join(
+ src,
+ os.path.relpath(path, rel_dst)
+ )
+ if os.path.isfile(candidate):
+ return os.path.relpath(candidate, os.getcwd())
+
+ # whatever!
+ return None
+
+
def get_theme_bundles(themes):
"""Given a theme chain, return the bundle definitions."""
bundles = {}