VSCODE写HEXO博客时自动插入FrontMatter的实现

首先点VSCODE文件->首选项->用户片段,在弹出来的对话框中选择markdown.json。输入以下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
	"Hexo Front Matter": {
		"prefix": "---", # 触发代码块的输入字符
		"body": [
			"---",
			"title: ${TM_FILENAME_BASE}", # 自动将文件名作为标题
			"date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}", # 自动输入当前时间
			"update: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}", # 自动输入当前时间
			"tags:",
			"  - ",
			"  - ",
			"categories:",
			"  - ",
			"  - ",			
			"description: ",
			"cover: ",
			"keywords: ",
			"---\r"
		],
		"description": "Hexo Front Matter"
	}
}

然后在VSCODE的设置中添加配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
"[markdown]": {
        "editor.formatOnSave": true,
        "editor.renderWhitespace": "all",
        "editor.quickSuggestions": {
            "other": true,
            "comments": true,
            "strings": true
        },
        "editor.acceptSuggestionOnEnter": "on"
    }

经过以上两个步骤后,用VSCODE写hexo博客,只需要在hexo的source_post目录下新建markdown文件,并输入文件名,此时在编辑器中输入---,VSCODE将弹出自动补全的窗口,选中回车即可输入以下内容,省去了人工输入大量Front Matter信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
---
      
<!--more-->
title: VSCODE写HEXO博客时自动插入FrontMatter的实现
date: 2021-08-20 12:47:39
update: 2021-08-20 12:47:39
tags:
  - 
  - 
categories:
  - 
  - 
description: 
cover: 
keywords: 
---
      
<!--more-->