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
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/jekyll_build_search.rb', line 27
def build_post_hashes(post, converter)
post_hashes = []
curr_post = nil
curr_hash = {}
curr_hash["content"] = []
converted_lines = post.content.split("\n").map do |line|
curr_hash["content"] << line
in_code_block = !in_code_block if line.match(/^```/)
next line if in_code_block
matched = line.match(/^(#+) /)
next line unless matched
DateTime.parse(line.strip) rescue next line
date = DateTime.parse(line.strip)
yearmonth = date.strftime("%Y_%m")
iddate = date.strftime("%Y%m%d")
displaydate = date.strftime("%b %e, %Y")
curr_hash["content"].pop()
tags = line.strip.scan(/#([a-zA-Z0-9._-]{3,} ?)/).flatten(1)
if !curr_post.nil?
curr_hash["content"] = converter.convert(curr_hash["content"].join("\n"))
post_hashes << curr_hash
end
curr_hash = {}
curr_hash["content"] = []
curr_hash["title"] = displaydate
curr_hash["url"] = "/log/#{yearmonth}/##{iddate}"
curr_hash["tags"] = tags
curr_post = date
end
return post_hashes
end
|