mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Move the perl part to add-link.pl
Signed-off-by: Yuan Fang <yuanfang@alauda.io>
This commit is contained in:
parent
5224403c15
commit
892008359f
@ -13,9 +13,9 @@ function add_github_link_to_examples {
|
||||
EOF
|
||||
)
|
||||
|
||||
# TODO use specific example link (e.g. https://github.com/roc-lang/examples/tree/main/examples/FizzBuzz) for every example
|
||||
local examples_link="https://github.com/roc-lang/examples"
|
||||
# Use specific example link (e.g. https://github.com/roc-lang/examples/tree/main/examples/FizzBuzz) for every example
|
||||
local examples_link="https://github.com/roc-lang/examples/tree/main/examples"
|
||||
|
||||
# TODO move perl stuff to add-link.pl
|
||||
find $examples_dir_path -type f -name "README.html" -exec perl -MFile::Basename -pi -e "(\$name = dirname(\$ARGV)); s!</h1>!</h1><a id='gh-example-link' href=\"\$name\" aria-label='view on github'>$github_logo_svg</a>!; s!href=\"$examples_dir_path!href=\"$examples_link!" {} \;
|
||||
# Insert a github link to the example in HTML
|
||||
find "$examples_dir_path" -type f -name "README.html" -exec perl scripts/add-link.pl "$examples_dir_path" "$examples_link" "$github_logo_svg" {} \;
|
||||
}
|
@ -1 +1,24 @@
|
||||
# TODO
|
||||
#!/usr/bin/perl
|
||||
|
||||
use File::Basename;
|
||||
|
||||
sub add_link {
|
||||
my $examples_dir_path = shift;
|
||||
my $examples_gh_link = shift;
|
||||
my $github_logo_svg = shift;
|
||||
my $file_path = shift;
|
||||
my $file_dir = dirname($file_path);
|
||||
|
||||
open my $fh, '<', $file_path or die "Can't open $file_path: $!";
|
||||
my $content = do { local $/; <$fh> };
|
||||
close $fh;
|
||||
|
||||
$content =~ s!</h1>!</h1><a id="gh-example-link" href="$file_dir" aria-label="view on github">$github_logo_svg</a>!;
|
||||
$content =~ s!href=\"$examples_dir_path!href=\"$examples_gh_link!;
|
||||
|
||||
open my $fh, '>', $file_path or die "Can't open $file_path: $!";
|
||||
print $fh $content;
|
||||
close $fh;
|
||||
}
|
||||
|
||||
add_link @ARGV
|
Loading…
Reference in New Issue
Block a user