This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
# Helper methods to convert markdown reports to HTML and open them in a browser. | ||
module Converter | ||
# The CSS to append to the HTML report with broken links | ||
CSS = %q( | ||
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | ||
<style> | ||
/* Lists | ||
–––––––––––––––––––––––––––––––––––––––––––––––––– */ | ||
ul { | ||
list-style: disc; | ||
font-family: \'Roboto\', sans-serif; | ||
color: red; } | ||
ol { | ||
list-style: decimal inside; }css | ||
ol, ul { | ||
padding-left: 0; | ||
margin-top: 0; } | ||
ul ul, | ||
ul ol, | ||
ol ol, | ||
ol ul { | ||
margin: 1.5rem 0 1.5rem 3rem; | ||
font-size: 90%; | ||
color: black;} | ||
li { | ||
margin-bottom: 1rem; | ||
font-weight: bold;} | ||
</style> | ||
) | ||
|
||
# Define the Kramdown method to convert markdown to HTML. | ||
def self.kramdown(text) | ||
Kramdown::Document.new(text).to_html | ||
end | ||
|
||
# Read content in the given path | ||
def self.content(path) | ||
File.read(path) | ||
end | ||
|
||
# Automatically open the HTML report in a browser. | ||
def self.open_in_browser(path) | ||
Launchy.open(path) do |exception| | ||
warn "Attempted to open #{path} and failed because #{exception}".red | ||
end | ||
end | ||
|
||
# Locate the output directory, and convert the latest markdown file to HTML. | ||
def self.to_html | ||
latest_md = | ||
FileList["#{LinkChecker::DIR}/*.md"].max_by { |file| File.mtime file } | ||
|
||
print "Reading the #{latest_md} ... ".magenta | ||
# Change a file extension to .html | ||
html_file = latest_md.ext('html') | ||
File.open(html_file, 'w') do |file| | ||
print 'converting to HTML ... '.magenta | ||
file.write kramdown(content(latest_md)) | ||
file.write CSS | ||
end | ||
|
||
# Open the HTML report in browser | ||
print 'opening the converted report in browser ... '.magenta | ||
open_in_browser(html_file) | ||
puts 'Done!'.green | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Custom check for html-proofer to find double forward slashes in URLs. | ||
module LinkChecker | ||
class DoubleSlashCheck < ::HTMLProofer::Check | ||
def slash? | ||
return false if @link.href.nil? | ||
@link.href.match %r{\w//} | ||
end | ||
|
||
def run | ||
@html.css('a').each do |node| | ||
@link = create_element(node) | ||
line = node.line | ||
|
||
if slash? | ||
return add_issue("Remove double forward slashes from URLs", line: line) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
# Helper methods to configure and run html-proofer | ||
module LinkChecker | ||
# Run html-proofer to check the generated HTML pages | ||
def self.check_site | ||
HTMLProofer.check_directory('_site', options).run | ||
end | ||
|
||
# Read options from the '_config.checks.yml' | ||
# Ignore baseurl if $branch is available in environment | ||
def self.options | ||
config = YAML.load_file('_config.checks.yml') | ||
baseurl = ENV['branch'] | ||
return config['html-proofer'] unless baseurl | ||
url_swap = { url_swap: { %r{\A/#{baseurl}} => '' } } | ||
config['html-proofer'].merge(url_swap) | ||
end | ||
|
||
# Relative path for the link checker report | ||
def self.md_report_path | ||
# Create the directory if it doesn't exist | ||
FileUtils.mkdir_p DIR | ||
File.join DIR, file_name | ||
end | ||
|
||
# Name the directory for the link checker reports | ||
DIR = File.join 'tmp', '.htmlproofer' | ||
|
||
# Read the current Git branch | ||
def self.current_branch | ||
`git symbolic-ref --short HEAD`.strip | ||
end | ||
|
||
# Name the file for the link checker report | ||
def self.file_name | ||
prefix = 'broken-links-in-' | ||
timestamp = Time.now.strftime('_%m-%d_%H-%M-%S') | ||
prefix + current_branch + timestamp + '.md' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace :multirepo do | ||
desc 'Add docs from external repositories (mftf, page-builder)' | ||
task :init do | ||
sh './scripts/docs-from-code.sh mftf git@github.com:magento-devdocs/magento2-functional-testing-framework.git docs-in-code' | ||
sh './scripts/docs-from-code.sh page-builder git@github.com:magento-devdocs/magento2-page-builder.git ds_docs-in-code' | ||
sh './scripts/docs-from-code.sh mbi git@github.com:magento/devdocs-mbi.git master' | ||
end | ||
|
||
desc 'Add multirepo docs providing arguments "dir", "repo", and "branch". Example: rake multirepo:add dir=mftf repo=git@github.com:magento-devdocs/magento2-functional-testing-framework.git branch=docs-in-code' | ||
task :add do | ||
dir = ENV['dir'] | ||
repo = ENV['repo'] | ||
branch = ENV['branch'] | ||
|
||
abort 'Provide a directory name for the multirepo docs. Example: dir=mftf' unless dir | ||
abort "'#{dir}' directory already exists" if Dir.exist? dir | ||
abort 'Provide a repository cloning URL (SSH).Example: repo=git@github.com:magento-devdocs/magento2-functional-testing-framework.git' unless repo | ||
abort 'Provide a branch name for the multirepo docs. Example: branch=master' unless branch | ||
|
||
sh "./scripts/docs-from-code.sh #{dir} #{repo} #{branch}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
dir=$1 | ||
repo=$2 | ||
branch=$3 | ||
|
||
echo "Creating a directory: $dir" | ||
mkdir "$dir" | ||
cd "$dir" || exit | ||
|
||
echo 'Initiating git in the directory' | ||
git init | ||
|
||
echo "Adding a remote repository: $repo" | ||
git remote add origin -f "$repo" | ||
|
||
echo 'Enabling sparse checkout' | ||
git config core.sparseCheckout true | ||
|
||
echo 'Adding /docs/* to sparse checkout' | ||
echo '/docs/*' >> .git/info/sparse-checkout | ||
|
||
echo "Checkouting a branch: $branch" | ||
git checkout "$branch" | ||
cd .. |