Featured image of post WingerBlog2.0一期:本地自动上传

WingerBlog2.0一期:本地自动上传

  1. 找到PATH文件夹中.md结尾的文件,记下文件名self,读入文件
  2. 读取第一行获得所有的tags[]
  3. 向文件头写入
1
2
3
4
5
6
7
8
9
---
title: {self}
date: {fileGeneratedDate}
update: {currentDate}
tags:
	- {tags[0]}
	- {tags[1]}
	- {tags[2]}
---
  1. 找到PATH2,运行hexo new {self}
  2. 找到PATH3,把 self.md 进行替换
  3. 将PATH1中剩余的全部文件mv到PATH3中的self文件夹
  4. 在PATH2中运行hexo clean && hexo g -d

python源码:download

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os,time,datetime
from os import listdir
from os.path import isfile, join
import re

PATH = '/Users/******/Documents/Blog-drafts'
PATH2 = '/Users/******/Documents/Blog'
PATH3 = '/Users/******/Documents/Blog/source/_posts/'
filename = "NAN"


####################################################

onlyfiles = [f for f in listdir(PATH) if isfile(join(PATH, f))]


for f in onlyfiles:
    if f[-3:] == ".md":
        filename = f[:-3]

if(filename == "NAN"):
    print("未找到.md文件,请重试!")
    exit(0)

##############################################

file0 = PATH+"/"+filename+".md"

file = open(file0)

wholestring= ""

cnt = 0
for i in file:
    if cnt == 0:
        i = i.strip()
        tags = re.split(',| |,',i)
        cnt+=1
    else:
        wholestring+=i

file.close()



########################################


fileCreatTime = str(datetime.datetime.fromtimestamp(os.stat(file0).st_ctime))
fileModTime = str(datetime.datetime.fromtimestamp(os.stat(file0).st_mtime))

os.system(f"rm {file0}")


text = f'''---
title: {filename}
date: {fileCreatTime[:-7]}
tags:
'''

# if fileCreatTime[:-7] != fileModTime[:-7] :
#     text+=f'''
#     update: {fileModTime[:-7]}
#     '''


#
#
# text+='''
# tags:
# '''

#######################
for i in tags:
    text+=f'''    - {i}
'''
#######################
text+=f'''
---
'''
###################
print(text)

os.system(f"cd {PATH2} && hexo new {filename}")

PATH3filename = PATH3 + filename.replace('.','-')

with open(f"{PATH3filename}.md","w") as lastfile:
    lastfile.write(text)
    lastfile.write(wholestring)
    lastfile.close()

########################

os.system(f"mv {PATH}/* {PATH3filename}/")
os.system(f"cd {PATH2} && hexo g -d")
Built with Hugo
主题 StackJimmy 设计