Skip to content

Commit

Permalink
Added optional robots.txt and favicon.ico baking. Fixes #23.
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Feb 12, 2014
1 parent 9783bc5 commit 702b702
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
22 changes: 18 additions & 4 deletions bakery/management/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,26 @@ def handle(self, *args, **options):
interactive=False,
verbosity=0
)
target_dir = os.path.join(self.build_dir, settings.STATIC_URL[1:])
if os.path.exists(settings.STATIC_ROOT) and settings.STATIC_URL:
shutil.copytree(
settings.STATIC_ROOT,
os.path.join(self.build_dir, settings.STATIC_URL[1:])
shutil.copytree(settings.STATIC_ROOT, target_dir)
# If they exist in the static directory, copy the robots.txt
# and favicon.ico files down to the root so they will work
# on the live website.
robot_src = os.path.join(target_dir, 'robots.txt')
favicon_src = os.path.join(target_dir, 'favicon.ico')
if os.path.exists(robot_src):
shutil.copy(robot_src, os.path.join(
settings.BUILD_DIR,
'robots.txt'
)
)
if os.path.exists(favicon_src):
shutil.copy(favicon_src, os.path.join(
settings.BUILD_DIR,
'favicon.ico',
)
)

# Build the media directory
if not options.get("skip_media"):
if self.verbosity > 1:
Expand Down
4 changes: 4 additions & 0 deletions bakery/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def test_build_cmd(self):
'build_dir': settings.BUILD_DIR,
})
call_command("build", 'bakery.tests.MockDetailView')
robots_path = os.path.join(settings.BUILD_DIR, 'robots.txt')
self.assertTrue(os.path.exists(robots_path))
favicon_path = os.path.join(settings.BUILD_DIR, 'favicon.ico')
self.assertTrue(os.path.exists(favicon_path))
if django.VERSION >= (1, 5):
self.assertRaises(
CommandError,
Expand Down
Binary file added bakery/tests/static/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions bakery/tests/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello robots!

0 comments on commit 702b702

Please sign in to comment.