You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cli-usage.md 4.2KB

6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. +++
  2. title = "CLI usage"
  3. weight = 2
  4. +++
  5. Zola only has 4 commands: `init`, `build`, `serve` and `check`.
  6. You can view the help for the whole program by running `zola --help` and
  7. that for a specific command by running `zola <cmd> --help`.
  8. ## init
  9. Creates the directory structure used by Zola at the given directory after asking a few basic configuration questions.
  10. Any choices made during these prompts can be easily changed by modifying `config.toml`.
  11. ```bash
  12. $ zola init my_site
  13. $ zola init
  14. ```
  15. If the `my_site` directory already exists, Zola will only populate it if it contains only hidden files (dotfiles are ignored). If no `my_site` argument is passed, Zola will try to populate the current directory.
  16. You can initialize a git repository and a Zola site directly from within a new folder:
  17. ```bash
  18. $ git init
  19. $ zola init
  20. ```
  21. ## build
  22. This will build the whole site in the `public` directory (if this directory already exists, it is overwritten).
  23. ```bash
  24. $ zola build
  25. ```
  26. You can override the config `base_url` by passing a new URL to the `base-url` flag.
  27. ```bash
  28. $ zola build --base-url $DEPLOY_URL
  29. ```
  30. This is useful for example when you want to deploy previews of a site to a dynamic URL, such as Netlify
  31. deploy previews.
  32. You can override the default output directory `public` by passing another value to the `output-dir` flag.
  33. ```bash
  34. $ zola build --output-dir $DOCUMENT_ROOT
  35. ```
  36. You can point to a config file other than `config.toml` like so (note that the position of the `config` option is important):
  37. ```bash
  38. $ zola --config config.staging.toml build
  39. ```
  40. You can also process a project from a different directory with the `root` flag. If building a project 'out-of-tree' with the `root` flag, you may want to combine it with the `output-dir` flag. (Note that like `config`, the position is important):
  41. ```bash
  42. $ zola --root /path/to/project build
  43. ```
  44. By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
  45. ## serve
  46. This will build and serve the site using a local server. You can also specify
  47. the interface/port combination to use if you want something different than the default (`127.0.0.1:1111`).
  48. You can also specify different addresses for the interface and base_url using `--interface` and `-u`/`--base-url`, respectively, if for example you are running Zola in a Docker container.
  49. Use the `--open` flag to automatically open the locally hosted instance in your
  50. web browser.
  51. In the event you don't want Zola to run a local webserver, you can use the `--watch-only` flag.
  52. Before starting, Zola will delete the `public` directory to start from a clean slate.
  53. ```bash
  54. $ zola serve
  55. $ zola serve --port 2000
  56. $ zola serve --interface 0.0.0.0
  57. $ zola serve --interface 0.0.0.0 --port 2000
  58. $ zola serve --interface 0.0.0.0 --base-url 127.0.0.1
  59. $ zola serve --interface 0.0.0.0 --port 2000 --output-dir www/public
  60. $ zola serve --watch-only
  61. $ zola serve --open
  62. ```
  63. The serve command will watch all your content and provide live reload without
  64. a hard refresh if possible.
  65. Some changes cannot be handled automatically and thus live reload may not always work. If you
  66. fail to see your change or get an error, try restarting `zola serve`.
  67. You can also point to a config file other than `config.toml` like so (note that the position of the `config` option is important):
  68. ```bash
  69. $ zola --config config.staging.toml serve
  70. ```
  71. By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
  72. ### check
  73. The check subcommand will try to build all pages just like the build command would, but without writing any of the
  74. results to disk. Additionally, it will also check all external links in Markdown files by trying to fetch
  75. them (links in the template files are not checked).
  76. By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag.
  77. ## Colored output
  78. Colored output is used if your terminal supports it.
  79. *Note*: coloring is automatically disabled when the output is redirected to a pipe or a file (i.e., when the standard output is not a TTY).
  80. You can disable this behavior by exporting one of the following two environment variables:
  81. - `NO_COLOR` (the value does not matter)
  82. - `CLICOLOR=0`
  83. To force the use of colors, you can set the following environment variable:
  84. - `CLICOLOR_FORCE=1`