自建hexo博客并将原有的文章发布其上

1、保存粘贴到memo9中的博客文章,并将txt转换成word文档

var
  PowerShellPath, CommandLine: string; //  , ScriptPath
begin
     //save to txt
  Memo9.Lines.SaveToFile('test.txt');
  memo10.Lines.SaveToFile('txt2word.ps1');
     //save as docx
  PowerShellPath := 'powershell.exe ';
  CommandLine := 'C:\delphisource\mytools\mynewtools\Win64\Debug\txt2word.ps1 ';
  DosCommand3.CommandLine := PowerShellPath + ' -ExecutionPolicy Bypass -File ' + CommandLine;
  DosCommand3.Execute;

end;

txt2word.ps1代码 

$word = New-Object -ComObject word.application
$doc = $word.documents.open("C:\delphisource\mytools\mynewtools\Win64\Debug\test.txt")
$doc.saveas("C:\delphisource\mytools\mynewtools\Win64\Debug\test.docx",16)
$doc.close()
$word.quit()

2、使用pandoc将word文档转换成md文档 

begin
    //pandoc word2md
  DosCommand3.CommandLine := 'pandoc -s C:\delphisource\mytools\mynewtools\Win64\Debug\test.docx -t markdown -o C:\delphisource\mytools\mynewtools\Win64\Debug\test.md';
     // 启动进程
  DosCommand3.Execute;
  exit;

end;

3、使用hexo新建博客文章

begin
 // newblogs bash command file

  Memo11.Lines.Add('hexo new "' +UTF8Encode(edit9.Text) + '"');
  Memo11.Lines.SaveToFile('C:\pythoncode\new\test.sh');
  DosCommand3.CommandLine := '"C:\Program Files\Git\bin\bash.exe"  C:\pythoncode\new\test.sh';
     // 启动进程
  DosCommand3.Execute;

end;

test.sh脚本

#!/bin/bash

# �л���ָ��Ŀ¼
cd C:/Users/86182/myblog/source/_posts

# ����Hexo����
hexo new "Python中的PDF文本提取:使用fitz和wxPython库(带进度条�?

4、将第二步产生的md文档,复制到指定文件夹下,并替换新建的博客md文档

begin
  Memo12.Lines.Add('mv "c:/Users/86182/myblog/source/_posts/test.md" "c:/Users/86182/myblog/source/_posts/'+UTF8Encode(Edit9.Text)+'.md"');
  Memo12.Lines.SaveToFile('C:\pythoncode\new\test4.sh');
  DosCommand3.CommandLine := '"C:\Program Files\Git\bin\bash.exe"  C:\pythoncode\new\test4.sh';
     // 启动进程
  DosCommand3.Execute;
end;

 test4.sh代码

#!/bin/bash

# �����ļ�
cp "c:/delphisource/mytools/mynewtools/Win64/Debug/test.md" "c:/Users/86182/myblog/source/_posts"

# ������Ŀ���ļ�
mv "c:/Users/86182/myblog/source/_posts/test.md" "c:/Users/86182/myblog/source/_posts/探索硬件王国:计算机硬件信息一览(使用powershell获得计算机硬件信息).md"

5、hexo将刚刚新增并编辑好的md文档生成。

begin

  DosCommand3.CommandLine := '"C:\Program Files\Git\bin\bash.exe"  C:\pythoncode\new\test1.sh';
     // 启动进程
  DosCommand3.Execute;
end;

test1.sh代码

#!/bin/bash

cd C:/Users/86182/myblog/source/_posts

hexo generate 

6、hexo 启动服务器(注意先关闭)

begin
  DosCommand3.CommandLine := '"C:\Program Files\Git\bin\bash.exe"  C:\pythoncode\new\test3.sh';
     // 启动进程
  DosCommand3.Execute;
end;

test3.sh代码

#!/bin/bash

cd C:/Users/86182/myblog/source/_posts

hexo server

结果如下

 

你可能感兴趣的:(bash,TDOSCommand,delphi,pandoc,hexo,powershell)