From da494d90a0bf1e53d6e098a4351528b4df51e218 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 25 Jun 2021 12:23:55 -0700 Subject: [PATCH] Preserve Docker-provided "Sponsored Links" while updating descriptions --- push.pl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/push.pl b/push.pl index ffd157f0e..77c047041 100755 --- a/push.pl +++ b/push.pl @@ -69,6 +69,8 @@ my $userData = $ua->get('https://hub.docker.com/v2/user/' => $authorizationHeade die 'user failed' unless $userData->res->is_success; $userData = $userData->res->json; +my $supportedTagsRegex = qr%^(# Supported tags and respective `Dockerfile` links\n\n)(.*?\n)(?=# |\[)%ms; + sub prompt_for_edit { my $currentText = shift; my $proposedFile = shift; @@ -80,6 +82,14 @@ sub prompt_for_edit { # remove our warning about generated files (Hub doesn't support HTML comments in Markdown) $proposedText =~ s% ^ \s* %%sx; + # extract/re-inject sponsored links + my $sponsoredLinks = ''; + if ($currentText =~ m{ ( ^ --- \n+ \Q*Useful Resources*\E \n .*? \n --- \n ) }smx) { + $sponsoredLinks = $1 . "\n"; + say $sponsoredLinks; + $proposedText =~ s%$supportedTagsRegex%$1$2$sponsoredLinks%; + } + my $alwaysShortTags = ($proposedFile eq 'neo4j/README.md'); if ($alwaysShortTags || ($lengthLimit > 0 && length($proposedText) > $lengthLimit)) { @@ -94,7 +104,7 @@ sub prompt_for_edit { my $trimmedText = $proposedText; # if our text is too long for the Hub length limit, let's first try removing the "Supported tags" list and add $tagsNote and see if that's enough to let us put the full image documentation - $trimmedText =~ s%^(# Supported tags and respective `Dockerfile` links\n\n).*?\n(?=# |\[)%$1$tagsNote%ms; + $trimmedText =~ s%$supportedTagsRegex%$1$tagsNote$sponsoredLinks%ms; # (we scrape until the next "h1" or a line starting with a link which is likely a build status badge for an architecture-namespace) $proposedText = $trimmedText if $alwaysShortTags;