preface
Some of you may find it difficult to set up a blog. You need to buy a domain name to register, a configuration server, and the cost to maintain them. It doesn’t matter, you can build your own blog even if you don’t have any of these. All you need is a Github account.
An overview of the article is as follows:
Now let’s start blogging with Hexo
Set up the blog
Install hexo
npm install -g hexo-cli
Copy the code
Initialize the project
Now we have hexo installed. Next, use Hexo to initialize the blog project.
// Initialize the blog project
hexo init blog
Copy the code
Configure the topic
The default theme for hexo is _landscape, and we will now configure the theme to keep. _
// Check whether the directory is in the blog, if not, then switch the directory to the blog
cd blog
// Install the Keep theme
npm install hexo-theme-keep
// Modify the _config.yml configuration file
theme: keep
// Preview the website
hexo server
Copy the code
Open it in your browserhttp://localhost:4000As shown in figure
Add the article
new
Now, let’s create a new blog
// In the blog project, run the following command: new post
hexo newPost Recipe of the DayCopy the code
As you can see, the new blog is stored in the blog/source/_posts directory in markdown format.
The editor
To add text
Now let’s go to Recipe of the Day and write down our recipe of the day.
And save it. Refresh the link http://localhost:4000. You can see the latest article that we just updated. As shown in figure
Add categories and labels
Then we added categories and tags to the articles: go to “Cookbook of the Day. Md” and modify them as followsThen, open the terminal and run the following commands.
hexo new page categories
hexo new page tags
Copy the code
As shown below, Hexo creates a folder under the Souce directory called Categories and tags, both of which contain an index.md file.Now go to the following addresses in a browser and see the categories and tags we added. Click the “Food” category and “Recipes” TAB to see the articles that belong to them.http://localhost:4000/categories/
http://localhost:4000/tags/
To enable direct access to tags and categories from the home page, we can modify the node_moduels/hexo-theme-keep/_config.yml configuration file as follows:Refresh againhttp://localhost:4000As shown in figure
Published a draft
If you don’t want the article to be publicly accessible just yet, create a draft first. The following
hexo newDraft TodayCopy the code
The refreshhttp://localhost:4000For the time being, we cannot access the newly created article. If we want to access the article, we need to publish the article and execute the following command
// Release the draftHexo Publish Draft TodayCopy the code
This article has now been moved from the _draft directory to the _POST directory.And then, let’s refresh againhttp://localhost:4000″, you can see this article
The deployment of blog
Now we use github Page to deploy our blog. First, you’ll need to have a Github account. If you don’t, you’ll need to sign up for one.
The new warehouse
Let’s open itgithub, and then click the New Repository button, as shown in the figure
2. Create a file namedusername .github.ioWhere username is your username on GitHub3. After the long repository is successfully created, copy the HTTPS address of the repository, as shown in the figure
The deployment of
// Check whether the directory is in the blog, if not, then switch the directory to the blog
cd blog
// Install and deploy the plug-in
npm install hexo-deployer-git --save
// Modify the _config.yml configuration file
// Paste the copied address into the following repo field
deploy:
type: git
repo: https://github.com/one-cheese/one-cheese.github.io.git
branch: master
// Deploy the web site to the repository you created
hexo deploy
Copy the code
After the deployment, we refreshed the one-cheese.github. IO repository and uploaded all the static resources in the locally generated public to the repository, as shown in the figure.Now visit the Github page at one-cheese.github. IO to see the successful deployment blog.