nanoc-github 1.0.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: 98ed4924d4561de729f3aa70c1c955f5655991dda103c9594987c89127aa8ac8
4
+ data.tar.gz: 28d63967294e40839d52508ea7c18c902d370c18b4792ea0d57362ea11f3adc7
5
+ SHA512:
6
+ metadata.gz: eb09ee28dea1f6c8ab415738b544d3008a420283cb0f2396d97233488db54fc7adf39d9bfa0f7ba2097a1f0f754269997da24b4aefa7d32ad909723f3297d916
7
+ data.tar.gz: c4da759a73c852b0d888959f41ea33a3189c1b8ecd9840eae7f3f249c2f4ea0696b234fd4cc424883b4304f4440872871c698c80c1c23b5c007c87c2685a3d3c
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Paweł Pacana
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Nanoc::Github
2
+
3
+ Content source from git repository. A way to have your writing in public and open for edition while not being distracted
4
+ by static site generator trivia this content is usually mixed with.
5
+
6
+ ## Usage
7
+
8
+ Add to `Gemfile` in your nanoc project:
9
+
10
+ ```ruby
11
+ gem "nanoc-github"
12
+ ```
13
+
14
+ Then tell nanoc to load it in `lib/default.rb`:
15
+
16
+ ```ruby
17
+ require "nanoc/github"
18
+ ```
19
+
20
+ At last, enable github data source in `nanoc.yaml`:
21
+
22
+ ```yaml
23
+ data_sources:
24
+ - type: github
25
+ items_root: /posts # the root where items should be mounted
26
+ repository: arkency/posts-from-arkency-blog # organization/repository on github to use as a source of content
27
+ encoding: utf-8 # how to decode content (default: utf-8)
28
+ access_token: secret123 # github access token, not required for public repositories (default: nil)
29
+ path: posts/ # subdirectory of the content in given repository (default: nil)
30
+ concurrency: 10 # how many threads to spawn to fetch data (default: 5)
31
+ ```
32
+
33
+ ## Status
34
+
35
+ [![build status](https://github.com/pawelpacana/nanoc-github/workflows/test/badge.svg)](https://github.com/pawelpacana/nanoc-github/actions)
36
+ [![gem version](https://badge.fury.io/rb/nanoc-github.svg)](https://badge.fury.io/rb/nanoc-github)
@@ -0,0 +1,72 @@
1
+ require "nanoc"
2
+ require "octokit"
3
+ require "concurrent-ruby"
4
+
5
+ module Nanoc
6
+ module Github
7
+ REGEX = /^(?<metadata>---\s*\n.*?\n?)^(---\s*$\n?)/m
8
+
9
+ class Source < Nanoc::DataSource
10
+ identifier :github
11
+
12
+ def items
13
+ @items ||= begin
14
+ repository_items.map do |item|
15
+ identifier = Nanoc::Identifier.new("/#{item[:name]}")
16
+ metadata, data = decode(item[:content])
17
+
18
+ new_item(data, metadata, identifier, checksum_data: item[:sha])
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def client
26
+ Octokit::Client.new(access_token: access_token)
27
+ end
28
+
29
+ def decode(content)
30
+ content = Base64.decode64(content).force_encoding(encoding)
31
+ matchdata = content.match(REGEX)
32
+ metadata = matchdata ? YAML.safe_load(matchdata[:metadata], permitted_classes: [Time]) : {}
33
+
34
+ [metadata, content.gsub(REGEX, '')]
35
+ end
36
+
37
+ def repository_items
38
+ pool = Concurrent::FixedThreadPool.new(concurrency)
39
+ items = Concurrent::Array.new
40
+ client
41
+ .contents(repository, path: path)
42
+ .select { |item| item[:type] == "file" }
43
+ .each { |item| pool.post { items << client.contents(repository, path: item[:path]) } }
44
+ pool.shutdown
45
+ pool.wait_for_termination
46
+ items
47
+ rescue Octokit::NotFound => exc
48
+ []
49
+ end
50
+
51
+ def encoding
52
+ @config[:encoding] || "utf-8"
53
+ end
54
+
55
+ def concurrency
56
+ @config[:concurrency] || 5
57
+ end
58
+
59
+ def access_token
60
+ @config[:access_token]
61
+ end
62
+
63
+ def path
64
+ @config[:path]
65
+ end
66
+
67
+ def repository
68
+ @config[:repository]
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Nanoc
2
+ module Github
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Pacana
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nanoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '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: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: concurrent-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.6
55
+ description: |
56
+ Nanoc content source from git repository. A way to have your writing in public and open for edition while not being
57
+ distracted by static site generator trivia this content is usually mixed with.
58
+ email:
59
+ - pawel.pacana@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ - LICENSE.txt
65
+ files:
66
+ - LICENSE.txt
67
+ - README.md
68
+ - lib/nanoc/github.rb
69
+ - lib/nanoc/github/version.rb
70
+ homepage: https://github.com/pawelpacana/nanoc-github
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ homepage_uri: https://github.com/pawelpacana/nanoc-github
75
+ source_code_uri: https://github.com/pawelpacana/nanoc-github
76
+ changelog_uri: https://github.com/pawelpacana/nanoc-github/releases
77
+ bug_tracker_uri: https://github.com/pawelpacana/nanoc-github/issues
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.1.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Nanoc content source from git repository
97
+ test_files: []