Oh, I hadn’t yet heard of that use case!
You should be able to filter the status messages, like use PHP’s str_replace() to replace the local with your public domain. This of course requires you’re able to add code snippets someplace, like in functions.php, a custom (must-use) plugin, or through the use of a separate “code snippets” plugin:
Just a quick example:
add_filter( 'share_on_mastodon_status', function( $status, $post ) {
$status = str_replace( 'http://localhost.test/', 'https://www.example.org/', $status );
return $status;
}, 10, 2 );
This would modify the message before it gets sent to your Mastodon server.
Of course, depending on how or when the static pages are pushed to your web host, Mastodon instances might temporarily hit a 404 and cache the wrong link preview data. (It might be possible to work around that by setting a delay, under the plugin’s advanced settings. But maybe I’m overthinking things.)