jekyll-blogger-generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7590917b93c7be32e78e3500b1a4528c23974e9c89d16727eda30e37b3676364
4
+ data.tar.gz: 5d8d1886a6d2a6ff929c57027b4574b6002b129fb05be00c3e0c3c17b716ee58
5
+ SHA512:
6
+ metadata.gz: 41264182e4e1acfe7adb01610075e9d0059bc133d7eec293447de6ac75b494b7bdbbb49eb0eb8616c11b3d338e702be6576222aaf5d4358b662e33b6302c9e21
7
+ data.tar.gz: 67b51942ea58a1d939201651d81e4852235f178f2fab1f685fa2fb67a58ce95b6c62d40ae17a1fdaa318ef41b8378867f8026d808387bcf246c8e8ed279917c6
@@ -0,0 +1,6 @@
1
+ require 'jekyll-blogger-generator/version'
2
+ require 'jekyll/blogger_document'
3
+ require 'jekyll/blogger_generator'
4
+
5
+ module JekyllBloggerGenerator
6
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllBloggerGenerator
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ module Jekyll
2
+ class BloggerDocument < Document
3
+ require 'active_support/core_ext/hash/keys'
4
+
5
+ def initialize(post, relations = {})
6
+ @post = post
7
+ @category = relations[:blog_url][/^https?:\/\/([^.]+)\./, 1]
8
+
9
+ super(post.url.sub(/.*\//, "#{@category}/_#{relations[:collection].label}/"), relations)
10
+ end
11
+
12
+ def source_file_mtime
13
+ Time.parse(@post.updated)
14
+ end
15
+
16
+ def read_content(**opts)
17
+ self.content = @post.content
18
+ merge_data!(@post.to_h.deep_stringify_keys, source: 'Blogger')
19
+ data.delete('content')
20
+ merge_data!({
21
+ 'categories' => [@category],
22
+ 'date' => @post.published,
23
+ 'draft' => data['status'].eql?('DRAFT'),
24
+ 'excerpt_separator' => '<!--more-->',
25
+ 'tags' => @post.labels
26
+ }, source: 'Blogger')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ module Jekyll
2
+ class BloggerGenerator < Generator
3
+ require 'active_support/core_ext/hash/keys'
4
+ require 'google/apis/blogger_v3'
5
+
6
+ def initialize(config = {})
7
+ @config = config
8
+ @blogger = Google::Apis::BloggerV3::BloggerService.new
9
+ @blogger.key = blogger_config['key']
10
+ super
11
+ end
12
+
13
+ def generate(site)
14
+ read_blog(
15
+ site,
16
+ @blogger.get_blog_by_url(blogger_config['url']),
17
+ blogger_config['list_post_parameters']
18
+ ) if blogger_config['url']
19
+
20
+ blogger_config['urls'].each do |url|
21
+ if url.is_a?(Hash)
22
+ read_blog(site, @blogger.get_blog_by_url(url['url']), url['list_post_parameters'] || blogger_config['list_post_parameters'])
23
+ else
24
+ read_blog(site, @blogger.get_blog_by_url(url), blogger_config['list_post_parameters'])
25
+ end
26
+ end if blogger_config['urls']
27
+ end
28
+
29
+ private
30
+
31
+ def blogger_config
32
+ @blogger_config ||= @config['blogger'] || {}
33
+ end
34
+
35
+ def read_blog(site, blog, list_post_parameters = {})
36
+ parameters = {
37
+ max_results: 500
38
+ }.merge(list_post_parameters || {}).deep_symbolize_keys
39
+
40
+ loop do
41
+ list_posts = @blogger.list_posts(blog.id, **parameters)
42
+
43
+ list_posts.items.each do |post|
44
+ doc = BloggerDocument.new(post, site: site, collection: site.posts, blog_url: blog.url)
45
+ doc.read
46
+ site.posts.docs << doc
47
+ end
48
+
49
+ break if (parameters[:page_token] = list_posts.next_page_token).nil?
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-blogger-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Susco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-apis-blogger_v3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 6.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 6.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-jekyll
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ description:
98
+ email:
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - lib/jekyll-blogger-generator.rb
104
+ - lib/jekyll-blogger-generator/version.rb
105
+ - lib/jekyll/blogger_document.rb
106
+ - lib/jekyll/blogger_generator.rb
107
+ homepage: https://github.com/dsusco/jekyll-blogger-generator
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.7.2
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.1.4
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A Blogger generator for Jekyll.
130
+ test_files: []