Skip to content

Commit 2ebffa7

Browse files
committed
extract row
1 parent de3d276 commit 2ebffa7

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎_plugins/generators.rb‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module Jekyll
2-
class RSSGenerator < Generator
1+
module RSS
2+
class Generator < Jekyll::Generator
3+
ROW_MATCHER = /^-\s*\[(?<title>[^\]]+)\]\((?<url>[^)]+)\){:\s*.article(?<data>(\s*data-\w+="[^"]+")+)\s*}\s*$/
4+
DATA_MATCHER = /data-(?<key>\w+)="(?<value>[^"]+)"/
35
def generate(site)
46
@index_page = site.pages.find { |page| page.name == "index.md" }
57
@feed_page = site.pages.find { |page| page.name == "feed.xml" }
@@ -12,21 +14,26 @@ def generate(site)
1214
def articles
1315
unless @articles
1416
@articles = []
15-
rows = @index_page.content.split(/#articles\s*}\n\n/).last.split(/## \[동영상\]/).first.split(/\n/)
1617
rows.each do |row|
17-
@articles << {}
18-
m = row.match(/^-\s*\[(?<title>[^\]]+)\]\((?<url>[^)]+)\){:\s*.article(?<data>(\s*data-\w+="[^"]+")+)\s*}\s*$/)
19-
@articles.last["title"] = m[:title]
20-
@articles.last["url"] = m[:url]
21-
m[:data].scan(/data-(?<key>\w+)="(?<value>[^"]+)"/) do |key, value|
22-
@articles.last[key] = value
18+
article = {}
19+
m = row.match(ROW_MATCHER)
20+
m[:data].scan(DATA_MATCHER) do |key, value|
21+
article[key] = value
2322
end
24-
if articles.last["tags"].include?("translated")
25-
@articles.last["title"] = "[번역] #{m[:title]}"
23+
if article["tags"].include?("translated")
24+
article["title"] = "[번역] #{m[:title]}"
25+
else
26+
article["title"] = m[:title]
2627
end
28+
article["url"] = m[:url]
29+
@articles << article
2730
end
2831
end
2932
@articles
3033
end
34+
35+
def rows
36+
@index_page.content.split(/#articles\s*}\n\n/).last.split(/## \[동영상\]/).first.split(/\n/)
37+
end
3138
end
3239
end

0 commit comments

Comments
 (0)