diff --git a/Gemfile b/Gemfile index b9f579491..105a4ff55 100644 --- a/Gemfile +++ b/Gemfile @@ -23,11 +23,11 @@ end group :test, :development do gem 'classifier-reborn', github: 'jekyll/classifier-reborn' gem 'github-pages-health-check' - #gem 'gsl', github: 'SciRuby/rb-gsl' Not compatible with Ruby 3.0 - gem 'numo-narray' - gem 'numo-linalg' + # gem 'gsl', github: 'SciRuby/rb-gsl' Not compatible with Ruby 3.0 gem 'html-proofer' gem 'nokogiri' + gem 'numo-linalg' + gem 'numo-narray' gem 'pry' gem 'rake' gem 'rspec' diff --git a/Rakefile b/Rakefile index 2e2a1cf1f..7aedd19a9 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ task :format_yaml do next unless content.match?(Jekyll::Document::YAML_FRONT_MATTER_REGEXP) parts = content.split Jekyll::Document::YAML_FRONT_MATTER_REGEXP - yaml = YAML.load_file(parts[1], permitted_classes: [Psych, Symbol]) + yaml = YAML.load(parts[1], permitted_classes: [Psych, Symbol]) %w[title description].each { |key| yaml[key] = strip_whitespace(yaml[key]) if yaml[key] } %w[tags category categories post_format].each { |key| yaml.delete(key) } File.write(path, "#{yaml.to_yaml(line_width: -1)}---\n\n#{parts[4]}") diff --git a/script/build-related-posts b/script/build-related-posts index 62c826229..f3251d4bb 100755 --- a/script/build-related-posts +++ b/script/build-related-posts @@ -9,7 +9,7 @@ require 'psych' options = { 'source' => File.expand_path('../', __dir__), 'lsi' => true, - 'verbose' => true, + 'verbose' => true } ignore_list = [ @@ -17,7 +17,7 @@ ignore_list = [ '_posts/2012-12-26-securing-the-status-quo.md' ] -Jekyll.logger.info "Building site" +Jekyll.logger.info 'Building site' config = Jekyll.configuration(options) site = Jekyll::Site.new(config) @@ -25,7 +25,7 @@ site.reset site.read site.posts.docs.delete_if { |post| ignore_list.include?(post.relative_path) || post.data['archived'] } -Jekyll.logger.info "Building related posts" +Jekyll.logger.info 'Building related posts' relations = {} site.posts.docs.each do |post| relations[post.relative_path] = post.related_posts.map(&:relative_path) diff --git a/script/lint-front-matter b/script/lint-front-matter index 6e91d4afb..cd142b1fe 100755 --- a/script/lint-front-matter +++ b/script/lint-front-matter @@ -6,12 +6,19 @@ require 'open3' exitstatus = 0 +# Pre-collect all files to avoid re-reading during iteration +files_with_yaml = [] Dir['*/**.md'].each do |path| content = File.read(path) next unless content.match?(Jekyll::Document::YAML_FRONT_MATTER_REGEXP) parts = content.split Jekyll::Document::YAML_FRONT_MATTER_REGEXP - output, status = Open3.capture2e('yamllint', '-', '-c', '.yamllint.yml', '-f', 'colored', stdin_data: parts[1]) + files_with_yaml << [path, parts[1]] +end + +# Process all collected files +files_with_yaml.each do |path, yaml_content| + output, status = Open3.capture2e('yamllint', '-', '-c', '.yamllint.yml', '-f', 'colored', stdin_data: yaml_content) next if status.exitstatus.zero? puts path diff --git a/spec/amazon_link_check.rb b/spec/amazon_link_check.rb index 36cfcc280..a72ca7133 100644 --- a/spec/amazon_link_check.rb +++ b/spec/amazon_link_check.rb @@ -6,18 +6,18 @@ def affiliate_id end def uri - URI.parse(@link.href) + @uri ||= URI.parse(@link.href) end def params - CGI.parse(uri.query) if uri.query + @params ||= CGI.parse(uri.query) if uri.query end def amazon_link? uri.host =~ /amazon\.com/ end - def afiiliate_id? + def affiliate_id? return false unless params&.key?('tag') params['tag'].first == affiliate_id @@ -26,10 +26,12 @@ def afiiliate_id? def run @html.css('a').each do |node| @link = create_element(node) + @uri = nil # Reset memoized URI for new link + @params = nil # Reset memoized params for new link next if @link.data_proofer_ignore || @link.href.nil? - if amazon_link? && !afiiliate_id? - msg = "Misssing Amazon Affiliate ID: #{@link.href}" + if amazon_link? && !affiliate_id? + msg = "Missing Amazon Affiliate ID: #{@link.href}" add_issue(msg, line: node.line) end end