simiki
simiki copied to clipboard
外部的.md无法生成
外部转移过来的md文件,没法生成,需要挨个添加title之类的头部信息才能生成,有时间搞个默认的title之类的,糟心啊土豪
@Nataila 别胡闹,默认 title 怎么定?你写个脚本改一下啊……
@tankywoo 默认文件名?
其实可以考虑做迁移插件
@Nataila 如果依赖文件名,需要文件名非常准确,比如以减号分隔单词。
@Xuanwo 等有需求时可以考虑。
@Nataila windows 可以试试这个(在文章目录下保存为bat);需要有sed iconv,安装git设置环境变量就有. 把文件名作为标题,格式化为utf-8,且末尾添个.md;日期格式可能因不同格式有差异需要微调。 below's a bat file for windows, processing txt file or file without extension. It will automatically add filename (as title) and date to the head of the file and formalize to utf-8, meanwhile add .md to the end of each filename. Requires sed and iconv, which can be fetched by installing git and add git/usr/bin to environment path. Because sed and iconv are commands under linux, ni dong de. Notice, the file must be saved to the same directory of your txt files to take effect.
Because of different date format on various platform, date might need some adjustment. this file works fine when date output looks like 周一 2017/09/01 12:13
@echo off
set /p x="警告:将删除原有文件,请做好备份!继续吗?WARNING: THE ORINGIN FILE WILL BE PERMANENTLY MODIFIED, PLEASE LEAVE A BACKUP!! continue?(Y/N):"
if /i %x%==Y (
echo "执行中 processing"
) else (
echo "终止程序 exiting program"&pause&exit
)
chcp 65001
rem utf-8代码页
rem 需要sed iconv能正常运行
rem 仅能处理无后缀名或后缀为txt的文档
for /r . %%i in (*.*) do if "%%~xi" neq ".md" if "%%~xi" neq ".bat" sed -i "1i---\r\ntitle: \"%%~ni\"\r\ndate: %date:~3,4%-%date:~8,2%-%date:~11,2% %time:~0,5%\r\n---\r\n" "%%i" & type "%%i" > "%%i.md" & rm "%%i"
简单拼凑的一个添加页面头信息的shell脚本,供参考:
#! /bin/bash
dir=$1
date_str=`date "+%F %T"`
addFrontMatter(){
for i in `find $1 -name '*'`
do
if [ -d "$i" ]
then
#todo
echo "dir skip"
else
file_name=${i##*\/}
title=${file_name%.*}
sed -i "1i---\ntitle: \"$title\"\ndate: $2\nupdated: $2\n---\n\n[TOC]\n" "$i"
fi
done
}
addFrontMatter $dir "$date_str"
有几个问题:
- 处理名称包含空格的文件或目录可能有问题;
- 简单使用当前时间作为创建时间和最后修改时间,可考虑使用ctime和mtime代替;
- 多级目录考虑处理为集合或标签字段,仅仅是个想法