Skip to content

Commit

Permalink
Validate date and title better
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp committed Mar 20, 2021
1 parent 2873712 commit 6ee4042
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions bin/jekyll-planet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run( args )

Pluto.connect( @db_config )

Pluto::Model::Item.latest.where.not(title: '', published: nil).limit(1000).each_with_index do |item,i|
Pluto::Model::Item.latest.each_with_index do |item,i|
puts "[#{i+1}] #{item.title}"

generate_blog_post( item )
Expand All @@ -46,10 +46,28 @@ def generate_blog_post( item )

FileUtils.mkdir_p( posts_root ) ## make sure path exists

item.published = item.updated if item.published.nil?

content = item.content ? item.content : item.summary

if item.title == ''
item.title = Nokogiri::HTML::Document.parse(content).search('//text()').first if content
item.title = item.title.slice(0..(item.title.index('.'))) if item.title
item.title = item.title.slice(0..255) if item.title
end

return unless item.title && item.published && item.url && content

## Note:
## Jekyll pattern for blogs must follow
## 2014-12-21- e.g. must include trailing dash (-)
fn = "#{posts_root}/#{item.published.strftime('%Y-%m-%d')}-#{item.title.parameterize}.html"
if item.title.parameterize == ''
trailing = Digest::SHA2.hexdigest item.content if item.content
trailing = Digest::SHA2.hexdigest item.summary if item.summary
else
trailing = item.title.parameterize
end
fn = "#{posts_root}/#{item.published.strftime('%Y-%m-%d')}-#{trailing}.html"
# Check for author tags

data = {}
Expand All @@ -71,6 +89,7 @@ def generate_blog_post( item )
data[contact] = true
end
end if item.feed.author
data["original_link"] == data["link"] + data["original_link"] unless data["original_link"].include?('//')
frontmatter = generate_frontmatter(data)

File.open( fn, 'w' ) do |f|
Expand All @@ -79,14 +98,7 @@ def generate_blog_post( item )
f.write "---\n"

# There were a few issues of incomplete html documents, nokogiri fixes that
html = ""
if item.content
html = Nokogiri::HTML::DocumentFragment.parse(item.content).to_html
elsif item.summary
html = Nokogiri::HTML::DocumentFragment.parse(item.summary).to_html
else
## warn: not content found for feed
end
html = Nokogiri::HTML::DocumentFragment.parse(content).to_html
# Liquid complains about curly braces
html.gsub!("{", "{")
html.gsub!("{", "}")
Expand Down

0 comments on commit 6ee4042

Please sign in to comment.