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

文章介绍了使用PowerShell将TXT转换为Word文档,然后用Pandoc将Word转为Markdown,最后通过Hexo创建并发布博客文章的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

结果如下

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值