|
| 1 | +# Quick-start guide |
| 2 | + |
| 3 | +This assumes you already have some project in Crystal, say, a file `src/foo.cr`. |
| 4 | + |
| 5 | +??? example "src/foo.cr" |
| 6 | + ```crystal |
| 7 | + --8<-- "examples/simple/src/foo.cr" |
| 8 | + ``` |
| 9 | + |
| 10 | +Hosting on GitHub is also assumed, though that's easy to adapt. |
| 11 | + |
| 12 | +We'll be working from the project's root directory (the one that *contains* `src`). |
| 13 | + |
| 14 | +[View the final file layout](https://github.com/oprypin/mkdocstrings-crystal/tree/master/examples/simple/) |
| 15 | + |
| 16 | +## Dependencies |
| 17 | + |
| 18 | +The dependencies that we'll be using can be installed like this: |
| 19 | + |
| 20 | +```console |
| 21 | +$ pip install mkdocs-material mkdocstrings-crystal |
| 22 | +``` |
| 23 | + |
| 24 | +This assumes you have [Python][] installed, with `pip` available. |
| 25 | + |
| 26 | +!!! tip |
| 27 | + You might want to install these in a [virtualenv][] (i.e. localized just to this project). |
| 28 | + |
| 29 | + And check out how to **[manage Python dependencies](python-dependencies.md)** long-term. |
| 30 | + |
| 31 | +## Base config |
| 32 | + |
| 33 | +Let's configure [MkDocs][] with *mkdocstrings-crystal*. Add/merge this config as your `mkdocs.yml`: |
| 34 | + |
| 35 | +???+ example "mkdocs.yml" |
| 36 | + ```yaml |
| 37 | + --8<-- "examples/simple/mkdocs.yml" |
| 38 | + ``` |
| 39 | + |
| 40 | +???+ question "Why configure like this" |
| 41 | + `theme:` `material` |
| 42 | + : [material](https://squidfunk.github.io/mkdocs-material/) is the only supported [MkDocs theme](https://www.mkdocs.org/user-guide/styling-your-docs/#third-party-themes). |
| 43 | + |
| 44 | + `repo_url` and `icon` |
| 45 | + : Link back to your repository nicely. [See more](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/). |
| 46 | + |
| 47 | + `extra_css` |
| 48 | + : Don't forget to copy and include the [recommended styles](../styling.md#recommended-styles). |
| 49 | + |
| 50 | + `mkdocstrings:` `default_handler: crystal` |
| 51 | + : Activate the upstream *mkdocstrings* plugin and tell it to collect items from Crystal, not Python, by default. |
| 52 | + |
| 53 | + `watch: [src]` |
| 54 | + : Watch a directory for [auto-reload](https://pawamoy.github.io/mkdocstrings/usage/#watch-directories). Assuming the sources are under `src/`. |
| 55 | + |
| 56 | + [`pymdownx.*` extensions](https://facelessuser.github.io/pymdown-extensions/) |
| 57 | + : Python-Markdown is an "old-school" Markdown parser, and these extensions bring the defaults more in line with what people are used to now. |
| 58 | + |
| 59 | + `deduplicate-toc` extension |
| 60 | + : This is actually an integral part of *mkdocstrings-crystal*. [Read more](../extras.md#deduplicate-toc-extension). |
| 61 | + |
| 62 | +## Add an API doc page |
| 63 | + |
| 64 | +???+ example "docs/api.md" |
| 65 | + ```md |
| 66 | + --8<-- "examples/simple/docs/api.md" |
| 67 | + ``` |
| 68 | + |
| 69 | +## Add a normal page |
| 70 | + |
| 71 | +???+ example "docs/index.md" |
| 72 | + ```md |
| 73 | + --8<-- "examples/simple/docs/index.md" |
| 74 | + ``` |
| 75 | + |
| 76 | +We linked directly to an identifier here, and *mkdocstrings* knows which page it's on and automatically links that. See: [identifier linking syntax](../README.md#identifier-linking-syntax). |
| 77 | + |
| 78 | +## View the site |
| 79 | + |
| 80 | +That's it -- we're ready! |
| 81 | + |
| 82 | +```shell |
| 83 | +mkdocs build # generate from docs/ into site/ |
| 84 | +mkdocs serve # live preview |
| 85 | +``` |
| 86 | + |
| 87 | +## Next steps |
| 88 | + |
| 89 | +If you find that you have too many classes and you don't want to manually create files with callouts to them, there are ways to automate it, and good examples are in [the migration-oriented guide](migrate.md#base-config). |
| 90 | + |
| 91 | +Otherwise, you're encouraged to curate per-topic pages with your API items. See "Manually curated docs page" [in Showcase](../showcase.md#crystal-chipmunk) for examples. |
| 92 | + |
| 93 | +And you'll probably want to [set up a navigation config](https://www.mkdocs.org/user-guide/configuration/#documentation-layout) anyway. |
| 94 | + |
| 95 | + |
| 96 | +[mkdocs]: https://www.mkdocs.org/ |
| 97 | +[python]: https://www.python.org/ |
| 98 | +[virtualenv]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment |
0 commit comments