-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[i18n, CI] How to deal with broken links in non-en pages when updatin…
…g en pages (#5448)
- Loading branch information
Showing
9 changed files
with
196 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,5 @@ dictionaries: | |
- softwareTerms | ||
# Other | ||
- companies | ||
words: # Valid words across all locales | ||
- htmltest |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
--- | ||
title: Blog | ||
menu: | ||
main: { weight: 50 } | ||
menu: { main: { weight: 50 } } | ||
redirects: [{ from: '', to: '2024/ 301!' }] | ||
outputs: [HTML, RSS] | ||
htmltest: | ||
IgnoreDirs: | ||
- ^blog/(\d+/)?page/\d+ | ||
--- |
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
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
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,135 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my $gD = 0; | ||
|
||
sub main { | ||
my @ignore_dirs; | ||
|
||
collect_htmltest_config_from_front_matter(\@ignore_dirs, @ARGV); | ||
update_htmltest_config_file(\@ignore_dirs); | ||
} | ||
|
||
sub collect_htmltest_config_from_front_matter { | ||
my ($ignore_dirs_ref, @files) = @_; | ||
|
||
foreach my $file_path (@files) { | ||
my @htmltest_config = extract_htmltest_config($file_path); | ||
next unless @htmltest_config; | ||
push @$ignore_dirs_ref, @htmltest_config; | ||
} | ||
} | ||
|
||
sub extract_htmltest_config { | ||
# Returns list of htmlconfig lines extracted from the front matter of $file_path | ||
my ($file_path) = @_; | ||
|
||
open my $fh, '<', $file_path or die "Could not open '$file_path': $!"; | ||
my $content = do { local $/; <$fh> }; | ||
close $fh; | ||
|
||
return unless $content =~ /---\n(.*?)\n---/s; | ||
|
||
my $front_matter = $1; | ||
my @htmltest_config = _extract_htmltest_config($front_matter); | ||
|
||
return unless @htmltest_config; | ||
|
||
if (@htmltest_config == 1) { | ||
warn "Warning: Failed to extract htmltest config from front matter in file '$file_path'.\n"; | ||
return; | ||
} | ||
|
||
shift @htmltest_config; | ||
|
||
if (@htmltest_config >= 1 && $htmltest_config[0] =~ /^IgnoreDirs:/i) { | ||
return _extract_ignore_dirs($file_path, @htmltest_config) | ||
} | ||
|
||
# TODO: Add support for `IgnoreURLs`. | ||
|
||
warn "Warning: Unrecognized htmltest config from front matter in file '$file_path'.\n"; | ||
} | ||
|
||
sub _extract_ignore_dirs { | ||
my ($file_path, | ||
@ignore_dirs_config_lines # Can include comment lines | ||
) = @_; | ||
my @config; | ||
|
||
foreach my $line (@ignore_dirs_config_lines) { | ||
next if $line =~ /^IgnoreDirs:\s*$/i; | ||
if ($line =~ /\s*#/) { | ||
push @config, $line; | ||
} elsif ($line =~ /^IgnoreDirs:\s*\[\s*(.*?)\s*\]/i || $line =~ /^\s*-\s*(.*?)$/) { | ||
push @config, (split /\s*,\s*/, $1); | ||
} else { | ||
warn "Warning: Unrecognized htmltest IgnoreDirs config from front matter in file '$file_path': $line\n"; | ||
} | ||
} | ||
return @config; | ||
} | ||
|
||
sub _extract_htmltest_config { | ||
# Returns a list of htmltext config lines with whitespace trimmed away. | ||
|
||
my ($front_matter) = @_; | ||
my @lines = split /\n/, $front_matter; | ||
my @htmltest_lines; | ||
my $in_htmltest_section = 0; | ||
|
||
foreach my $line (@lines) { | ||
if ($line =~ /^htmltest:(.*?)(#.*)?$/) { | ||
$in_htmltest_section = 1; | ||
push @htmltest_lines, $line; | ||
} elsif ($in_htmltest_section) { | ||
if ($line =~ /^(\s{2,})(.*)$/) { | ||
push @htmltest_lines, $2; | ||
printf " > Config line: $line" if $gD; | ||
} else { | ||
last; | ||
} | ||
} | ||
} | ||
return @htmltest_lines; | ||
} | ||
|
||
sub update_htmltest_config_file { | ||
my ($ignore_dirs_ref) = @_; | ||
my $htmltest_config_path = '.htmltest.yml'; | ||
my $do_not_edit_msg = " # DO NOT EDIT! IgnoreDirs list is auto-generated from markdown file front matter.\n"; | ||
|
||
# Read config file as array of lines | ||
open my $fh, '<', $htmltest_config_path or die "Could not open '$htmltest_config_path' for reading: $!"; | ||
my @lines = <$fh>; | ||
close $fh; | ||
|
||
# Replace the existing IgnoreDirs entries with the new ones | ||
my $in_ignore_dirs = 0; | ||
my @new_lines; | ||
foreach my $line (@lines) { | ||
if ($line =~ /^IgnoreDirs:/) { | ||
push @new_lines, ($line, $do_not_edit_msg); | ||
foreach my $ignore_dir (@$ignore_dirs_ref) { | ||
my $prefix = $ignore_dir =~ /^#/ ? ' ' : ' - '; | ||
push @new_lines, "$prefix$ignore_dir\n"; | ||
} | ||
push @new_lines, $do_not_edit_msg; | ||
$in_ignore_dirs = 1; | ||
} elsif ($in_ignore_dirs) { | ||
next if $line =~ /^\s*([#-]|$)/; | ||
$in_ignore_dirs = 0; | ||
push @new_lines, $line; | ||
} else { | ||
push @new_lines, $line; | ||
} | ||
} | ||
|
||
open my $fh_out, '>', $htmltest_config_path or die "Could not open '$htmltest_config_path' for writing: $!"; | ||
print $fh_out @new_lines; | ||
close $fh_out; | ||
} | ||
|
||
main(); |
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,8 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# We handle listing all markdown files here because it is more portable across | ||
# supported operating systems. | ||
|
||
SCRIPT_DIR=$(dirname $0) | ||
FILES=$(find content -name "*.md") | ||
exec $SCRIPT_DIR/htmltest-config.pl $FILES |