Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix RuboCop #545

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exe/jekyll-import
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Mercenary.program(:jekyll_import) do |p|
p.action do |args, _|
if args.empty?
Jekyll.logger.error "An importer subcommand is required."
puts p
Jekyll.logger.info p
abort
else
subcommand = args.first
Expand Down
46 changes: 23 additions & 23 deletions lib/jekyll-import/importers/pebble.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: false

module JekyllImport
module Importers
class Pebble < Importer
Expand All @@ -8,34 +10,32 @@ def self.require_deps
))
end

def self.specify_options(c)
def self.specify_options(c)
c.option "directory", "--directory PATH", "Pebble source directory"
end

def self.process(opts)
options = {
directory: opts.fetch("directory", "")
}
options = { directory => opts.fetch("directory", "") }

FileUtils.mkdir_p("_posts")
FileUtils.mkdir_p("_drafts")

traverse_posts_within(options[:directory]) do |file|
next if file.end_with?('categories.xml')
next if file.end_with?("categories.xml")

process_file(file)
end
end

def self.traverse_posts_within(directory, &block)
def self.traverse_posts_within(directory, &block)
Dir.foreach(directory) do |fd|
path = File.join(directory, fd)
if fd == '.' || fd == '..'
if fd.include?(".") || fd.include?("..")
next
elsif File.directory?(path)
elsif File.directory?(path)
traverse_posts_within(path, &block)
elsif path.end_with?('xml')
elsif path.end_with?("xml")
yield(path) if block_given?
else
end
end
end
Expand All @@ -46,17 +46,17 @@ def self.process_file(file)

doc = xml.xpath("blogEntry")

title = kebabize(doc.xpath('title').text).gsub('_', '-')
date = Date.parse(doc.xpath('date').text)
title = kebabize(doc.xpath("title").text).tr("_", "-")
date = Date.parse(doc.xpath("date").text)

directory = "_posts"
name = "#{date.strftime('%Y-%m-%d')}-#{title}"
name = "#{date.strftime("%Y-%m-%d")}-#{title}"

header = {
"layout" => 'post',
"title" => doc.xpath("title").text,
"tags" => doc.xpath("tags").text.split(", "),
"categories" => doc.xpath('category').text.split(', ')
"layout" => "post",
"title" => doc.xpath("title").text,
"tags" => doc.xpath("tags").text.split(", "),
"categories" => doc.xpath("category").text.split(", "),
}
header["render_with_liquid"] = false

Expand All @@ -71,17 +71,17 @@ def self.process_file(file)
end

def self.kebabize(string)
kebab = '-'.freeze
string.gsub!(/[^\w\-_]+/, kebab)
kebab = "-".freeze
string.gsub!(%r![^\w\-_]+!, kebab)

unless kebab.nil? || kebab.empty?
if kebab == "-".freeze
re_duplicate_kebab = /-{2,}/
re_leading_trailing_kebab = /^-|-$/
re_duplicate_kebab = %r!-{2,}!
re_leading_trailing_kebab = %r!^-|-$!
else
re_sep = Regexp.escape(kebab)
re_duplicate_kebab = /#{re_sep}{2,}/
re_leading_trailing_kebab = /^#{re_sep}|#{re_sep}$/
re_duplicate_kebab = %r!#{re_sep}{2,}!
re_leading_trailing_kebab = %r!^#{re_sep}|#{re_sep}$!
end
# No more than one of the kebab in a row.
string.gsub!(re_duplicate_kebab, kebab)
Expand Down