Repository: mkdocs/mkdocs

Issue:
README.md in theme directory overrides index.md in docs
## Summary

MkDocs will generate `index.html` from `README.md` in the theme directory, even if `index.md` exists in the docs directory.

## Steps to reproduce
Consider the following minimal example:
```
├── docs
│   └── index.md
├── mkdocs.yml
└── theme
    ├── main.html
    └── README.md
```
docs/index.md:
```
The right index.
```
theme/README.md:
```
The wrong index.
```
theme/main.html:
```
{{ page.content }}
```
mkdocs.yml:
```yaml
site_name: Repro
theme:
  name: null
  custom_dir: theme
nav:
  - Overview: index.md
```

After running `mkdocs build`, the following `index.html` is produced:
```
<p>The wrong index.</p>
```
Furthermore, `mkdocs build` emits the following message:
```
INFO    -  The following pages exist in the docs directory, but are not included in the "nav" configuration:
  - README.md 
```

This is especially surprising, because the [the docs say](https://www.mkdocs.org/user-guide/writing-your-docs/#file-layout):

> If both an index.md file and a README.md file are found in the same directory, then the index.md file is used and the README.md file is ignored.

I would expect markdown files in the `theme` directory to not affect how the documentation is built, unless they are specifically included from a template.

```
$ mkdocs --version
mkdocs, version 1.0.4 from /usr/lib/python3.7/site-packages/mkdocs (Python 3.7)
```


Discussion:
I expect this was fixed in #1672, which will be available in the next release. However, it occurs to me that perhaps we should exclude all Markdown files from the theme directory, or at least README files. A Theme should not be able to add "pages" to a site and README files in a theme would not be content either.

Resolving patch:
diff --git a/mkdocs/structure/files.py b/mkdocs/structure/files.py
--- a/mkdocs/structure/files.py
+++ b/mkdocs/structure/files.py
@@ -66,10 +66,11 @@ def css_files(self):
     def add_files_from_theme(self, env, config):
         """ Retrieve static files from Jinja environment and add to collection. """
         def filter(name):
-            patterns = ['.*', '*.py', '*.pyc', '*.html', 'mkdocs_theme.yml']
+            patterns = ['.*', '*.py', '*.pyc', '*.html', '*readme*', 'mkdocs_theme.yml']
+            patterns.extend('*{0}'.format(x) for x in utils.markdown_extensions)
             patterns.extend(config['theme'].static_templates)
             for pattern in patterns:
-                if fnmatch.fnmatch(name, pattern):
+                if fnmatch.fnmatch(name.lower(), pattern):
                     return False
             return True
         for path in env.list_templates(filter_func=filter):


Test patch:
diff --git a/mkdocs/tests/structure/file_tests.py b/mkdocs/tests/structure/file_tests.py
--- a/mkdocs/tests/structure/file_tests.py
+++ b/mkdocs/tests/structure/file_tests.py
@@ -322,7 +322,9 @@ def test_files(self):
     @tempdir(files=[
         'base.html',
         'favicon.ico',
-        'style.css'
+        'style.css',
+        'foo.md',
+        'README'
     ])
     def test_add_files_from_theme(self, tdir, ddir):
         config = load_config(docs_dir=ddir, theme={'name': None, 'custom_dir': tdir})