没有输出的输入是不完整的

0%

create-my-leetcode-artical-template

在我每次写leetcode解题文章的时候,经常需要搞排版信息,一次两次还好,但是次数多了就会比较烦。那么我们能不能自定义一个属于自己的leetcode文章模版呢?当然可以!于是就有了本篇文章。

原理

从创建文章说起

我们在使用如下命令创建文章的时候,

1
hexo new title

实际上我们使用的是如下的命令

1
hexo new post title

上面的命令是这个命令的缩写形式而已,因为一般搭建都不太会创建草稿(draft)或者页面(page),大家都是创建文章,它太常用了,所以就被设置成了默认选项。

真实的创建命令

那么真实使用的创建命令是什么呢?其实是下面这个。

1
hexo new [layout] <title>

根据官方文档显示,hexo默认的layout有三种,分别是post,draft,page,他们都有自己的默认样式,他们文件本身都在scaffolds目录下面。

1
2
3
4
5
➜  blog ls -l scaffolds 

-rw-r--r-- 1 liqingwen staff 33 10 18 21:52 draft.md
-rw-r--r-- 1 liqingwen staff 44 10 18 21:52 page.md
-rw-r--r-- 1 liqingwen staff 76 10 21 16:48 post.md

在新建文章时,Hexo 会根据 scaffolds 文件夹内相对应的文件来建立文件,所以我们要想创建自己的模版,只要在这里面创建一个leetcode模板即可,然后以后就可以通过如下命令

1
hexo new leetcode leetcode-number-nanme

来创建符合对应布局的文章啦。

动手

  1. 先查看模版中的文件有哪些
1
2
3
4
5
➜  blog ls -l scaffolds 

-rw-r--r-- 1 liqingwen staff 33 10 18 21:52 draft.md
-rw-r--r-- 1 liqingwen staff 44 10 18 21:52 page.md
-rw-r--r-- 1 liqingwen staff 76 10 21 16:48 post.md
  1. 查看我们常用的post模板中的内容,然后我们照着这个改写就可以啦。
1
2
3
4
5
6
7
8
9
## 查看模版中内容
➜ blog cat scaffolds/post.md
---
title: {{ title }}
date: {{ date }}
tags:
- tag1
categories:
- cat1
  1. 复制一份post,重命名为leetcode,然后将我们想要的东西都加进去,然后保存即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
➜  blog cd scaffolds 
➜ scaffolds cp post.md leetcode.md
➜ scaffolds ls
draft.md leetcode.md page.md post.md

# 注意这里我使用的是sublime编辑器,然后在文档中添加的内容已经通过后面的cat输出了,大家可以直接赋值。
➜ scaffolds subl leetcode.md

➜ scaffolds ls
draft.md leetcode.md page.md post.md
➜ scaffolds cat leetcode.md
---
title: {{ title }}
date: {{ date }}
tags:
- leetcode
- hard,medium,easy
- Greedy, DP, String
categories:
- 算法训练
---
摘要内容
<!--more-->

## 题目描述
### sample1
## 解题思路
## 巧妙之处
## 解题代码
  1. 尝试使用leetcode模版
1
2
3
4
➜  scaffolds cd ..
➜ blog hexo new leetcode "leetcode-406-QueueReconstructionbyHeight"
INFO Created: ~/workplace/blog/source/_posts/leetcode-406-QueueReconstructionbyHeight.md
➜ blog subl source/_posts/leetcode-406-QueueReconstructionbyHeight.md

大功告成,于是就可以可以很开心的写文章啦。

  1. 2019-11-12更新
    1. 为了更加的解释算法过程,特地添加了详细解释部分。
    2. 为了更好的体现算法的演进,特地添加了算法升级部分。
      升级之后结果如下。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
title: {{ title }}
date: {{ date }}
tags:
- leetcode
- hard
- medium
- easy
- Greedy;
- DP
- String
categories:
- 算法训练
---
摘要内容
<!--more-->

## 题目描述
### Sample
## 解题思路
## 详细解释
## 巧妙之处
## 解题代码
### 原始代码
### 升级代码
以上,本题结束!