1. Preparations
1. Install Node.js
-
Download Node.js: official website download address (here take Windows as an example):
-
Double-click the downloaded
.msi
file, press Next, and install it; -
In the cmd command window, enter the following command. If the version of Node.js can be displayed, the installation is successful.
node -v
2. Install Git
-
Download Git: official website download address (here, take Windows as an example, I downloaded it here) You can also go to the official website to download;
-
Double-click the downloaded Git installation package, press Next to install it;
-
In the cmd command window, enter the following command. If the version of Git can be displayed, the installation is successful.
git -version
- If you want to know more about Git, you can learn from the following websites. If you have a better website, you can also recommend it to me:
- official website
- W3Cschool
- Liao Xuefeng Website Tutorial
2. Hexo build blog
1. Install Hexo
-
In the computer, create a
winneyBlog
folder to store your own blog content. -
In the
winneyBlog
folder, right mouse button, selectGit Bash
, enter the command window
-
In the command window, enter the following code:
npm install -g hexo-cli
as the picture shows:
2. Initialize Hexo
-
In the command window, enter the following code: (a
hexo
folder will be created under thewinneyBlog
directory)hexo init hexo
as the picture shows:
3. Configure Hexo
-
Enter the hexo folder
cd hexo
-
install dependencies
npm install
-
deployment file
hexo generate
as the picture shows:
4. Start the server
-
Execute the following code in the command window:
As shown in the figure: (If you want to perform other command operations, you can press
Ctrl + C
to stop the server)
hexo server
-
Enter http://localhost:4000/ in the address bar of the browser (the default port is 4000). If you can see the effect as shown in the figure, it means that the initialized Hexo blog has been successfully built.
as the picture shows:
3. Deploy the local Hexo blog to GitHub Pages
-
Create a new warehouse named
winney07.github.io
(the name of this warehouse must be named in strict accordance with the format ofusername.github.io
) [provided that you have A Github account]
As shown in the picture: (Because I have already created this library, a red warning will be displayed, but later I will rewrite a new one with the same name for screenshots)
-
Enter the warehouse that has been created (click your avatar, select Your profile, click the newly created warehouse to enter the warehouse), click settings, find the GitHub Pages option, click Choose a theme to choose a theme (you can choose or not) , decide whether to operate this step according to your own needs)
as the picture shows:
-
Configure Git personal information, in the
winneyBlog
directory, right mouse button, selectGit Bash
, enter the command window, enter the following commandgit config --global user.name "Github username" //My Github account name git config --global user.email "Github mailbox" // Register your own Github email address
-
Generating SSH KEY means generating a public key and key, because Github needs a key to connect to the local. Enter the following command in the command window, and then you need to press Enter 3 times in a row to generate the key (you can see the corresponding information every time you press Enter) [You can also check whether you already have the ssh key:
cd ~/.ssh
If there is no key, there will be no such folder, and if there is, the backup will be deleted]ssh-keygen -t rsa -C "Github mailbox" //Register your own Github email address
as the picture shows:
-
The generated SSH KEY will be saved to the
C:/Users/computer name/username/.ssh
directory (according to your own computer user name, open the corresponding directory)
(1) Open the .ssh directory, open the id_rsa.pub file, and copy all the contents inside (these contents are the keys)
-
Add
SSH keys
to GitHub-
Open Github, click on the avatar, and select
Settings
;
-
Select the
SSH and GPG keys
item, click theNew SSH key
button in the upper right corner, and paste the newly copied key into thekey
input box, title just give it a name
-
Finally click
Add Key
, if this interface is displayed, it means that the SSH KEY configuration is successful:
-
-
Modify the global configuration file
-
Under the hexo folder, find the
_config.yml
file;
as the picture shows:
-
Copy warehouse address:
as the picture shows:
-
Modify the deploy attribute in the
_config.yml
file (the purpose is to put the local hexo project on Github)
as the picture shows:
Note: [If the
https
protocol is filled inrepository
, andhexo d
uploads the code to Github with the following similar error, you can replacerepository
to link tossh
]
as the picture shows:
-
-
Install the
hexo-deployer-git
plugin to quickly host the code on Githubnpm install hexo-deployer-git --save
-
Host the hexo project on GitHub (commands can be written separately or together)
hexo clean & amp; & amp; hexo generate & amp; & amp; hexo deploy
Remarks:
hexo clean
: Clear cache files (db.json) and generated static files (public)
hexo generate
: Pre-generate static files before deployment, abbreviated ashexo g
hexo deploy
: Deploy the website immediately after the file is generated, abbreviated ashexo d
-
Enter https://username.github.io/ in the browser address bar to access, (username is your Github account name), if it can be accessed normally, and the content displayed by the local hexo project is the same, then it means You have deployed your local hexo project to Github.
4. Configure blog personal information
-
In the hexo directory, find the global configuration file
_config.yml
-
The configuration information is as follows:
# Hexo Configuration ## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/hexojs/hexo/ # Site site information configuration title: winney #site name subtitle: It is never too old to learn. #Site subtitle description: Doing is better than saying. #Site Information Introduction keywords: winneyBlog Blog author: winney #site author language: zh-Hans #site language, default is English, zh-Hans is Chinese timezone: Asia/Shanghai #timezone # URL blog address ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' url: https://AAAAAAAAAA.github.io/ root: / permalink: :year/:month/:day/:title/ permalink_defaults: # Directory directory settings source_dir: source public_dir: public tag_dir: tags archive_dir: archives category_dir: categories code_dir: downloads/code i18n_dir: :lang skip_render: # Writing article layout new_post_name: :title.md # File name of new posts default_layout: post titlecase: false # Transform title into titlecase external_link: true # Open external links in new tab filename_case: 0 render_drafts: false post_asset_folder: true relative_link: false future: true highlight: enable: true line_number: true auto_detect: false tab_replace: # Home page setting Home page setting # path: Root path for your blogs index page. (default = '') # per_page: Posts displayed per page. (0 = disable pagination) # order_by: Posts order. (Order by date descending by default) index_generator: path: '' per_page: 3 #number of articles per page order_by: -date # Category & amp; Tag categories and tags default_category: uncategorized category_map: tag_map: # Date / Time format date / time format ## Hexo uses Moment.js to parse and display date ## You can customize the date format as defined in ## http://momentjs.com/docs/#/displaying/format/ date_format: YYYY-MM-DD time_format: HH:mm:ss # Pagination archive display ## Set per_page to 0 to disable pagination per_page: 10 pagination_dir: page # Extensions extension ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: next # Deployment ## Docs: https://hexo.io/docs/deployment.html deploy: type: git #deployment type repository: https://github.com/AAAAAAA/AAAAAAA.github.io.git #warehouse address branch: master #branch name message: hexo deploy #submit information #Search search: path: search.xml field: post format: html limit: 10000
Note
: The.yml
file has strict format requirements. All configurations in the file are: colon space value, and the colon is the input in English. If you want to know more, you can go to the official website. -
In the blog directory, right-click Git Bash, enter the command window, enter the following command, and you can see the content you just set is displayed on the page in the browser:
hexo server // abbreviated as hexo s
Submit to the remote warehouse to report an error
Report 403 or enter the account password every time you submit
You can put _config.yml
in
repository: https://github.com/********.github.io.git #warehouse address
Change to:
repository: [email protected]:********.github.io.git #warehouse address
Originality is not easy, please indicate the source of this article and the link to the original article when reprinting.
Like it, if this article is helpful to you, please give it a like, it will be the driving force for my creation!
Bookmark, if you think this article is of reference value, please bookmark it for future reading.
Comments, welcome to share your thoughts and suggestions with me in the comment area, it will be my greatest support and encouragement.