jekyll-shorts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b3d8759f41c495c08a1001975d9a43dcf139f03355b21a9e9d79f698e7ab1877
4
+ data.tar.gz: 6fb9f3a3ec31d2c485d03d8def545b2b73c0008b18a121033add28cbbe7a4f20
5
+ SHA512:
6
+ metadata.gz: 33b528a89955c8c9a4b4dae4f5daa07fd926881128dd697805036dbaa0273f20630e8f672d7d13c143ee089c4b1e34cfa6165d1437465230a04dac137ca7fc4f
7
+ data.tar.gz: 9e30d54dbc5fbe3d5314bcf60af37e04516acd9b5a491eec163b070e6f438f0044d5b8b05a17edaf3229512db292ae0e98b1d12a53c7f090471ba2f7e44238a9
data/.0pdd.yml ADDED
@@ -0,0 +1,9 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
6
+
7
+ tags:
8
+ - pdd
9
+ - bug
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: codecov
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ codecov:
9
+ runs-on: ubuntu-22.04
10
+ steps:
11
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ - run: sudo apt-get -y install plantuml
16
+ - run: bundle update
17
+ - run: bundle exec rake
18
+ - uses: codecov/codecov-action@v4.0.0-beta.3
19
+ with:
20
+ token: ${{ secrets.CODECOV_TOKEN }}
21
+ file: coverage/.resultset.json
22
+ fail_ci_if_error: true
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: pdd
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ pdd:
12
+ runs-on: ubuntu-22.04
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: volodya-lombrozo/pdd-action@master
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ name: test
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-20.04, macos-12, windows-2022]
16
+ ruby: [3.1]
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - run: bundle update
24
+ - run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: xcop
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ xcop:
8
+ runs-on: ubuntu-22.04
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - uses: g4s8/xcop-action@master
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ .bundle/
4
+ .DS_Store
5
+ coverage/
6
+ _chatgpt-translate/
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude src/main/resources/images/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.7
7
+ SuggestExtensions: false
8
+ NewCops: enable
9
+
10
+ Gemspec/RequiredRubyVersion:
11
+ Enabled: false
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+ Style/ClassAndModuleChildren:
15
+ Enabled: false
16
+ Layout/MultilineMethodCallIndentation:
17
+ Enabled: false
18
+ Metrics/AbcSize:
19
+ Enabled: false
20
+ Metrics/BlockLength:
21
+ Max: 100
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 30
24
+ Metrics/PerceivedComplexity:
25
+ Max: 40
26
+ Layout/EmptyLineAfterGuardClause:
27
+ Enabled: false
28
+ Naming/FileName:
29
+ Enabled: false
30
+ Layout/IndentationWidth:
31
+ Enabled: false
32
+ Layout/ElseAlignment:
33
+ Enabled: false
34
+ Layout/EndAlignment:
35
+ Enabled: false
36
+ Metrics/ClassLength:
37
+ Max: 200
38
+ Style/ClassVars:
39
+ Enabled: false
data/.rultor.yml ADDED
@@ -0,0 +1,23 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.22.0
3
+ assets:
4
+ rubygems.yml: yegor256/home#assets/rubygems.yml
5
+ install: |
6
+ pdd -f /dev/null
7
+ bundle install --no-color
8
+ release:
9
+ pre: false
10
+ script: |-
11
+ bundle exec rake
12
+ rm -rf *.gem
13
+ sed -i "s/0\.0\.0/${tag}/g" jekyll-shorts.gemspec
14
+ sed -i "s/0\.0\.0/${tag}/g" lib/jekyll-shorts/version.rb
15
+ git add jekyll-shorts.gemspec
16
+ git add lib/jekyll-shorts/version.rb
17
+ git commit -m "version set to ${tag}"
18
+ gem build jekyll-shorts.gemspec
19
+ chmod 0600 ../rubygems.yml
20
+ gem push *.gem --config-file ../rubygems.yml
21
+ merge:
22
+ script: |-
23
+ bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ source 'https://rubygems.org'
26
+ gemspec
27
+
28
+ gem 'cucumber', '9.1.0', require: false
29
+ gem 'minitest', '5.21.1', require: false
30
+ gem 'rake', '13.1.0', require: false
31
+ gem 'rubocop', '1.59.0', require: false
32
+ gem 'rubocop-rspec', '2.26.1', require: false
33
+ gem 'simplecov', '0.22.0', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024 Yegor Bugayenko
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ [![rake](https://github.com/yegor256/jekyll-shorts/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/jekyll-shorts/actions/workflows/rake.yml)
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll-shorts.svg)](http://badge.fury.io/rb/jekyll-shorts)
3
+
4
+ If you have a [Jekyll](https://jekyllrb.com/) static site, this plugin may help you automatically
5
+ generate short links for every page. I'm using this plugin for
6
+ [my blog](https://github.com/yegor256/blog).
7
+
8
+ Install it first (you need [Ruby 3+](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/)
9
+ and [Jekyll 3+](https://jekyllrb.com/)):
10
+
11
+ ```
12
+ $ gem install jekyll-shorts
13
+ ```
14
+
15
+ Then, add this to `_config.yml`:
16
+
17
+ ```yaml
18
+ plugins:
19
+ - ... your other plugins here ...
20
+ - jekyll-shorts
21
+ shorts:
22
+ permalink: :year:month:day.html
23
+ ```
24
+
25
+ Here, every page in the site will get a sibling with the name
26
+ `:year:month:day.html`, which will redirect to the page itself. You can use:
27
+
28
+ * `:year` - the year of the post
29
+ * `:month` - the year of the post
30
+ * `:day` - the year of the post
31
+ * `:position` - the unique position of the post in the entire list of them
32
+
33
+ Be careful with the `:position`, since it may change when you add a new post
34
+ somewhere in the middle of existing flow of posts.
35
+
36
+ ## How to Contribute
37
+
38
+ Make a fork and then test it locally like this:
39
+
40
+ ```bash
41
+ $ bundle update
42
+ $ bundle exec rake
43
+ ```
44
+
45
+ If it works, make changes, test again, and then submit a pull request.
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'rubygems'
26
+ require 'rake'
27
+
28
+ def name
29
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
30
+ end
31
+
32
+ def version
33
+ Gem::Specification.load(Dir['*.gemspec'].first).version
34
+ end
35
+
36
+ require 'rake/clean'
37
+ task default: %i[clean test features rubocop copyright]
38
+
39
+ require 'rake/testtask'
40
+ desc 'Run all unit tests'
41
+ Rake::TestTask.new(:test) do |test|
42
+ Rake::Cleaner.cleanup_files(['coverage'])
43
+ test.libs << 'lib' << 'test'
44
+ test.pattern = 'test/**/test_*.rb'
45
+ test.warning = true
46
+ test.verbose = false
47
+ end
48
+
49
+ require 'rdoc'
50
+ require 'rdoc/task'
51
+ desc 'Build RDoc documentation'
52
+ Rake::RDocTask.new do |rdoc|
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "#{name} #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
58
+
59
+ require 'rubocop/rake_task'
60
+ desc 'Run RuboCop on all directories'
61
+ RuboCop::RakeTask.new(:rubocop) do |task|
62
+ task.fail_on_error = true
63
+ task.requires << 'rubocop-rspec'
64
+ end
65
+
66
+ require 'cucumber/rake/task'
67
+ Cucumber::Rake::Task.new(:features) do
68
+ Rake::Cleaner.cleanup_files(['coverage'])
69
+ end
70
+ Cucumber::Rake::Task.new(:'features:html') do |t|
71
+ t.profile = 'html_report'
72
+ end
73
+
74
+ task :copyright do
75
+ sh "grep -q -r '#{Date.today.strftime('%Y')}' \
76
+ --include '*.rb' \
77
+ --include '*.txt' \
78
+ --include 'Rakefile' \
79
+ ."
80
+ end
@@ -0,0 +1,27 @@
1
+ Feature: Simple site building
2
+ I want to be able to build a site
3
+
4
+ Scenario: Simple site
5
+ Given I have a "_config.yml" file with content:
6
+ """
7
+ markdown: kramdown
8
+ plugins:
9
+ - jekyll-shorts
10
+ shorts:
11
+ permalink: :day.html
12
+ """
13
+ And I have a "_layouts/default.html" file with content:
14
+ """
15
+ {{ content }}
16
+ """
17
+ And I have a "_posts/2023-01-01-hello.md" file with content:
18
+ """
19
+ ---
20
+ title: Hello, world!
21
+ layout: default
22
+ ---
23
+ Hello, world!
24
+ """
25
+ Then I build Jekyll site
26
+ And Exit code is zero
27
+ And File "_site/01.html" exists
@@ -0,0 +1,24 @@
1
+ Feature: Gem Package
2
+ As a source code writer I want to be able to
3
+ package the Gem into .gem file
4
+
5
+ Scenario: Gem can be packaged
6
+ When It is Unix
7
+ Given I have a "execs.rb" file with content:
8
+ """
9
+ #!/usr/bin/env ruby
10
+ require 'rubygems'
11
+ spec = Gem::Specification::load('./spec.rb')
12
+ """
13
+ And I copy this gem into temp dir
14
+ When I run bash with:
15
+ """
16
+ set -x
17
+ set -e
18
+ cd jekyll-shorts
19
+ gem build jekyll-shorts.gemspec
20
+ gem specification --ruby jekyll-shorts-*.gem > ../spec.rb
21
+ cd ..
22
+ ruby execs.rb
23
+ """
24
+ Then Exit code is zero
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023-2024 Yegor Bugayenko
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 all
13
+ # 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 NONINFINGEMENT. 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 THE
21
+ # SOFTWARE.
22
+
23
+ require 'tmpdir'
24
+ require 'English'
25
+
26
+ Before do
27
+ @cwd = Dir.pwd
28
+ @dir = Dir.mktmpdir('test')
29
+ FileUtils.mkdir_p(@dir)
30
+ Dir.chdir(@dir)
31
+ end
32
+
33
+ After do
34
+ Dir.chdir(@cwd)
35
+ FileUtils.rm_rf(@dir)
36
+ end
37
+
38
+ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
39
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
40
+ File.write(file, text.gsub('\\xFF', 0xFF.chr))
41
+ end
42
+
43
+ When('I build Jekyll site') do
44
+ @stdout = `jekyll build`
45
+ @exitstatus = $CHILD_STATUS.exitstatus
46
+ end
47
+
48
+ Then('Stdout contains {string}') do |string|
49
+ raise "STDOUT doesn't contain '#{string}':\n#{@stdout}" unless @stdout.include?(string)
50
+ end
51
+
52
+ Then('File {string} exists') do |string|
53
+ raise "The file \"#{string}\" is absent:\n#{`tree -s`}" unless File.exist?(string)
54
+ end
55
+
56
+ Then('File {string} contains {string}') do |string, string2|
57
+ raise "The file \"#{string}\" is absent" unless File.exist?(string)
58
+ content = File.read(string)
59
+ raise "The file \"#{string}\" doesn't contain \"#{string2}\":\n#{content}" unless content.include?(string2)
60
+ end
61
+
62
+ Then('Exit code is zero') do
63
+ raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
64
+ end
65
+
66
+ Then('Exit code is not zero') do
67
+ raise 'Zero exit code' if @exitstatus.zero?
68
+ end
69
+
70
+ When('I run bash with {string}') do |string|
71
+ @stdout = `#{string}`
72
+ @exitstatus = $CHILD_STATUS.exitstatus
73
+ end
74
+
75
+ When(/^I run bash with:$/) do |text|
76
+ @stdout = `#{text}`
77
+ @exitstatus = $CHILD_STATUS.exitstatus
78
+ end
79
+
80
+ When('I copy this gem into temp dir') do
81
+ FileUtils.copy_entry(@cwd, File.join(@dir, 'jekyll-shorts'))
82
+ end
83
+
84
+ Given('It is Unix') do
85
+ pending if Gem.win_platform?
86
+ end
87
+
88
+ Given('It is Windows') do
89
+ pending unless Gem.win_platform?
90
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023-2024 Yegor Bugayenko
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 all
13
+ # 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 NONINFINGEMENT. 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 THE
21
+ # SOFTWARE.
22
+
23
+ require 'simplecov'
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'English'
26
+
27
+ Gem::Specification.new do |s|
28
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
29
+ s.required_ruby_version = '>= 2.6'
30
+ s.name = 'jekyll-shorts'
31
+ s.version = '0.0.1'
32
+ s.license = 'MIT'
33
+ s.summary = 'Automatically generates short links for Jekyll website'
34
+ s.description = [
35
+ 'Add this plugin to your Jekyll site and all posts will automatically',
36
+ 'get short links (similar to what URL shorteners may provide)'
37
+ ].join(' ')
38
+ s.authors = ['Yegor Bugayenko']
39
+ s.email = 'yegor256@gmail.com'
40
+ s.homepage = 'https://github.com/yegor256/jekyll-shorts'
41
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
42
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
43
+ s.rdoc_options = ['--charset=UTF-8']
44
+ s.extra_rdoc_files = %w[README.md LICENSE.txt]
45
+ s.add_runtime_dependency 'jekyll', '>= 3'
46
+ s.metadata['rubygems_mfa_required'] = 'true'
47
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'jekyll'
26
+ require 'fileutils'
27
+ require 'json'
28
+ require_relative 'version'
29
+
30
+ # The module we are in.
31
+ module JekyllShorts; end
32
+
33
+ # Pages generator.
34
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
35
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
36
+ # License:: MIT
37
+ class JekyllShorts::Generator < Jekyll::Generator
38
+ safe true
39
+ priority :lowest
40
+
41
+ # Main plugin action, called by Jekyll-core
42
+ def generate(site)
43
+ Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION} starting...")
44
+ config ||= site.config['shorts'] || {}
45
+ permalink ||= config['permalink'] || ':year:month:day'
46
+ start = Time.now
47
+ total = 0
48
+ site.posts.docs.sort_by(&:url).each_with_index do |doc, pos|
49
+ long = doc.url
50
+ short = Jekyll::URL.new(
51
+ template: permalink,
52
+ placeholders: {
53
+ 'year' => doc.date.year.to_s,
54
+ 'month' => doc.date.month.to_s.rjust(2, '0'),
55
+ 'day' => doc.date.day.to_s.rjust(2, '0'),
56
+ 'position' => pos.to_s
57
+ }
58
+ ).to_s
59
+ site.static_files << ShortFile.new(site, short, long)
60
+ doc.data['short-url'] = short
61
+ total += 1
62
+ end
63
+ Jekyll.logger.info("jekyll-shorts #{JekyllShorts::VERSION}: \
64
+ #{total} link(s) generated in #{(Time.now - start).round(2)}s")
65
+ end
66
+
67
+ # The HTML file with a redirect.
68
+ class ShortFile < Jekyll::StaticFile
69
+ def initialize(site, short, long)
70
+ super(site, site.dest, '', short)
71
+ @long = long
72
+ end
73
+
74
+ def write(_dest)
75
+ FileUtils.mkdir_p(File.dirname(path))
76
+ html = "<html> redirect to #{@long}</html>"
77
+ File.write(path, html)
78
+ Jekyll.logger.info("HTML #{path.inspect} -> #{@long.inspect}")
79
+ true
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ module JekyllShorts
26
+ VERSION = '0.0.1'
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'jekyll-shorts/generator'
data/renovate.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ],
6
+ "ignorePaths": [
7
+ "jekyll-tests/jekyll-3/Gemfile",
8
+ "jekyll-tests/jekyll-4/Gemfile"
9
+ ]
10
+ }
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
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 all
13
+ # 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 NONINFINGEMENT. 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 THE
21
+ # SOFTWARE.
22
+
23
+ $stdout.sync = true
24
+
25
+ require 'simplecov'
26
+ SimpleCov.start
27
+
28
+ require 'jekyll'
29
+ Jekyll.logger.adjust_verbosity(verbose: true)
30
+
31
+ # The module we are in.
32
+ module JekyllShorts; end
33
+
34
+ # Fake.
35
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
36
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
37
+ # License:: MIT
38
+ class JekyllShorts::FakeSite
39
+ attr_reader :config, :pages, :static_files
40
+
41
+ def initialize(config, docs = [])
42
+ @config = config
43
+ @docs = docs
44
+ @pages = []
45
+ @static_files = []
46
+ end
47
+
48
+ def posts
49
+ JekyllShorts::FakePosts.new(@docs)
50
+ end
51
+
52
+ def permalink_style
53
+ ''
54
+ end
55
+
56
+ def frontmatter_defaults
57
+ Jekyll::FrontmatterDefaults.new(self)
58
+ end
59
+
60
+ def converters
61
+ [Jekyll::Converters::Markdown.new({ 'markdown_ext' => 'md' })]
62
+ end
63
+
64
+ def source
65
+ ''
66
+ end
67
+
68
+ def dest
69
+ return '' if @docs.empty?
70
+ File.dirname(@docs[0])
71
+ end
72
+
73
+ def in_theme_dir(base, _foo = nil, _bar = nil)
74
+ base
75
+ end
76
+
77
+ def in_dest_dir(*paths)
78
+ paths[0].dup
79
+ end
80
+ end
81
+
82
+ # Fake.
83
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
84
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
85
+ # License:: MIT
86
+ class JekyllShorts::FakeDocument
87
+ attr_reader :data
88
+
89
+ def initialize(path)
90
+ @path = path
91
+ @data = { 'date' => Time.now, 'title' => 'Hello!' }
92
+ end
93
+
94
+ def content
95
+ 'Hello, world!'
96
+ end
97
+
98
+ def date
99
+ Time.now
100
+ end
101
+
102
+ def []=(key, value)
103
+ @data[key] = value
104
+ end
105
+
106
+ def [](key)
107
+ @data[key] || ''
108
+ end
109
+
110
+ def relative_path
111
+ @path
112
+ end
113
+
114
+ def url
115
+ '2023-01-01-hello.html'
116
+ end
117
+
118
+ def basename
119
+ '2023-01-01-hello.md'
120
+ end
121
+ end
122
+
123
+ # Fake.
124
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
125
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
126
+ # License:: MIT
127
+ class JekyllShorts::FakePosts
128
+ attr_reader :config
129
+
130
+ def initialize(docs)
131
+ @docs = docs
132
+ end
133
+
134
+ def docs
135
+ @docs.map { |d| JekyllShorts::FakeDocument.new(d) }
136
+ end
137
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (The MIT License)
4
+ #
5
+ # Copyright (c) 2024 Yegor Bugayenko
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the 'Software'), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'minitest/autorun'
26
+ require 'tmpdir'
27
+ require_relative 'test__helper'
28
+ require_relative '../lib/jekyll-shorts/generator'
29
+
30
+ # Generator test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class JekyllShorts::GeneratorTest < Minitest::Test
35
+ def test_simple_scenario
36
+ Dir.mktmpdir do |home|
37
+ post = File.join(home, '2023-01-01-hello.md')
38
+ File.write(post, "---\ntitle: Hello\n---\n\nHello, world!")
39
+ site = JekyllShorts::FakeSite.new(
40
+ {
41
+ 'url' => 'https://www.yegor256.com/',
42
+ 'shorts' => {
43
+ 'permalink' => ':year:month.html'
44
+ }
45
+ },
46
+ [post]
47
+ )
48
+ gen = JekyllShorts::Generator.new
49
+ gen.generate(site)
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-shorts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ description: Add this plugin to your Jekyll site and all posts will automatically
28
+ get short links (similar to what URL shorteners may provide)
29
+ email: yegor256@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - README.md
34
+ - LICENSE.txt
35
+ files:
36
+ - ".0pdd.yml"
37
+ - ".github/workflows/codecov.yml"
38
+ - ".github/workflows/pdd.yml"
39
+ - ".github/workflows/rake.yml"
40
+ - ".github/workflows/xcop.yml"
41
+ - ".gitignore"
42
+ - ".pdd"
43
+ - ".rubocop.yml"
44
+ - ".rultor.yml"
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - features/cli.feature
50
+ - features/gem_package.feature
51
+ - features/step_definitions/steps.rb
52
+ - features/support/env.rb
53
+ - jekyll-shorts.gemspec
54
+ - lib/jekyll-shorts.rb
55
+ - lib/jekyll-shorts/generator.rb
56
+ - lib/jekyll-shorts/version.rb
57
+ - renovate.json
58
+ - test/test__helper.rb
59
+ - test/test_generator.rb
60
+ homepage: https://github.com/yegor256/jekyll-shorts
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ rubygems_mfa_required: 'true'
65
+ post_install_message:
66
+ rdoc_options:
67
+ - "--charset=UTF-8"
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '2.6'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.4.10
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Automatically generates short links for Jekyll website
85
+ test_files: []