diff options
-rw-r--r-- | .rubocop.yml | 3 | ||||
-rw-r--r-- | commands/frontend.rb | 1 | ||||
-rw-r--r-- | lib/filters/tabs.rb | 1 | ||||
-rw-r--r-- | lib/helpers/algolia_rank.rb | 85 | ||||
-rw-r--r-- | lib/helpers/generic.rb | 1 | ||||
-rw-r--r-- | lib/helpers/versions.rb | 1 | ||||
-rw-r--r-- | spec/lib/filters/tabs_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/helpers/algolia_rank_spec.rb | 39 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 |
9 files changed, 66 insertions, 67 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 58222779..d6e1e318 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,9 @@ inherit_gem: gitlab-styles: - rubocop-default.yml +AllCops: + NewCops: enable + CodeReuse/ActiveRecord: Enabled: false diff --git a/commands/frontend.rb b/commands/frontend.rb index c88c475f..48ece62f 100644 --- a/commands/frontend.rb +++ b/commands/frontend.rb @@ -42,5 +42,4 @@ run do |opts, args, cmd| puts 'Copying Lunr.js...' puts "- Copied #{lunr_src}" if File.write('public/assets/javascripts/lunr.min.js', File.read("#{root}/#{lunr_src}")) end - end diff --git a/lib/filters/tabs.rb b/lib/filters/tabs.rb index 08385383..6caa5504 100644 --- a/lib/filters/tabs.rb +++ b/lib/filters/tabs.rb @@ -18,5 +18,4 @@ class TabsFilter < Nanoc::Filter def generateWrapper(content) %(<div class="js-tabs">#{content}</div>) end - end diff --git a/lib/helpers/algolia_rank.rb b/lib/helpers/algolia_rank.rb index 3e14f0d7..03bcc7bf 100644 --- a/lib/helpers/algolia_rank.rb +++ b/lib/helpers/algolia_rank.rb @@ -1,50 +1,51 @@ # frozen_string_literal: true module Nanoc::Helpers - module AlgoliaRank - ### - # Add a URL pattern and weight to CUSTOM_PAGERANKS to modify Algolia search results. - # - # Weights greater than DEFAULT_PAGERANK will boost a page in search results, - # and weights below DEFAULT_PAGERANK will lower its ranking. - # - # The weight value appears in the "docsearch:pageRank" metatag - # on each page that contains the URL pattern. - # - # For example, the "/runner/development/reviewing-gitlab-runner.html" page - # will match "/runner/development" in CUSTOM_PAGERANKS and receive a weight of "20". - # - # @see https://docsearch.algolia.com/docs/record-extractor/#boost-search-results-with-pagerank - ## - DEFAULT_PAGERANK = 100 - CUSTOM_PAGERANKS = { - "/ee/api" => 50, - "/ee/development" => 20, - "/omnibus/development" => 20, - "/runner/development" => 20, - "/charts/development" => 20, - } + module AlgoliaRank + ### + # Add a URL pattern and weight to CUSTOM_PAGERANKS to modify Algolia search results. + # + # Weights greater than DEFAULT_PAGERANK will boost a page in search results, + # and weights below DEFAULT_PAGERANK will lower its ranking. + # + # The weight value appears in the "docsearch:pageRank" metatag + # on each page that contains the URL pattern. + # + # For example, the "/runner/development/reviewing-gitlab-runner.html" page + # will match "/runner/development" in CUSTOM_PAGERANKS and receive a weight of "20". + # + # @see https://docsearch.algolia.com/docs/record-extractor/#boost-search-results-with-pagerank + ## + DEFAULT_PAGERANK = 100 + CUSTOM_PAGERANKS = { + "/ee/api" => 50, + "/ee/development" => 20, + "/omnibus/development" => 20, + "/runner/development" => 20, + "/charts/development" => 20 + }.freeze - def algolia_rank(item) - if result = CUSTOM_PAGERANKS.keys.find {|k| item.identifier.to_s.include? k} - return CUSTOM_PAGERANKS[result] - else - return DEFAULT_PAGERANK - end - end + def algolia_rank(item) + if result = CUSTOM_PAGERANKS.keys.find { |k| item.identifier.to_s.include? k } + return CUSTOM_PAGERANKS[result] + else + return DEFAULT_PAGERANK + end + end + + ### + # Calculate the navigation level of a given page. + # We use this on Algolia to increase relevance of higher-level pages. + ### + def algolia_level(item) + path = item.identifier.to_s + level = path.scan("/").count - ### - # Calculate the navigation level of a given page. - # We use this on Algolia to increase relevance of higher-level pages. - ### - def algolia_level(item) - path = item.identifier.to_s - level = path.scan("/").count - if path.include? "index.md" - level -= 1 - end - return level - end + if path.include? "index.md" + level -= 1 + end + return level end + end end diff --git a/lib/helpers/generic.rb b/lib/helpers/generic.rb index cb6e8c12..1f7a091c 100644 --- a/lib/helpers/generic.rb +++ b/lib/helpers/generic.rb @@ -53,6 +53,5 @@ module Nanoc::Helpers def show_banner? @items['/_data/banner.yaml'][:show_banner] end - end end diff --git a/lib/helpers/versions.rb b/lib/helpers/versions.rb index 954ea6ca..70fa6a67 100644 --- a/lib/helpers/versions.rb +++ b/lib/helpers/versions.rb @@ -32,6 +32,5 @@ module Nanoc::Helpers def stable_version?(version) version.match?(STABLE_VERSIONS_REGEX) end - end end diff --git a/spec/lib/filters/tabs_spec.rb b/spec/lib/filters/tabs_spec.rb index 6ae64b0a..bbaeca9a 100644 --- a/spec/lib/filters/tabs_spec.rb +++ b/spec/lib/filters/tabs_spec.rb @@ -23,6 +23,5 @@ describe TabsFilter do expect(run).to eq("<div class=\"js-tabs\">Tabs content</div>") end end - end end diff --git a/spec/lib/helpers/algolia_rank_spec.rb b/spec/lib/helpers/algolia_rank_spec.rb index 7156446d..161fd216 100644 --- a/spec/lib/helpers/algolia_rank_spec.rb +++ b/spec/lib/helpers/algolia_rank_spec.rb @@ -5,31 +5,30 @@ require 'nanoc' require 'helpers/algolia_rank' RSpec.describe Nanoc::Helpers::AlgoliaRank do - let(:mock_class) { Class.new { extend Nanoc::Helpers::AlgoliaRank } } - let(:identifier) { "/runner/development/reviewing-gitlab-runner.html" } + let(:mock_class) { Class.new { extend Nanoc::Helpers::AlgoliaRank } } + let(:identifier) { "/runner/development/reviewing-gitlab-runner.html" } - let(:mock_item) do - item = Struct.new(:identifier) - item.new(identifier) - end + let(:mock_item) do + item = Struct.new(:identifier) + item.new(identifier) + end - subject { mock_class.algolia_rank(mock_item) } + subject { mock_class.algolia_rank(mock_item) } - describe '#algolia_rank' do - using RSpec::Parameterized::TableSyntax + describe '#algolia_rank' do + using RSpec::Parameterized::TableSyntax - where(:url_pattern, :identifier, :weight) do - "/ee/api" | "/ee/api/openapi/openapi_interactive.html" | 50 - "/runner/development" | "/runner/development/reviewing-gitlab-runner.html" | 20 - "/ee/development" | "/ee/development/documentation/graphql_styleguide.html" | 20 - "" | "/ee/install/installation.html" | 100 - end + where(:url_pattern, :identifier, :weight) do + "/ee/api" | "/ee/api/openapi/openapi_interactive.html" | 50 + "/runner/development" | "/runner/development/reviewing-gitlab-runner.html" | 20 + "/ee/development" | "/ee/development/documentation/graphql_styleguide.html" | 20 + "" | "/ee/install/installation.html" | 100 + end - with_them do - it 'returns correct weight for matched identifier' do - expect(subject).to eq(weight) - end + with_them do + it 'returns correct weight for matched identifier' do + expect(subject).to eq(weight) end - end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29762f59..340b70a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ unless ENV['SIMPLECOV'] == '0' SimpleCov.start SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter end + $LOAD_PATH << 'lib/' require 'rspec-parameterized' |