Skip to content

Commit

Permalink
refactor: simplify mobile about text handling
Browse files Browse the repository at this point in the history
  • Loading branch information
coignard committed Nov 8, 2024
1 parent 3d0224f commit 0d4475a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
16 changes: 6 additions & 10 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

final class Config
{
private const VERSION = '1.18.3';
private const VERSION = '1.18.4';
private const CONFIG_PATH = __DIR__.'/../config.ini';

/**
Expand Down Expand Up @@ -145,22 +145,18 @@ private function handleMobileDevice(): void
$this->showDate = false;
$this->showCopyright = false;
$this->showUrls = ShowUrls::OFF;

if (isset($this->config['about_text_alt'])) {
$this->author->setAbout(
StringUtils::sanitizeText(
$this->getString('about_text_alt') ?? $this->author->getAbout()
)
);
}
}

private function setAuthor(): void
{
$name = $this->getString('author_name') ?? $this->author->getName();
$email = $this->getString('author_email') ?? $this->author->getEmail();
$location = $this->getString('author_location') ?? $this->author->getLocation();
$aboutText = StringUtils::sanitizeText($this->getString('about_text') ?? $this->author->getAbout());

$aboutText = Validator::isMobileDevice() && isset($this->config['about_text_alt'])
? $this->getString('about_text_alt')
: $this->getString('about_text');
$aboutText = StringUtils::sanitizeText($aboutText ?? $this->author->getAbout());

$this->author = new Author(
name: $name,
Expand Down
7 changes: 0 additions & 7 deletions src/Model/Entity/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
namespace Weblog\Model\Entity;

use Weblog\Config;
use Weblog\Utils\StringUtils;
use Weblog\Model\Enum\Beautify;

final class Author
{
Expand Down Expand Up @@ -59,11 +57,6 @@ public function getAbout(): string
return $this->aboutText;
}

public function setAbout(string $aboutText): void
{
$this->aboutText = StringUtils::formatAboutText($aboutText);
}

public function getInformation(): string
{
return $this->email ?? $this->name;
Expand Down
16 changes: 0 additions & 16 deletions src/Utils/StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,6 @@ public static function containsIgnoreCaseAndDiacritics(string $haystack, string
return mb_strpos($haystack, $needle) !== false;
}

/**
* Cleans a slug from extensions.
*
* @return string the formatted string
*/
public static function formatAboutText(string $text): string
{
$text = preg_replace('/\.(\s)/', '. $1', rtrim($text));

if (null === $text) {
throw new \RuntimeException('Failed to format text.');
}

return str_replace('\\n', "\n", $text);
}

/**
* Cleans a slug from extensions.
*
Expand Down

0 comments on commit 0d4475a

Please sign in to comment.