Preserve HTML during CDN rewrites and refine SHNU benefits layout
This commit is contained in:
+27
-9
@@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use RuntimeException;
|
||||
|
||||
final class Assets
|
||||
@@ -33,13 +31,33 @@ final class Assets
|
||||
if ($cdn === '') {
|
||||
return $html;
|
||||
}
|
||||
$document = new DOMDocument('1.0', 'UTF-8');
|
||||
$document->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
|
||||
$xpath = new DOMXPath($document);
|
||||
foreach ($xpath->query('//@src | //@href | //@poster') as $attribute) {
|
||||
$attribute->value = self::url($attribute->value, $cdn);
|
||||
}
|
||||
|
||||
return $document->saveHTML();
|
||||
// Match opening tags separately from comments and text-only elements' contents.
|
||||
$tags = <<<'REGEX'
|
||||
~<!--.*?(?:-->|\z)|(?<opening><(?:(?<textTag>script|style|textarea|title)|[a-z][\w:-]*)(?=[\s/>])(?:[^<>"']++|"[^"]*"|'[^']*')*+>)(?(textTag)(?<tail>.*?(?:</\k<textTag>\s*>|\z)))~is
|
||||
REGEX;
|
||||
$attributes = <<<'REGEX'
|
||||
~(\s+)([^\s/<>="']+)(?:(\s*=\s*)("[^"]*"|'[^']*'|[^\s<>"'=`]+))?~
|
||||
REGEX;
|
||||
|
||||
return preg_replace_callback($tags, static function (array $tag) use ($attributes, $cdn): string {
|
||||
if (!isset($tag['opening'])) {
|
||||
return $tag[0];
|
||||
}
|
||||
|
||||
$opening = preg_replace_callback($attributes, static function (array $attribute) use ($cdn): string {
|
||||
if (!isset($attribute[4]) || !in_array(strtolower($attribute[2]), ['src', 'href', 'poster'], true)) {
|
||||
return $attribute[0];
|
||||
}
|
||||
|
||||
$value = $attribute[4];
|
||||
$quote = str_starts_with($value, '"') || str_starts_with($value, "'") ? $value[0] : '';
|
||||
$path = $quote === '' ? $value : substr($value, 1, -1);
|
||||
|
||||
return $attribute[1] . $attribute[2] . $attribute[3] . $quote . self::url($path, $cdn) . $quote;
|
||||
}, $tag['opening']) ?? $tag['opening'];
|
||||
|
||||
return $opening . ($tag['tail'] ?? '');
|
||||
}, $html) ?? $html;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,6 +387,38 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
||||
.catalog-content .overline { margin-bottom: .4rem; }
|
||||
.catalog-content .actions { margin-top: auto; padding-top: 1rem; }
|
||||
|
||||
.hero-shnu-sc ~ #benefits { background: #f7f9fe; padding-block: clamp(3.25rem, 6vw, 6rem); }
|
||||
.hero-shnu-sc ~ #benefits .section-heading { margin-bottom: 1.25rem; }
|
||||
.hero-shnu-sc ~ #benefits h2 { font-size: clamp(1.85rem, 3.35vw, 3rem); }
|
||||
.hero-shnu-sc ~ #benefits .rich > p { margin-bottom: .85rem; }
|
||||
.hero-shnu-sc ~ #benefits .rich > ul { padding-left: 1.35rem; }
|
||||
.hero-shnu-sc ~ #benefits .rich > ul li + li { margin-top: .35rem; }
|
||||
.hero-shnu-sc ~ #benefits .rich > ul li::marker { color: var(--accent); }
|
||||
.hero-shnu-sc ~ #benefits .rich > img {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 .75rem 2.25rem #101c341a;
|
||||
}
|
||||
@media (min-width: 52rem) {
|
||||
.hero-shnu-sc ~ #benefits > .wrap:has(> .rich > p:first-child + ul + img:last-child) {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
|
||||
gap: .8rem clamp(2rem, 5vw, 5.5rem);
|
||||
align-content: center;
|
||||
}
|
||||
.hero-shnu-sc ~ #benefits > .wrap:has(> .rich > p:first-child + ul + img:last-child) > .rich { display: contents; }
|
||||
.hero-shnu-sc ~ #benefits > .wrap:has(> .rich > p:first-child + ul + img:last-child) :is(.section-heading, .rich > p, .rich > ul) {
|
||||
grid-column: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.hero-shnu-sc ~ #benefits > .wrap:has(> .rich > p:first-child + ul + img:last-child) .rich > img {
|
||||
grid-column: 2;
|
||||
grid-row: 1 / span 3;
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
|
||||
.copyright-service #materials .feature-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.copyright-service #why .choice-card { background: #e9f0ff; border-color: #7599ec; box-shadow: inset 0 3px var(--accent); }
|
||||
.copyright-service #why .choice-card h3 { color: var(--accent-deep); }
|
||||
|
||||
Reference in New Issue
Block a user