Class: Article
- Inherits:
-
Object
- Object
- Article
- Defined in:
- lib/article.rb
Instance Method Summary collapse
-
#convert(relative_path) ⇒ Object
转换文件.
-
#initialize ⇒ Article
constructor
A new instance of Article.
Constructor Details
Instance Method Details
#convert(relative_path) ⇒ Object
转换文件
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/article.rb', line 22 def convert(relative_path) result = Hash.new file = File::join @setup.content_dir, relative_path #原始路径 result['file'] = file #路径的MD5值 result['relative_path_md5'] = Digest::SHA256.hexdigest(relative_path.to_s)[0..15] result['mtime'] = File::ctime file #读取原始内容 original = @util.read_file file result['original'] = original #相对路径 result['relative_path'] = relative_path result['relative_url'] = relative_path.to_s.gsub(/\.md$/, '.html') = @meta.analysis original = ['meta'] || {} body = ['body'] ['title'] = File::basename(file, '.md') if !['title'] ['publish_date'] = result['mtime'] if !['publish_date'] result['meta'] = result['body_markdown'] = body if body #创建markdown实例 markdown = Kramdown::Document.new(body) html = result['body_html'] = markdown.to_html result['excerpt'] = Nokogiri::HTML(html).text[0..99] #获取toc相关的内容 result['toc_html'] = @toc.to_html markdown.to_toc end result end |