hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

usage.md (10033B)

    1 ---
    2 title: Basic Usage
    3 linktitle: Basic Usage
    4 description: Hugo's CLI is fully featured but simple to use, even for those who have very limited experience working from the command line.
    5 date: 2017-02-01
    6 publishdate: 2017-02-01
    7 lastmod: 2017-02-01
    8 categories: [getting started]
    9 keywords: [usage,livereload,command line,flags]
   10 menu:
   11   docs:
   12     parent: "getting-started"
   13     weight: 40
   14 weight: 40
   15 sections_weight: 40
   16 draft: false
   17 aliases: [/overview/usage/,/extras/livereload/,/doc/usage/,/usage/]
   18 toc: true
   19 ---
   20 
   21 The following is a description of the most common commands you will use while developing your Hugo project. See the [Command Line Reference][commands] for a comprehensive view of Hugo's CLI.
   22 
   23 ## Test Installation
   24 
   25 Once you have [installed Hugo][install], make sure it is in your `PATH`. You can test that Hugo has been installed correctly via the `help` command:
   26 
   27 ```
   28 hugo help
   29 ```
   30 
   31 The output you see in your console should be similar to the following:
   32 
   33 ```
   34 hugo is the main command, used to build your Hugo site.
   35 
   36 Hugo is a Fast and Flexible Static Site Generator
   37 built with love by spf13 and friends in Go.
   38 
   39 Complete documentation is available at https://gohugo.io/.
   40 
   41 Usage:
   42   hugo [flags]
   43   hugo [command]
   44 
   45 Available Commands:
   46   completion  Generate the autocompletion script for the specified shell
   47   config      Print the site configuration
   48   convert     Convert your content to different formats
   49   deploy      Deploy your site to a Cloud provider.
   50   env         Print Hugo version and environment info
   51   gen         A collection of several useful generators.
   52   help        Help about any command
   53   import      Import your site from others.
   54   list        Listing out various types of content
   55   mod         Various Hugo Modules helpers.
   56   new         Create new content for your site
   57   server      A high performance webserver
   58   version     Print the version number of Hugo
   59 
   60 Flags:
   61   -b, --baseURL string             hostname (and path) to the root, e.g. https://spf13.com/
   62   -D, --buildDrafts                include content marked as draft
   63   -E, --buildExpired               include expired content
   64   -F, --buildFuture                include content with publishdate in the future
   65       --cacheDir string            filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/
   66       --cleanDestinationDir        remove files from destination not found in static directories
   67       --config string              config file (default is path/config.yaml|json|toml)
   68       --configDir string           config dir (default "config")
   69   -c, --contentDir string          filesystem path to content directory
   70       --debug                      debug output
   71   -d, --destination string         filesystem path to write files to
   72       --disableKinds strings       disable different kind of pages (home, RSS etc.)
   73       --enableGitInfo              add Git revision, date, author, and CODEOWNERS info to the pages
   74   -e, --environment string         build environment
   75       --forceSyncStatic            copy all files when static is changed.
   76       --gc                         enable to run some cleanup tasks (remove unused cache files) after the build
   77   -h, --help                       help for hugo
   78       --ignoreCache                ignores the cache directory
   79       --ignoreVendorPaths string   ignores any _vendor for module paths matching the given Glob pattern
   80   -l, --layoutDir string           filesystem path to layout directory
   81       --log                        enable Logging
   82       --logFile string             log File path (if set, logging enabled automatically)
   83       --minify                     minify any supported output format (HTML, XML etc.)
   84       --noChmod                    don't sync permission mode of files
   85       --noTimes                    don't sync modification time of files
   86       --panicOnWarning             panic on first WARNING log
   87       --poll string                set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes
   88       --printI18nWarnings          print missing translations
   89       --printMemoryUsage           print memory usage to screen at intervals
   90       --printPathWarnings          print warnings on duplicate target paths etc.
   91       --printUnusedTemplates       print warnings on unused templates.
   92       --quiet                      build in quiet mode
   93       --renderToMemory             render to memory (only useful for benchmark testing)
   94   -s, --source string              filesystem path to read files relative from
   95       --templateMetrics            display metrics about template executions
   96       --templateMetricsHints       calculate some improvement hints when combined with --templateMetrics
   97   -t, --theme strings              themes to use (located in /themes/THEMENAME/)
   98       --themesDir string           filesystem path to themes directory
   99       --trace file                 write trace to file (not useful in general)
  100   -v, --verbose                    verbose output
  101       --verboseLog                 verbose logging
  102   -w, --watch                      watch filesystem for changes and recreate as needed
  103 
  104 Use "hugo [command] --help" for more information about a command.
  105 ```
  106 
  107 ## The `hugo` Command
  108 
  109 The most common usage is probably to run `hugo` with your current directory being the input directory.
  110 
  111 This generates your website to the `public/` directory by default, although you can customize the output directory in your [site configuration][config] by changing the `publishDir` field.
  112 
  113 The command `hugo` renders your site into `public/` dir and is ready to be deployed to your web server:
  114 
  115 ```
  116 hugo
  117 0 draft content
  118 0 future content
  119 99 pages created
  120 0 paginator pages created
  121 16 tags created
  122 0 groups created
  123 in 90 ms
  124 ```
  125 
  126 ## Draft, Future, and Expired Content
  127 
  128 Hugo allows you to set `draft`, `publishdate`, and even `expirydate` in your content's [front matter][]. By default, Hugo will not publish:
  129 
  130 1. Content with a future `publishdate` value
  131 2. Content with `draft: true` status
  132 3. Content with a past `expirydate` value
  133 
  134 All three of these can be overridden during both local development *and* deployment by adding the following flags to `hugo` and `hugo server`, respectively, or by changing the boolean values assigned to the fields of the same name (without `--`) in your [configuration][config]:
  135 
  136 1. `--buildFuture`
  137 2. `--buildDrafts`
  138 3. `--buildExpired`
  139 
  140 ## LiveReload
  141 
  142 Hugo comes with [LiveReload](https://github.com/livereload/livereload-js) built in. There are no additional packages to install. A common way to use Hugo while developing a site is to have Hugo run a server with the `hugo server` command and watch for changes:
  143 
  144 ```
  145 hugo server
  146 0 draft content
  147 0 future content
  148 99 pages created
  149 0 paginator pages created
  150 16 tags created
  151 0 groups created
  152 in 120 ms
  153 Watching for changes in /Users/yourname/sites/yourhugosite/{data,content,layouts,static}
  154 Serving pages from /Users/yourname/sites/yourhugosite/public
  155 Web Server is available at http://localhost:1313/
  156 Press Ctrl+C to stop
  157 ```
  158 
  159 This will run a fully functioning web server while simultaneously watching your file system for additions, deletions, or changes within the following areas of your [project organization][dirs]:
  160 
  161 * `/static/*`
  162 * `/content/*`
  163 * `/data/*`
  164 * `/i18n/*`
  165 * `/layouts/*`
  166 * `/themes/<CURRENT-THEME>/*`
  167 * `config`
  168 
  169 Whenever you make changes, Hugo will simultaneously rebuild the site and continue to serve content. As soon as the build is finished, LiveReload tells the browser to silently reload the page.
  170 
  171 Most Hugo builds are so fast that you may not notice the change unless looking directly at the site in your browser. This means that keeping the site open on a second monitor (or another half of your current monitor) allows you to see the most up-to-date version of your website without the need to leave your text editor.
  172 
  173 {{% note "Closing `</body>` Tag"%}}
  174 Hugo injects the LiveReload `<script>` before the closing `</body>` in your templates and will therefore not work if this tag is not present..
  175 {{% /note %}}
  176 
  177 ### Redirect automatically to the page you just saved
  178 
  179 When you are working with more than one document and want to see the markup as real-time as possible it's not ideal to keep jumping between them. 
  180 Fortunately Hugo has an easy, embedded and simple solution for this. It's the flag `--navigateToChanged`.
  181 
  182 ### Disable LiveReload
  183 
  184 LiveReload works by injecting JavaScript into the pages Hugo generates. The script creates a connection from the browser's web socket client to the Hugo web socket server.
  185 
  186 The following methods make it easy to disable LiveReload:
  187 
  188 ```
  189 hugo server --watch=false
  190 ```
  191 
  192 Or...
  193 
  194 ```
  195 hugo server --disableLiveReload
  196 ```
  197 
  198 The latter flag can be omitted by adding the following:
  199 
  200 {{< code-toggle file="config" >}}
  201 disableLiveReload = true
  202 {{< /code-toggle >}}
  203 
  204 ## Deploy Your Website
  205 
  206 After running `hugo server` for local web development, you need to do a final `hugo` run *without the `server` part of the command* to rebuild your site. You may then deploy your site by copying the `public/` directory to your production web server.
  207 
  208 Since Hugo generates a static website, your site can be hosted *anywhere* using any web server. See [Hosting and Deployment][hosting] for methods for hosting and automating deployments contributed by the Hugo community.
  209 
  210 {{% warning "Generated Files are **NOT** Removed on Site Build" %}}
  211 Running `hugo` *does not* remove generated files before building. This means that you should delete your `public/` directory (or the publish directory you specified via flag or configuration file) before running the `hugo` command. If you do not remove these files, you run the risk of the wrong files (e.g., drafts or future posts) being left in the generated site.
  212 {{% /warning %}}
  213 
  214 
  215 [commands]: /commands/
  216 [config]: /getting-started/configuration/
  217 [dirs]: /getting-started/directory-structure/
  218 [front matter]: /content-management/front-matter/
  219 [hosting]: /hosting-and-deployment/
  220 [install]: /getting-started/installing/