style updates
This commit is contained in:
@@ -13,14 +13,20 @@ final class ThemeHtmlBuilder
|
||||
public function stylesheet(?string $path = null): HtmlString
|
||||
{
|
||||
$path ??= $this->stylist->current()->stylesheet();
|
||||
if (! $this->stylist->current()->has($path)) return new HtmlString('');
|
||||
if (! $this->stylist->current()->has($path)) {
|
||||
return new HtmlString('');
|
||||
}
|
||||
|
||||
return new HtmlString('<link rel="stylesheet" href="'.e($this->url->asset($path)).'">');
|
||||
}
|
||||
|
||||
public function script(?string $path = null): HtmlString
|
||||
{
|
||||
$path ??= $this->stylist->current()->script();
|
||||
if (! $this->stylist->current()->has($path)) return new HtmlString('');
|
||||
if (! $this->stylist->current()->has($path)) {
|
||||
return new HtmlString('');
|
||||
}
|
||||
|
||||
return new HtmlString('<script src="'.e($this->url->asset($path)).'" defer></script>');
|
||||
}
|
||||
|
||||
@@ -32,11 +38,15 @@ final class ThemeHtmlBuilder
|
||||
|
||||
foreach ($theme->appearances() as $name => $definition) {
|
||||
$vars = (array) data_get($definition, 'variables', []);
|
||||
if ($vars) $rules[] = ':root[data-theme="'.$this->selector($name).'"]{'.$this->declarations($vars).'}';
|
||||
if ($vars) {
|
||||
$rules[] = ':root[data-theme="'.$this->selector($name).'"]{'.$this->declarations($vars).'}';
|
||||
}
|
||||
}
|
||||
foreach ($theme->accents() as $name => $definition) {
|
||||
$vars = (array) data_get($definition, 'variables', []);
|
||||
if ($vars) $rules[] = ':root[data-accent="'.$this->selector($name).'"]{'.$this->declarations($vars).'}';
|
||||
if ($vars) {
|
||||
$rules[] = ':root[data-accent="'.$this->selector($name).'"]{'.$this->declarations($vars).'}';
|
||||
}
|
||||
}
|
||||
|
||||
if ($theme->appearances() === [] && $theme->accents() === []) {
|
||||
|
||||
@@ -9,15 +9,36 @@ use Modules\Stylist\Theme\UrlGenerator;
|
||||
final class ThemeSeoBuilder
|
||||
{
|
||||
public function __construct(private readonly Stylist $stylist, private readonly UrlGenerator $urls) {}
|
||||
public function render(array $overrides=[]): HtmlString
|
||||
|
||||
public function render(array $overrides = []): HtmlString
|
||||
{
|
||||
$theme=$this->stylist->current(); $seo=array_replace($theme->seo(),$overrides); $settings=$this->stylist->settings();
|
||||
$title=(string)($seo['title']??$settings['site_title']??$theme->name()); $description=(string)($seo['description']??$settings['site_description']??$theme->description());
|
||||
$image=$seo['image']??$theme->preview(); if($image && $theme->has($image))$image=$this->urls->asset($image);
|
||||
$tags=['<title>'.e($title).'</title>']; if($description!=='')$tags[]='<meta name="description" content="'.e($description).'">';
|
||||
foreach(['og:title'=>$title,'og:description'=>$description,'twitter:card'=>'summary_large_image','twitter:title'=>$title,'twitter:description'=>$description] as $property=>$content){if($content==='')continue;$attribute=str_starts_with($property,'og:')?'property':'name';$tags[]='<meta '.$attribute.'="'.e($property).'" content="'.e($content).'">';}
|
||||
if($image){$tags[]='<meta property="og:image" content="'.e($image).'">';$tags[]='<meta name="twitter:image" content="'.e($image).'">';}
|
||||
if(isset($seo['json_ld'])&&is_array($seo['json_ld']))$tags[]='<script type="application/ld+json">'.json_encode($seo['json_ld'],JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE).'</script>';
|
||||
return new HtmlString(implode("\n",$tags));
|
||||
$theme = $this->stylist->current();
|
||||
$seo = array_replace($theme->seo(), $overrides);
|
||||
$settings = $this->stylist->settings();
|
||||
$title = (string) ($seo['title'] ?? $settings['site_title'] ?? $theme->name());
|
||||
$description = (string) ($seo['description'] ?? $settings['site_description'] ?? $theme->description());
|
||||
$image = $seo['image'] ?? $theme->preview();
|
||||
if ($image && $theme->has($image)) {
|
||||
$image = $this->urls->asset($image);
|
||||
}
|
||||
$tags = ['<title>'.e($title).'</title>'];
|
||||
if ($description !== '') {
|
||||
$tags[] = '<meta name="description" content="'.e($description).'">';
|
||||
}
|
||||
foreach (['og:title' => $title, 'og:description' => $description, 'twitter:card' => 'summary_large_image', 'twitter:title' => $title, 'twitter:description' => $description] as $property => $content) {
|
||||
if ($content === '') {
|
||||
continue;
|
||||
}$attribute = str_starts_with($property, 'og:') ? 'property' : 'name';
|
||||
$tags[] = '<meta '.$attribute.'="'.e($property).'" content="'.e($content).'">';
|
||||
}
|
||||
if ($image) {
|
||||
$tags[] = '<meta property="og:image" content="'.e($image).'">';
|
||||
$tags[] = '<meta name="twitter:image" content="'.e($image).'">';
|
||||
}
|
||||
if (isset($seo['json_ld']) && is_array($seo['json_ld'])) {
|
||||
$tags[] = '<script type="application/ld+json">'.json_encode($seo['json_ld'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE).'</script>';
|
||||
}
|
||||
|
||||
return new HtmlString(implode("\n", $tags));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user