1
+ # frozen_string_literal: false
2
+
1
3
module JekyllImport
2
4
module Importers
3
5
class Pebble < Importer
@@ -8,34 +10,32 @@ def self.require_deps
8
10
) )
9
11
end
10
12
11
- def self . specify_options ( c )
13
+ def self . specify_options ( c )
12
14
c . option "directory" , "--directory PATH" , "Pebble source directory"
13
15
end
14
16
15
17
def self . process ( opts )
16
- options = {
17
- directory : opts . fetch ( "directory" , "" )
18
- }
18
+ options = { directory => opts . fetch ( "directory" , "" ) }
19
19
20
20
FileUtils . mkdir_p ( "_posts" )
21
21
FileUtils . mkdir_p ( "_drafts" )
22
22
23
23
traverse_posts_within ( options [ :directory ] ) do |file |
24
- next if file . end_with? ( 'categories.xml' )
24
+ next if file . end_with? ( "categories.xml" )
25
+
25
26
process_file ( file )
26
27
end
27
28
end
28
29
29
- def self . traverse_posts_within ( directory , &block )
30
+ def self . traverse_posts_within ( directory , &block )
30
31
Dir . foreach ( directory ) do |fd |
31
32
path = File . join ( directory , fd )
32
- if fd == '.' || fd == '..'
33
+ if fd . include? ( "." ) || fd . include? ( ".." )
33
34
next
34
- elsif File . directory? ( path )
35
+ elsif File . directory? ( path )
35
36
traverse_posts_within ( path , &block )
36
- elsif path . end_with? ( ' xml' )
37
+ elsif path . end_with? ( " xml" )
37
38
yield ( path ) if block_given?
38
- else
39
39
end
40
40
end
41
41
end
@@ -46,17 +46,17 @@ def self.process_file(file)
46
46
47
47
doc = xml . xpath ( "blogEntry" )
48
48
49
- title = kebabize ( doc . xpath ( ' title' ) . text ) . gsub ( '_' , '-' )
50
- date = Date . parse ( doc . xpath ( ' date' ) . text )
49
+ title = kebabize ( doc . xpath ( " title" ) . text ) . tr ( "_" , "-" )
50
+ date = Date . parse ( doc . xpath ( " date" ) . text )
51
51
52
52
directory = "_posts"
53
- name = "#{ date . strftime ( ' %Y-%m-%d' ) } -#{ title } "
53
+ name = "#{ date . strftime ( " %Y-%m-%d" ) } -#{ title } "
54
54
55
55
header = {
56
- "layout" => ' post' ,
57
- "title" => doc . xpath ( "title" ) . text ,
58
- "tags" => doc . xpath ( "tags" ) . text . split ( ", " ) ,
59
- "categories" => doc . xpath ( ' category' ) . text . split ( ', ' )
56
+ "layout" => " post" ,
57
+ "title" => doc . xpath ( "title" ) . text ,
58
+ "tags" => doc . xpath ( "tags" ) . text . split ( ", " ) ,
59
+ "categories" => doc . xpath ( " category" ) . text . split ( ", " ) ,
60
60
}
61
61
header [ "render_with_liquid" ] = false
62
62
@@ -71,17 +71,17 @@ def self.process_file(file)
71
71
end
72
72
73
73
def self . kebabize ( string )
74
- kebab = '-' . freeze
75
- string . gsub! ( / [^\w \- _]+/ , kebab )
74
+ kebab = "-" . freeze
75
+ string . gsub! ( %r! [^\w \- _]+! , kebab )
76
76
77
77
unless kebab . nil? || kebab . empty?
78
78
if kebab == "-" . freeze
79
- re_duplicate_kebab = / -{2,}/
80
- re_leading_trailing_kebab = / ^-|-$/
79
+ re_duplicate_kebab = %r! -{2,}!
80
+ re_leading_trailing_kebab = %r! ^-|-$!
81
81
else
82
82
re_sep = Regexp . escape ( kebab )
83
- re_duplicate_kebab = / #{ re_sep } {2,}/
84
- re_leading_trailing_kebab = / ^#{ re_sep } |#{ re_sep } $/
83
+ re_duplicate_kebab = %r! #{ re_sep } {2,}!
84
+ re_leading_trailing_kebab = %r! ^#{ re_sep } |#{ re_sep } $!
85
85
end
86
86
# No more than one of the kebab in a row.
87
87
string . gsub! ( re_duplicate_kebab , kebab )
0 commit comments