Basic use of HEXO

1 Create, edit and preview articles

1. Create a new article

hexo new [layout] title       # 或 hexo n [layout] title

        Before creating an article, you must first select a template, which is also called a layout in hexo. Hexo supports three layouts: post (default), draft, and page. We will first introduce how to use an existing layout, and later we will introduce how to customize the layout.

        When you enter the following command in the blog directory, the post layout will be used by default, and then a text1.md file will be automatically generated in the source\_posts directory:

hexo n text1

        Of course you can also specify the layout:

hexo n [layout_name] draft1

        This command creates an article named draft1 using a specific layout.

        Opening the text1.md file created previously, we can see that the beginning of the article contains the following content:

---
title: text1
date: 2020-04-10 04:13:36
tags: hexo
categories: blog
---

        The content you display may not be the same as mine, don’t worry, this is because I have customized it. You just need to know that the above content is called Front-matter in hexo, which is actually some variables of this article, used to implement some specific functions.

        How to customize the layout? In fact, the layout is a markdown file, which is saved in the scaffolds/ directory. You can see that the three layouts that come with hexo are actually three .md files:

        All articles are placed in the _posts directory under the source file in the main directory. Please refer to my storage directory here.D:\Blog\source\_posts

        Two points of explanation are made here:

        Directories can be created in this directory, and the system can identify articles in multi-layer folders to facilitate classification; if the new articles generated by using the command must be in the _posts main directory

        I use VSCode to write MarkDown, it’s very easy to use. Click on the created file to see what’s in it first.

---
title: 第一篇文章
date: 2023-06-08 10:30:00
---

        The content between the two dotted lines is called Front-matter, which is mainly the configuration of your article. The specific configuration is as follows. Different themes here are different. I will take the Next theme as an example.

        All content in the Front-matter options are optional. But I still recommend filling in at least the values ​​for title and date. Here are the predefined parameters that you can use and take advantage of in your templates.

parameter describe default value
layout layout config.default_layout
title title Article file name
date Creation date File creation date
updated Updated File update date
comments Enable comments on articles true
tags Labels (does not work with pagination)
categories Categories (does not apply to pagination)
permalink Cover the permanent link of the article, the permanent link should end with / or .html null
excerpt Plain text summary of the page. Use the plugin to format text
disableNunjucks Disable Nunjucks tags when enabled{ { }}/{% %} andtag plugins Rendering function false
lang Set language to override Automatic detection Inherited from_config.yml

Below is an example of Front-matter for an article.

---
title: 第一篇文章
date: 2023-06-08 10:30:00
img: /source/images/xxx.jpg
top: true
cover: true
coverImg: /images/1.jpg
password: ********************************
mathjax: false
description: 这是你自定义的文章摘要内容,如果这个属性有值,文章卡片摘要就显示这段文字,也可以使用 <!--more--> 强制截断
categories: Markdown
tags:
  - VSCode
  - Markdown
---

        You will find that every time hexo n there is very little content in Front-matter, so how to modify the default format? Just go to the main directory and find a post.md file in the scaffolds folder to modify. Here is my directoryD:\Blog\scaffolds\post.md, for example mine

---
title: {
    
    {
    
     title }}
date: {
    
    {
    
     date }}
author: Carpe Diem
# 标签
tags: 
# 分类
categories:
# 简述
description:
# 使用自定义封面 
img: 
# 是否置顶true,或者去掉
top: false
# 轮播
cover:
# 轮播图
coverImg: 
---

2 Only display article abstracts on the homepage

Method 1: Write an overview

        Add to front-matter of the article, and the content in will be displayed on the home page. The rest will not be displayed. descriptiondescription

---
title: 让首页显示部分内容
date: 2020-02-23 22:55:10
description: 这是显示在首页的概述,正文内容均会被隐藏。
---

        What is more inconvenient is that you have to write an overview. Many times you are too lazy to write an overview, so the second method is needed.

Method 2: Article truncation

        ​ ​ ​ Add where you need to truncate:

<!--more-->

        The home page will display all the content above this item and hide all the following content.

        This is obviously much more convenient, but of course it has pros and cons. For example, a homepage that is full of nonsense at the beginning will not look very good, so I usually choose method two first. If I feel that the writing at the beginning of the article is not very good, I will use method one.

おすすめ

転載: blog.csdn.net/xq151750111/article/details/133043466