_ Batch script to modify md hexo standard post format [Bo]

 

Motivation, hope quickly release the original md

Notes that there would have been as md format, hoping to batch release. Rather than one by one hexo new page xxx, and then copy the past, too slow, and each modification requires manual md in the corresponding hexo inside the modified once.
However, due to the vnote notes and hexo format required md format is not exactly the same, so it is necessary to develop the script modifies vnote md internal format is consistent and hexo internal md format.
POST hexo standard text format addition md, more than information in the header of the following format

 

1
2
3
title: 笔记工具比较
date: 2019-11-30 13:21:23
tags:

For existing notes
to be: hexo new post xxx template generation md => text merge template => Publish and tedious! !
Scripts to increase the use of the prefix here, md generated directly copy to hexo can be.

Script 1, consistent with the article title and modify the path md

For example: "Amy's diary .md"
first line of the inside (ie, the title), the "# Amy's diary:"
File Path and the title of the article inconsistent on hexo will result list page title and page title text inconsistent strange phenomenon. And, personally I think that this is not a good habit. Take Coke bottle holds Sprite, although can drink, but always awkward.

 

1
2
3
sed -i '1d' *.md        #删除首行内容(如果之前md文件没有标题,则不执行这一步)
sed -i '1i\# ' *.md     #新增首行内容(# (和一个空格))
for f in *.md ;do sed -i "1 s/$/${f%.*}/"  $f ;done;#将文件名追加到首行的# 后面(就是md的标题)

Md ensure consistent execution after the file name and internal header name.

Script 2, add hexo the post template prefix information

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
需要添加的前缀,行首的01,02是为了方便标识添加的。实际不存在。
01 ---
02 title: 笔记工具比较
03 date: 2019-11-30 13:21:23
04 tags:
05 ---

脚本内容;
sed -i '1i\---' *.md    #对应05的---
sed -i '1i\tags:' *.md    #对应04
sed -i '1i\date: 2019-11-30 00:00:01' *.md #对应03
sed -i '1i\title: ' *.md    #对应02的前半个
for f in *.md ;do sed -i "1 s/$/${f%.*}/"  $f ;done;# 对应02的后半个,文件名部分
sed -i '1i\---' *.md    #对应01

To sum up the final script: batch execution (ctrl-v) to the terminal. * .Md can process all files in a folder under.

Script 3, vnote of md format to hexo format (icarus topics applicable) (github)

Address script GitHub: https://github.com/yuanjh6/scripts

The vnote of md md format into a format hexo
vnote original file:
Path: xxx / vnote / living / diary 20200328.md
content:

 

1
2
3
4
5
# 天气晴,32度,心情好
## 张三给我拳头
xxxxyyyyzzz
## 我打李四一巴掌
fffzzkkk

Execute: python md2hexo.py xxx / vnote / living / diary 20200328.md
adds title information in the new md after conversion here

 

1
2
3
4
5
title:日记20200328(注意:title其实是文件名)
date: 2020-03-01 16:18:26
categories: ['xxx','vnote','生活'](注意:这里即使就是文件的路径,切分)
tags: ['']
toc: true

Body parts:

 

1
2
3
4
## 张三给我拳头  
xxxxyyyyzzz  
## 我打李四一巴掌  
fffzzkkk

Title idea body part did not, because I am using icarus template, which is also recognized by the head of the title: xxxx here as the title, if the following are the title, the display is the double title, leading to confusion format
if you are using a template Next, is different, the need to change the code a little, holding the body of the first row header
using a method for file: python md2hexo.py xxxx / yyy.md
using method 2, to the directory: python md2hexo.py xxxx / yyyy / zzz /
use 3, and a plurality of files and directories: python md2hexo.py xxxx / yyy.md xxxx / yyyy / zzz / xxxx / yyyy / fff /

Special Instructions:
01, the Categories article is actually a file path segmentation, so before executing the script, md2hexo.py file location and the best md file or folder at the same level position
such as: script location: / xxx / yyy / zzz / md2hexo. py
your md file location: / fff / mmm / kkk / vnote / living / diary 20200328.md
at this point if you are in the path: execute script / xxx / yyy / zzz / under, python md2hexo.py / fff / mmm / kkk / vnote / living / diary 20200328.md
such categories, then md file is, fff, mmm, kkk, vnote , life, but in most cases, fff, mmm, may be useless, such as home / username / no, etc. meaning
it is proposed, will md2hexo.py put / fff / mmm / kkk / vnote / under execution in / fff / mmm / kkk / vnote / under: python md2hexo.py living / diary 20200328.md
such technology to produce categories of articles, compared with [ 'life'], in line with the intention of
following commands are:
1, md copy md2hexo.py to the folder / home / john / documents / vnote_notebooks / vNote /
2, where in the file folder outside the execution md md2hexo.py $ Python (LS the -I  v recycle_bin)
3, delete step 1 copied md2hexo.py script file
is recommended before a single step Under execution, look at what effect the various commands, avoiding wrong, but also to modify the .md file

 

1
cp md2hexo.py /home/john/文档/vnote_notebooks/vnote/ && cd /home/john/文档/vnote_notebooks/vnote/ && python md2hexo.py $(ls -I _v_recycle_bin) && rm md2hexo.py

02, read the code can be found for the title of the article (that is, the file name) if it contains [secret] is automatically increased field password: xxxxyyyy, add a password in order to achieve the article, no password can not access (with plug-ins required hexo)

Published 238 original articles · won praise 144 · views 860 000 +

Guess you like

Origin blog.csdn.net/u011331731/article/details/105189745