Skip to content

Instantly share code, notes, and snippets.

@autarch
Created January 8, 2022 16:46
Show Gist options
  • Save autarch/4b3d04bb08639eb0413c7bde8d9b65ce to your computer and use it in GitHub Desktop.
Save autarch/4b3d04bb08639eb0413c7bde8d9b65ce to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use v5.24;
use strict;
use warnings;
use autodie qw( :all );
use LWP::UserAgent;
use Mojo::DOM;
use Path::Tiny qw( tempfile );
my $uri = shift // 'https://houseabsolute.com/resume/';
my $ua = LWP::UserAgent->new;
# If we use the default agent it looks like render returns a 403 :(
$ua->agent('resume-pdf/1.0');
my $response = $ua->get($uri);
unless ( $response->is_success ) {
my $msg = 'Got ' . $response->code . " from $uri";
my $content = $response->decoded_content;
$msg .= "\n$content\n"
if $content;
die $msg;
}
my $html = $response->decoded_content;
my $dom = Mojo::DOM->new($html);
my $content = $dom->find('article')->first;
$dom->find('.web-only')->each( sub { $_->remove } );
$dom->find('h1')->first->remove;
my $head = sprintf( <<'EOF', $uri, $uri );
<h1>Dave Rolsky</h1>
<h2>
<a href="mailto:[email protected]">[email protected]</a>
<br>
<a href="tel:+1-612-555-1234">612-555-1234</a>
</h2>
<p>
The most up to date version of my resume can always be found online at<br>
<a href="%s">%s</a>.
</p>
<hr>
EOF
my $clean = $head . $content->children->join("\n");
$clean =~ s{ <i[^>]+class="fab fa-github"[^>]*></i>}{};
my $t = tempfile();
$t->spew_utf8($clean);
my $target = '/home/autarch/misc/job/resume.pdf';
my @vars = (
'-V', 'pagesize:letter',
'-V', 'linkcolor:Blue',
(
map { ( '-V', 'margin-' . $_ . ':1.0in' ) }
qw( top bottom left right )
),
);
system(
'pandoc',
$t,
@vars,
qw( -f html -t latex -o ), $target
);
system( 'xdg-open', $target );
__END__
Copyright © 2022 David Rolsky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment