<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>leo424y (Yang-Hsiang Chang)</title>
    <link>https://ruby-china.org/leo424y</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>DIY Markdown 切檔代碼</title>
      <description>&lt;p&gt;Myblog &lt;a href="http://leo424y.github.io" rel="nofollow" target="_blank"&gt;http://leo424y.github.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;此档案可以将一文字档单档切成 Github Page 用的 Markdown 档案，可方便直推 Github BLOG 如 &lt;a href="https://jekyllrb.com/" rel="nofollow" target="_blank"&gt;https://jekyllrb.com/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="v1.0.1105"&gt;v1.0.1105&lt;/h2&gt;&lt;h2 id="TODO 重构，通用化，对不起它很脏XD"&gt;TODO 重构，通用化，对不起它很脏 XD&lt;/h2&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 将此档另存后执行 $ ruby spliter.rb 即将同资料夹内的 "-2016-11-05-.md" 切出下面格式档案
# -2016-11-05-.md
# 事实
# 就是一切发生的事，众人认同的事
# xxx
# 情感
# 就是你看一切的看法
#
# 档案一.md
# ---
# layout: post
# comments: true
# title: 事实
# ---
# 就是一切发生的事，众人认同的事
#
# 档案二.md
# ---
# layout: post
# comments: true
# title: 情感
# ---
# 就是你看一切的看法
&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def chunker(f_in, out_pref)
  # 切档记号
  splitter = 'xxx'

  File.open(f_in, 'r') do |fh_in|
    $title = ''
    filename = 1
    until fh_in.eof?
      unless File.exist?("#{out_pref}#{$title}#{filename}.md")
        File.open("#{out_pref}#{filename}.md", 'w+') do |fh_out|
          $title = fh_in.readline.chomp!
          File.rename("#{out_pref}#{filename}.md", "#{out_pref}#{$title}#{filename}.md")

          head = &amp;lt;&amp;lt;HEAD
---
layout: post
comments: true
title: #{$title}
---
HEAD
          fh_out &amp;lt;&amp;lt; head
          puts '写进head'
        end
      end
      puts "&amp;gt;&amp;gt;打开#{filename}.md"
      # File https://www.tutorialspoint.com/ruby/ruby_input_output.htm
      File.open("#{out_pref}#{$title}#{filename}.md", 'a+') do |fh_out|
        line_context = fh_in.readline
        puts '下一行'
        # 碰到splitter开新档案
        if line_context == "#{splitter}\n"
          filename += 1
          puts "&amp;gt;&amp;gt;换至#{filename}.md"
        else
          fh_out &amp;lt;&amp;lt; line_context
          puts "&amp;gt;&amp;gt;写进#{line_context}"
        end
      end
    end
  end
end
today = Time.now.to_s.split(' ')[0]

chunker "-#{today}-.md", "#{today}-"
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>leo424y</author>
      <pubDate>Sat, 05 Nov 2016 23:50:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/31530</link>
      <guid>https://ruby-china.org/topics/31530</guid>
    </item>
  </channel>
</rss>
