private function convertItem(ItemInterface $item) { $this->eventDispatcher->dispatch('spress.before_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_RAW, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $ext = pathinfo($path, PATHINFO_EXTENSION); $result = $this->converterManager->convertContent($item->getContent(), $ext); $newPath = preg_replace('/\\.' . $ext . '$/', '.' . $result->getExtension(), $path); $item->setContent($result->getResult(), ItemInterface::SNAPSHOT_AFTER_CONVERT); $item->setPath($newPath, ItemInterface::SNAPSHOT_PATH_RELATIVE); $this->eventDispatcher->dispatch('spress.after_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_AFTER_CONVERT, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $this->siteAttribute->setItem($item); }
private function convertItem(ItemInterface $item) { $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); if ($item->isBinary() === true) { $item->setPath($path, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT); return; } $this->eventDispatcher->dispatch('spress.before_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_RAW, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $result = $this->converterManager->convertItem($item); $str = new StringWrapper($path); $filenameWithoutExtension = $str->deleteSufix($result->getInputExtension()); $newPath = $filenameWithoutExtension . $result->getExtension(); $item->setContent($result->getResult(), ItemInterface::SNAPSHOT_AFTER_CONVERT); $item->setPath($newPath, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT); $this->eventDispatcher->dispatch('spress.after_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_AFTER_CONVERT, ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT)); }