Repository: mkdocs/mkdocs

Issue:
jinja2.exceptions.UndefinedError: 'meta' is undefined
**jinja2.exceptions.UndefinedError: 'meta' is undefined**

Copying themes `bootstrap` to project folder named: `mybootstrap`

only .yml entry

```
site_name: The website
theme_dir: 'mybootstrap'
```

ERROR

```
$ mkdocs serve
Traceback (most recent call last):
  File "/usr/bin/mkdocs", line 9, in <module>
    load_entry_point('mkdocs==0.11.1', 'console_scripts', 'mkdocs')()
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/main.py", line 74, in run_main
    main(cmd, args=sys.argv[2:], options=dict(opts))
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/main.py", line 46, in main
    serve(config, options=options)
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/serve.py", line 85, in serve
    build(config, live_server=True)
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/build.py", line 223, in build
    build_pages(config)
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/build.py", line 155, in build_pages
    build_404(config, env, site_navigation)
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/build.py", line 142, in build_404
    output_content = template.render(global_context)
  File "/usr/lib/python3.4/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3.4/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.4/site-packages/jinja2/_compat.py", line 36, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.4/site-packages/mkdocs-0.11.1-py3.4.egg/mkdocs/themes/mkdocs/404.html", line 1, in <module>
    {% extends "base.html" %}
  File "mybootstrap/base.html", line 48, in <module>
    <div class="col-md-9" role="main">{% include "content.html" %}</div>
  File "mybootstrap/content.html", line 1, in <module>
    {% if meta.source %}
  File "/usr/lib/python3.4/site-packages/jinja2/environment.py", line 397, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'meta' is undefined

```

Patch: https://github.com/tomchristie/mkdocs/pull/244 seems not to help for this case



Discussion:

Resolving patch:
diff --git a/mkdocs/build.py b/mkdocs/build.py
--- a/mkdocs/build.py
+++ b/mkdocs/build.py
@@ -35,8 +35,11 @@ def convert_markdown(markdown_source, site_navigation=None, extensions=(), stric
         extensions=extensions
     )
     html_content = md.convert(markdown_source)
-    meta = md.Meta
-    toc_html = md.toc
+
+    # On completely blank markdown files, no Meta or tox properties are added
+    # to the generated document.
+    meta = getattr(md, 'Meta', {})
+    toc_html = getattr(md, 'toc', '')
 
     # Post process the generated table of contents into a data structure
     table_of_contents = toc.TableOfContents(toc_html)


Test patch:
diff --git a/mkdocs/tests/build_tests.py b/mkdocs/tests/build_tests.py
--- a/mkdocs/tests/build_tests.py
+++ b/mkdocs/tests/build_tests.py
@@ -13,6 +13,14 @@
 
 
 class BuildTests(unittest.TestCase):
+
+    def test_empty_document(self):
+        html, toc, meta = build.convert_markdown("")
+
+        self.assertEqual(html, '')
+        self.assertEqual(len(list(toc)), 0)
+        self.assertEqual(meta, {})
+
     def test_convert_markdown(self):
         """
         Ensure that basic Markdown -> HTML and TOC works.