Hexo has a command line interface (CLI). You use the command line prompt to execute ‘hexo’ statements. This section lists the common commands provided by Hexo
Hexo Server
Starts the server running.
- Note you must be in the directory you initialized.
- Hexo server default location is http://localhost:4000/
For example:
1 | hexo server |
Starts a local server (default is http://localhost:4000/) But use a config file called _config_localhost.yml located in the root folder.
Options
- -p or –port – default port
- -s or –static – only service static files
- –config=_config_localhost.yml
At this point you can use your browser to browse to the website shown in the window.
This is how you test.
Press Control C to shut down the server
Hexo Init {folder}
This is a command to create a website. This took about a minute, and then spit out more than the cmd buffer could hold. In reality it created a folder with a few folders
Ideally, you change directory to the folder that you just created, and you start building your website from that directory. (for example the next command is to create a blog page using ‘new’)
For example:
1 | cd c:\d\hexo |
This took about a minute to run, but upon completion I found a directory structure underneith c:\d\hexo\take1
Tips
- start with a directory that is easy to navigate to, since you do a lot of work in the command indow.
Hexo publish [layout] {title}
Publishes a draft. I think this means copy the draft file I’m working on into the hexo server area.
For example:
1 | hexo publish draft “hexo notes” |
- What I found was it moved the hexo-notes.md file out of the _drafts folder into the _posts folder.
- When I navigated to http://localhost:4000/ I found the top of this page had the hexo notes header. In addition, any categories I defined were added to my categories block.
layout
- post – path source/_posts
- page – source
- draft - source/_drafts
If you do not specify a layout then hexo will check the _drafts folder.
Hexo Generate
Build the website. This generates the static files needed for the website. It appears that it only generates changes needed to update the cached website. Hmm, not sure what this does, but I do not see my sample 2 page listed.
Options
• -d or –deploy – deploy after generation finishes
• -w or –watch – watch file changes
• -b or –bail – raise an error if any unhandled exception is through during generation
• -f or –force – force regenerate
• -c or –concurrency – maximum number of files to ge benerated in parallel. (default infinity)
9/21/2016 - Now that I have several pages what I did was deleted a few of the older sample pages. Pressing refresh (on localhost 4000) did not hide those pages. But when I executed the Hexo Generate statement it freshened the home page. So I am guessing that this function rebuilds all pages in the website. But it only generates files that are obsolete or needs to be generated.
9/26/2016 - If you have “Hexo-Local-Search” installed, then the search.xml file will be rebuilt with his step.
5/26/2023 – Rebuilds all files in the pnn/public directory
6/12/2023 – Do this before you deploy
Hexo deploy
Hexo deploy –generate
Copy files from local hexo server area to the area specified in the url:, root: parameters of the config.yml file.
Options
- -g or –generate – generate before deployment
6/23/2023 - Deployment needs to be configured see this website for more information: https://hexo.io/docs/one-command-deployment
Hexo version
Provides version information