Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RSS image handling and feed and sitemap generation processes #435

Merged
merged 24 commits into from
May 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
911a0da
Create Action class to find Image content lengths
caendesilva May 20, 2022
a10c1c3
Fetch information for local images
caendesilva May 20, 2022
6173a1a
Fetch information for remote images
caendesilva May 20, 2022
6a494a5
Add experimental support for remote images
caendesilva May 20, 2022
e827132
Move execution tests for subprocess
caendesilva May 20, 2022
82c73a3
Create build:sitemap command
caendesilva May 20, 2022
f995532
Add a preflight check
caendesilva May 20, 2022
65c25f8
Fix the test
caendesilva May 20, 2022
1c2a927
Require blog post feature to be enabled
caendesilva May 20, 2022
b2196a3
Wrap debug output in conditional
caendesilva May 20, 2022
97e9cbc
Only send debug info for HTTP calls and failures
caendesilva May 20, 2022
ac4788f
Create HydeBuildRssFeedCommand.php
caendesilva May 20, 2022
aac87ac
Move execution tests for subprocess
caendesilva May 20, 2022
2543b33
Create HydeBuildRssFeedCommandTest.php
caendesilva May 20, 2022
b236b4c
Add remote image preflight check
caendesilva May 20, 2022
0ec6d49
Reduce code complexity
caendesilva May 20, 2022
ad764ac
Offload RSS feed and sitemap generation to subcommands
caendesilva May 20, 2022
236b475
Inline method reducing undue complexity
caendesilva May 20, 2022
25e4e87
Remove unused internal method
caendesilva May 20, 2022
3fe8cfb
Add RSS and sitemap information to the docs
caendesilva May 20, 2022
4cb7c2f
Register the new commands
caendesilva May 20, 2022
2d24525
Normalize enclosure to URI paths for local images
caendesilva May 20, 2022
bc1e3ac
Apply fixes from StyleCI
StyleCIBot May 20, 2022
a017c40
Merge pull request #433 from hydephp/analysis-KZEVr3
May 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wrap debug output in conditional
  • Loading branch information
caendesilva committed May 20, 2022
commit b2196a30c340f1a5eb1ffe2420307879cfc800ea
27 changes: 18 additions & 9 deletions src/Actions/FindsContentLengthForImageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ class FindsContentLengthForImageObject implements ActionContract
*/
protected OutputInterface $output;

public function __construct(Image $image)
public function __construct(Image $image, bool $withOutput = false)
{
$this->image = $image;

$this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
if ($withOutput) {
$this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
}
}

public function execute(): int
{
$this->output->writeln('Attempting to find content length for image object...');
$this->write('Attempting to find content length for image object...');

if ($this->isImageStoredRemotely()) {
return $this->fetchRemoteImageInformation();
Expand All @@ -44,7 +46,7 @@ protected function isImageStoredRemotely(): bool

protected function fetchRemoteImageInformation(): int
{
$this->output->writeln('Fetching remote image information...');
$this->write('Fetching remote image information...');

$response = Http::withHeaders([
'User-Agent' => config('hyde.http_user_agent', 'RSS Request Client'),
Expand All @@ -54,27 +56,34 @@ protected function fetchRemoteImageInformation(): int
$headers = $response->headers();

if (array_key_exists('Content-Length', $headers)) {
$this->output->writeln('Found content length in headers.');
$this->write('Found content length in headers.');
return (int) key(array_flip($headers['Content-Length']));
}

$this->output->writeln('<comment>Warning</comment> Could not find content length in headers.');
$this->write('<comment>Warning</comment> Could not find content length in headers.');

return 0;
}

protected function fetchLocalImageInformation(): int
{
$this->output->writeln('Fetching local image information...');
$this->write('Fetching local image information...');

if (! file_exists($this->image->getSource())) {
$this->output->writeln('<comment>Warning</comment> Could not find image file.');
$this->write('<comment>Warning</comment> Could not find image file.');

return 0;
}

$this->output->writeln('Found image file.');
$this->write('Found image file.');

return filesize($this->image->getSource());
}

protected function write(string $string): void
{
if (isset($this->output)) {
$this->output->writeln($string);
}
}
}