<commit_before>---
index: false
---

:ruby

  def find_link(title)
    return unless title

    match = sitemap.resources.select do |resource|
      resource.data.wiki_title.to_s.strip == title.strip
    end.first

    match.url if match
  end

  def expand_redirect(title, redir = $REDIRECTS)
    match = redir[title]

    if match
      return expand_redirect(redir[title])
    else
      return title
    end
  end

  yaml_file = sitemap.resources.select do |resource|
    next unless resource
    resource.source_file.match(/redirects.(yml|yaml)$/)
  end.first

  if yaml_file
    redirs = YAML.load_file(yaml_file.source_file)

    $REDIRECTS = redirs[:wiki_redirects]
  end

-# redirs[:wiki_redirects].each do |orig, new|
  %li= "#{orig} => #{new}"

-# redirs[:map].each do |orig, new|

- if redirs
  - redirs[:map].each do |orig, new|
    - found = find_link(orig)
    - unless found
      - found_redir = find_link(expand_redirect(orig))
    %li
      %a{href: "http://ovirt.org/#{orig}", target: "_blank"}= orig

      %a{href: "/#{orig.gsub(/ /, '_')}"}
        %span.fa-external-link{title: "local link — should be remapped", target: "_blank"}

      = " => "
      - if found
        %a{href: found}= found
      - else
        - if found_redir
          %strong
            %a{href: found_redir}= found_redir
        - else
          %strong NO PAGE FOUND<commit_msg>revamped redirects page: tablized, sortable, and cache processing<commit_after>---
index: false
---

:ruby

  def find_link(title)
    return unless title

    match = sitemap.resources.select do |resource|
      resource.data.wiki_title.to_s.strip == title.strip
    end.first

    match.url if match
  end

  def expand_redirect(title, redir = $REDIRECTS)
    match = redir[title]

    if match
      return expand_redirect(redir[title])
    else
      return title
    end
  end

  yaml_file = sitemap.resources.select do |resource|
    next unless resource
    resource.source_file.match(/redirects.(yml|yaml)$/)
  end.first

  if yaml_file
    redirs = YAML.load_file(yaml_file.source_file)

    $REDIRECTS = redirs[:wiki_redirects]
  end

  $processed ||= redirs[:map].map do |orig, new|
    results = {
      orig: orig,
      found: find_link(orig),
      mw_path: "/#{orig.gsub(/ /, '_')}"
    }
    results[:found_redir] = find_link(expand_redirect(orig)) unless results[:found]

    results
  end.sort_by { |i| i[:found] || i[:found_redir] || i[:orig] }

%h1 MediaWiki redirects

:markdown
  Notes:

  - Bold links == remapped
  - When pages aren't found, it's sometimes intentional
    - The page could be MediaWiki specific
    - The page might be irrelevant
    - Unfound pages will redirect to 404, triggering a search based on
      the page's URL (converted to keywords)

-# %pre= redirs[:map].to_yaml

- if $processed
  %table.sortable.table
    %thead
      %tr
        %th
        %th Page title
        %th{'data-defaultsort' => 'asc'} New path

    %tbody
      -# redirs[:map].each do |orig, new|
      - $processed.each do |item|
        %tr
          %td
            %a{href: "http://ovirt.org/#{item[:orig]}", target: "_blank"}
              %span.fa-external-link{title: "view the link on oVirt.org", target: "_blank"}

          %td
            %a{href: item[:mw_path], title: "local link — should be remapped to new path via Apache .htaccess rules", target: "_blank"}
              = item[:orig]

          %td
            - if item[:found]
              %a{href: item[:found]}= item[:found]
            - else
              - if item[:found_redir]
                %strong
                  %a{href: item[:found_redir]}= item[:found_redir]
              - else
                %strong NO PAGE FOUND

- content_for :tail do
  :coffee
    jQuery.bootstrapSortable('table')
{'fraction_non_alphanumeric': 0.12781159036782216, 'fraction_numerical': 0.0010584810796507012, 'mean_word_length': 2.36, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055871', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1236, 'n_words': 310}