Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit d044d2b

Browse files
committed
Add a generator for the Migrated topics page
Group migrated topics by guide Add a link to the migrated log onto the banner rubocop's auto-fixes
1 parent 8e798f1 commit d044d2b

File tree

8 files changed

+76
-6
lines changed

8 files changed

+76
-6
lines changed

_checks/html_check_hook.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
require 'html-proofer'
1313
require 'yaml'
14-
require_relative '../lib/double_slash_check.rb'
14+
require_relative '../lib/double_slash_check'
1515

1616
Jekyll::Hooks.register :site, :post_write do |site|
1717
# Do nothing unless 'site.check_links' is set

_plugins/generators/migrated_log.rb

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright © Adobe, Inc. All rights reserved.
4+
# See COPYING.txt for license details.
5+
6+
# This plugin generates the page that contains a list of migrated topics.
7+
#
8+
9+
module Jekyll
10+
# Custom generator for MRG pages
11+
class MigratedLog < Generator
12+
safe true
13+
14+
def generate(site)
15+
# Make the site object available in any scope in this class.
16+
@site = site
17+
migrated_pages = @site.pages.filter { |page| page.data['layout'] == 'migrated' }
18+
19+
url_prefix = site.config['url'] + site.config['baseurl']
20+
21+
migrated_pages_data = []
22+
migrated_pages.each do |page|
23+
migrated_page = {
24+
path: page.path,
25+
title: page.data['title'],
26+
guide: @site.data['toc'][page.data['group']]['label'],
27+
migrated_from: url_prefix + page.url,
28+
migrated_to: page.data['migrated_to']
29+
}
30+
migrated_pages_data << migrated_page
31+
end
32+
33+
migrated_pages_by_group = migrated_pages_data.group_by { |page| page[:guide] }
34+
35+
content = "The folowing is the list of topics that have been migrated and will be redirected soon.\n\n"
36+
migrated_pages_by_group.each do |guide, topics|
37+
content += "\n## #{guide}\n\n\n"
38+
topics.sort_by { |topic| topic[:title] }
39+
.each do |topic|
40+
content += "1. [#{topic[:title]}](#{topic[:migrated_from]}) has moved to <#{topic[:migrated_to]}>\n"
41+
end
42+
end
43+
44+
# PageWithoutAFile handles processing files without reading it.
45+
# 'migrated.md' is a virtual file that's been created during Jekyll run.
46+
# See details in https://www.rubydoc.info/gems/jekyll/Jekyll/PageWithoutAFile
47+
# See tests in https://github.com/jekyll/jekyll/blob/master/test/test_page_without_a_file.rb
48+
topic = PageWithoutAFile.new(
49+
@site,
50+
@site.source,
51+
'.',
52+
'migrated.md'
53+
)
54+
topic.content = content
55+
topic.data['title'] = 'Migrated topics'
56+
topic.data['layout'] = 'full-width'
57+
topic.data['github_link'] = false
58+
topic.data['feedback_link'] = false
59+
topic.process('migrated.md')
60+
61+
# Add the newly constructed page object to the rest of pages
62+
# on the site.
63+
@site.pages << topic
64+
end
65+
end
66+
end

lib/doc_config.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Read Docfile file and get configuration data for adding subrepositories
77
class DocConfig
88
attr_reader :config
9+
910
def initialize(config_file = 'Docfile.yml')
1011
@config = YAML.load_file(config_file)
1112
end

lib/link_checker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ def self.current_branch
4040
def self.file_name
4141
prefix = 'broken-links-in-'
4242
timestamp = Time.now.strftime('_%m-%d_%H-%M-%S')
43-
prefix + current_branch + timestamp + '.md'
43+
"#{prefix}#{current_branch}#{timestamp}.md"
4444
end
4545
end

rakelib/check.rake

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ namespace :check do
1414
puts 'Looking in uncommitted files ...'.blue
1515
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
1616
deleted_files = `git ls-files --deleted`.split("\n")
17-
image_files_to_check = (modified_files - deleted_files).select { |file| File.extname(file) =~ /\.(png|jpg|jpeg|gif)/i }
17+
image_files_to_check = (modified_files - deleted_files).select do |file|
18+
File.extname(file) =~ /\.(png|jpg|jpeg|gif)/i
19+
end
1820

1921
next puts 'No images to check.'.magenta if image_files_to_check.empty?
2022

rakelib/multirepo.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace :multirepo do
88
task :init do
99
protocol = ENV['token'] ? "https://#{ENV['token']}@github.com/" : 'git@github.com:'
1010
@content_map.each do |subrepo|
11-
repo_url = protocol + subrepo['repository'] + '.git'
11+
repo_url = "#{protocol}#{subrepo['repository']}.git"
1212
add_subrepo(subrepo['directory'], repo_url, subrepo['branch'], subrepo['filter'])
1313
end
1414
end

rakelib/test.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace :test do
115115
puts "No links for #{include}".yellow
116116
end
117117
puts "Found #{includes.size} unlinked includes".red
118-
puts 'Be careful removing include files. Some include files, such as those in the layout/** directory, may not be linked in the project, but may be used implicitly by the doc theme.'.bold
118+
puts 'Be careful removing include files. Some include files, such as those in the layout/** directory, may not be linked in the project, but may be used implicitly by the doc theme.'.bold
119119
end
120120
end
121121
end

src/_layouts/migrated.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<div class="content-wrap">
99
<header class="content-header">
1010
<div class="message-banner">
11-
<b>This page has <a href="{{ page.migrated_to }}">moved</a> and will be redirected soon.</b>
11+
<b>This page has <a href="{{ page.migrated_to }}">moved</a> and will be redirected soon. See <a href="{{ site.baseurl }}/migrated.html">Migrated topics</a> for the complete list.</b>
12+
1213
</div>
1314
{% include layout/page-header.html %}
1415
</header>

0 commit comments

Comments
 (0)