Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

外部的.md无法生成 #93

Open
Nataila opened this issue May 4, 2017 · 6 comments
Open

外部的.md无法生成 #93

Nataila opened this issue May 4, 2017 · 6 comments

Comments

@Nataila
Copy link

Nataila commented May 4, 2017

外部转移过来的md文件,没法生成,需要挨个添加title之类的头部信息才能生成,有时间搞个默认的title之类的,糟心啊土豪

@tankywoo
Copy link
Owner

tankywoo commented May 4, 2017

@Nataila 别胡闹,默认 title 怎么定?你写个脚本改一下啊……

@Nataila
Copy link
Author

Nataila commented May 11, 2017

@tankywoo 默认文件名?

@Xuanwo
Copy link
Contributor

Xuanwo commented May 13, 2017

其实可以考虑做迁移插件

@tankywoo
Copy link
Owner

@Nataila 如果依赖文件名,需要文件名非常准确,比如以减号分隔单词。

@Xuanwo 等有需求时可以考虑。

@gitGksgk
Copy link

gitGksgk commented Sep 1, 2017

@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"

@himao
Copy link

himao commented Nov 18, 2017

简单拼凑的一个添加页面头信息的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"

有几个问题:

  1. 处理名称包含空格的文件或目录可能有问题;
  2. 简单使用当前时间作为创建时间和最后修改时间,可考虑使用ctime和mtime代替;
  3. 多级目录考虑处理为集合或标签字段,仅仅是个想法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants