Skip to content
Snippets Groups Projects

Issue 3389768: If we are give an XML file (e.g. the sitemap), resolve certain...

1 file
+ 30
0
Compare changes
  • Side-by-side
  • Inline
@@ -184,6 +184,9 @@ class StaticGenerator implements StaticGeneratorInterface {
$invoke_paths = array_merge($invoke_paths, $this->getHtmlAssets($content, $path), $event->getInvokePaths());
$invoke_paths = array_diff($invoke_paths, $event->getExcludePaths());
}
if (strpos($response->headers->get('Content-Type', ''), 'application/xml') === 0) {
$invoke_paths = array_merge($invoke_paths, $this->getXmlAssets($content, $path));
}
if (strpos($response->headers->get('Content-Type', ''), 'text/css') === 0) {
$invoke_paths = array_merge($invoke_paths, $this->getCssAssets($content, $path));
}
@@ -509,6 +512,33 @@ class StaticGenerator implements StaticGeneratorInterface {
return $paths;
}
/**
* Finds and exports assets for the given XML content.
*
* @param string $content
* An XML string.
* @param string $root
* A root path to resolve relative paths.
*
* @return array
* An array of paths found in the given XML string.
*/
protected function getXmlAssets($content, $root) {
$paths = [];
$document = new \DOMDocument();
@$document->loadHTML($content);
$xpath = new \DOMXPath($document);
/** @var \DOMProcessingInstruction $stylesheet */
foreach ($xpath->query('/processing-instruction("xml-stylesheet")') as $stylesheet) {
if (preg_match('/href="([^"]*)"/', $stylesheet->data, $matches)) {
if ($matches[1]) {
$paths[] = $matches[1];
}
}
}
return $paths;
}
/**
* Returns a destination for saving a given path.
*
Loading