mkdocs-material/docs/getting-started.md

342 lines
9.2 KiB
Markdown
Raw Normal View History

2016-09-02 23:59:14 +03:00
Title: My Document
Summary: A brief description of my document.
Authors: Waylan Limberg
John Doe
Date: October 2, 2007
blank-value:
base_url: http://example.com
2016-02-09 23:59:37 +03:00
# Getting started
## Installation
### Installing MkDocs
2016-02-24 19:31:01 +03:00
Before installing [MkDocs][], you need to make sure you have Python and `pip`
the Python package manager up and running. Assuming you are a developer and
have a basic understanding of how things work and what StackOverflow is, we
won't provide guidelines on setting those up. You can verify if you're already
good to go with the following commands:
2016-02-09 23:59:37 +03:00
``` sh
python --version
# Python 2.7.2
pip --version
# pip 1.5.2
```
Installing and verifying MkDocs is as simple as:
``` sh
pip install mkdocs && mkdocs --version
# mkdocs, version 0.15.2
```
### Installing Material
Next, assuming you have MkDocs up and running `mkdocs-material` can be
installed with `pip`:
``` sh
pip install mkdocs-material
```
## Usage
If you haven't already done it, creating a new documentation project is really
simple in MkDocs:
``` sh
mkdocs new my-project
cd my-project
```
MkDocs will create the necessary files and base directory structure inside the
folder `my-project`. In order to enable the theme just add the following line
to the auto-generated `mkdocs.yml`:
``` yaml
theme: 'material'
```
If your project is hosted on GitHub, add the repository link to the
configuration. If the `repo_name` equals **GitHub**, the Material theme will
add a download and star button, and display the number of stars:
``` yaml
repo_name: 'GitHub'
repo_url: 'https://github.com/my-github-handle/my-project'
```
MkDocs includes a development server, so you can view your changes as you go -
very handy. Spin it up with the following command:
``` sh
mkdocs serve
```
Now you can go to [localhost:8000](http://localhost:8000) and the Material
theme should be visible. You can now start writing your documentation, or read
on and customize the theme through some options.
## Options
The Material theme adds some extra variables for configuration via your
project's `mkdocs.yml`. See the following section for all available options.
2016-02-17 20:08:11 +03:00
### Adding a version
In order to add the current version next to the project banner inside the
drawer, you can set the variable `extra.version`:
``` yaml
extra:
version: '0.1.0'
```
This will also change the link behind the download button to point to the
archive with the respective version on GitHub, assuming a release tagged with
this exact version identifier.
2016-02-09 23:59:37 +03:00
### Adding a logo
If your project has a logo, you can add it to the drawer/navigation by defining
the variable `extra.logo`. Ideally, the image of your logo should have
2016-02-17 20:08:11 +03:00
rectangular shape with a minimum resolution of 128x128 and leave some room
towards the edges. The logo will also be used as a web application icon on iOS.
Simply create the folder `docs/images`, add your image and reference it via:
2016-02-09 23:59:37 +03:00
``` yaml
extra:
logo: 'images/logo.png'
```
2016-02-24 19:31:01 +03:00
### Changing the color palette
Material defines a default hue for every primary and accent color on Google's
material design [color palette][]. This makes it very easy to change the
overall look of the theme. Just set the variables `extra.palette.primary` and
`extra.palette.accent` to one of the colors defined in the palette:
``` yaml
extra:
palette:
primary: 'indigo'
accent: 'light blue'
```
Color names can be written upper- or lowercase but must match the names of the
material design [color palette][]. Valid values are: _red_, _pink_, _purple_,
_deep purple_, _indigo_, _blue_, _light blue_, _cyan_, _teal_, _green_, _light
green_, _lime_, _yellow_, _amber_, _orange_, _deep orange_, _brown_, _grey_ and
_blue grey_. The last three colors can only be used as a primary color.
If the color is set via this configuration, an additional CSS file called
`palettes.css` is included that defines the color palettes. If you want to
keep things lean, clone the repository and recompile the theme with your
custom colors set. See [this article](customization.md) for more information.
2016-02-17 20:08:11 +03:00
### Changing the font family
2016-02-09 23:59:37 +03:00
2016-02-17 20:08:11 +03:00
Material uses the [Ubuntu font family][] by default, specifically the regular
sans-serif type for text and the monospaced type for code. Both fonts are
loaded from [Google Fonts][] and can be easily changed to other fonts, like for
example Google's own [Roboto font][]:
2016-02-09 23:59:37 +03:00
``` yaml
extra:
2016-02-17 20:08:11 +03:00
font:
text: 'Roboto'
code: 'Roboto Mono'
```
2016-02-24 19:31:01 +03:00
The text font will be loaded in font-weights 400 and **700**, the monospaced
font in regular weight. If you want to load fonts from other destinations or
don't want to use the Google Fonts loading magic, just set `extra.font` to
`'none'`:
2016-02-17 20:08:11 +03:00
``` yaml
extra:
font: 'none'
2016-02-09 23:59:37 +03:00
```
2016-02-24 19:31:01 +03:00
### Localization
The **Previous** and **Next** labels in the footer can easily be changed by
defining the variables `extra.i18n.prev` and `extra.i18n.next`:
``` yaml
extra:
i18n:
prev: 'Previous'
next: 'Next'
```
2016-02-09 23:59:37 +03:00
### Adding a GitHub and Twitter account
If you have a GitHub and/or Twitter account, you can add links to your
accounts to the drawer by setting the variables `extra.author.github` and
`extra.author.twitter` respectively:
``` yaml
extra:
author:
github: 'my-github-handle'
twitter: 'my-twitter-handle'
```
### Google Analytics integration
Material makes it easy to integrate site tracking with Google Analytics.
Besides basic tracking, clicks on all outgoing links can be tracked, clicks on
the download and star button, as well as how site search is used. Tracking can
be activated in your project's `mkdocs.yml`:
``` yaml
google_analytics:
- 'UA-XXXXXXXX-X'
- 'auto'
```
2016-02-09 23:59:37 +03:00
### More advanced customization
2016-02-24 19:31:01 +03:00
If you want to change the general appearance of the Material theme, see
[this article](customization.md) for more information on advanced customization.
2016-02-09 23:59:37 +03:00
## Extensions
MkDocs supports several [Markdown extensions][]. The following extensions are
not enabled by default (see the link for which are enabled by default), so you
have to switch them on explicitly.
2016-08-07 19:01:56 +03:00
### CodeHilite <small>recommended</small>
2016-02-09 23:59:37 +03:00
This extensions adds code highlighting to fenced code blocks. It might not be
the best code highlighter, but it works without JavaScript and on the server:
``` yaml
markdown_extensions:
2016-08-07 19:01:56 +03:00
- codehilite
2016-02-09 23:59:37 +03:00
```
If you want more extensive highlighting, you can use a JavaScript library like
[highlight.js][], which is not included in Material. See [this link][extra] for
further instructions
2016-08-11 00:01:31 +03:00
### Permalinks <small>recommended</small>
2016-02-09 23:59:37 +03:00
In order to add [permalinks][] to the headers of your article, set the
`markdown_extensions.toc.permalink` variable to a symbol, e.g. `¶`:
``` yaml
markdown_extensions:
- toc:
permalink: '¶'
```
The symbol can be chosen freely, it can even be a WebFont icon.
### Admonition
[Admonition][] is a handy extension that adds block-styled side content to your
documentation, for example hints, notes or warnings. It can be enabled by
setting the variable `markdown_extensions.admonition`:
``` yaml
markdown_extensions:
- admonition
```
In order to add a note, use the following syntax inside your article:
``` markdown
!!! note
Nothing to see here, move along.
```
2016-02-17 20:08:11 +03:00
This will print the following block:
2016-02-09 23:59:37 +03:00
!!! note
Nothing to see here, move along.
2016-02-16 19:04:03 +03:00
The Material template adds a neutral color for the `note` class and a red color
2016-02-21 20:30:49 +03:00
for the `warning` class. You can also add a custom title:
2016-02-16 19:04:03 +03:00
2016-02-21 20:30:49 +03:00
``` markdown
2016-08-07 19:01:56 +03:00
!!! warning
MkDocs supports several [Markdown extensions][]. The following extensions are
not enabled by default (see the link for which are enabled by default), so you
have to switch them on explicitly.
2016-02-21 20:30:49 +03:00
```
This will print:
2016-08-07 19:01:56 +03:00
!!! warning
MkDocs supports several [Markdown extensions][]. The following extensions are
not enabled by default (see the link for which are enabled by default), so you
have to switch them on explicitly.
2016-02-16 19:04:03 +03:00
More colors can be freely defined.
2016-02-09 23:59:37 +03:00
## Full example
2016-08-07 19:01:56 +03:00
Below is a full example configuration for a `mkdocs.yml`:
2016-02-09 23:59:37 +03:00
``` yaml
# Project information
site_name: 'My Project'
site_description: 'A short description of my project'
site_author: 'John Doe'
2016-02-16 19:04:03 +03:00
site_url: 'https://my-github-handle.github.io/my-project'
2016-02-09 23:59:37 +03:00
# Repository
repo_name: 'GitHub'
repo_url: 'https://github.com/my-github-handle/my-project'
# Copyright
copyright: 'Copyright (c) 2016 John Doe'
# Documentation and theme
docs_dir: 'docs'
theme: 'material'
# Options
extra:
version: '0.1.0'
logo: 'images/logo.png'
2016-02-24 19:31:01 +03:00
palette:
primary: 'indigo'
accent: 'light blue'
2016-02-17 20:08:11 +03:00
font:
text: 'Roboto'
code: 'Roboto Mono'
2016-02-24 19:31:01 +03:00
i18n:
prev: 'Previous'
next: 'Next'
2016-02-09 23:59:37 +03:00
author:
github: 'my-github-handle'
twitter: 'my-twitter-handle'
# Google Analytics
google_analytics:
- 'UA-XXXXXXXX-X'
- 'auto'
2016-02-09 23:59:37 +03:00
# Extensions
markdown_extensions:
- codehilite(css_class=code)
- admonition
- toc:
permalink: '¶'
```
[MkDocs]: http://www.mkdocs.org
2016-02-24 19:31:01 +03:00
[color palette]: http://www.materialui.co/colors
2016-02-17 20:08:11 +03:00
[Ubuntu font family]: http://font.ubuntu.com
[Google Fonts]: https://www.google.com/fonts
[Roboto font]: https://www.google.com/fonts/specimen/Roboto
2016-02-09 23:59:37 +03:00
[Markdown extensions]: http://www.mkdocs.org/user-guide/writing-your-docs/#markdown-extensions
2016-02-17 20:08:11 +03:00
[highlight.js]: https://highlightjs.org
2016-02-09 23:59:37 +03:00
[extra]: http://www.mkdocs.org/user-guide/styling-your-docs/#customising-a-theme
[permalinks]: https://en.wikipedia.org/wiki/Permalink
[Admonition]: https://pythonhosted.org/Markdown/extensions/admonition.html