protected function createPageFile(DirectoryPath $repositoryPath, DirectoryPath $directoryPath, SplFileInfo $file) { $pageFile = new PageFile($repositoryPath->toAbsoluteFileString(), $directoryPath->toRelativeFileString(), $file->getRelativePathName()); $title = $this->elasticsearchRepository->getTitle($pageFile->getAbsolutePath()); if (empty($title)) { $title = $pageFile->getRelativePath()->getFileName(); } $pageFile->setTitle($title); return $pageFile; }
/** * __construct */ protected function __construct(SplFileInfo $file, $language = 'en') { $parser = app(Parser::class); $this->metadata = $parser->frontmatter($file->getContents()); $this->title = isset($this->metadata['PageTitle']) ? $this->metadata['PageTitle'] : (isset($this->metadata['Title']) ? $this->metadata['Title'] : Content::filename_to_title($file->getFilename())); $this->slug = Content::str_to_slug($this->title); if (ends_with($file->getRelativePathName(), 'index.md')) { $this->is_section_home = true; } $this->level = count(array_filter(explode(DIRECTORY_SEPARATOR, $file->getRelativePath()))); $relativePath = str_replace('\\', '/', $file->getRelativePath()); $this->is_homepage = $this->level === 0 && $this->is_section_home; if ($this->level > 0 && $this->is_section_home) { $this->path = $relativePath; } else { $relativePath = $relativePath . (ends_with($relativePath, '/') ? '' : '/'); $this->path = $relativePath . $this->slug; } $this->language = $language; $this->file = $file; $this->order = isset($this->metadata['Order']) ? $this->metadata['Order'] : (isset($this->metadata['Sort']) ? $this->metadata['Sort'] : 0); }
/** * Determine the target path. * * @param SplFileInfo $file * @return string */ protected function setTarget(SplFileInfo $file) { // Page extension $ext = $file->getExtension(); // Twig templates are HTML if (!$this->has('template') || $this->get('template') === 'none') { $targetExt = $ext; } else { $targetExt = 'html'; } // Get clean source path $sourcePath = $this->getCleanPath($file->getRelativePathName()); // Replace source extension with that of the template $this->target = substr($sourcePath, 0, -strlen($ext)); $this->target .= $targetExt; }
/** * @param DirectoryPath $repositoryPath * @param DirectoryPath $directoryPath * @param SplFileInfo $file * * @return PageFile */ protected function createPageFile(DirectoryPath $repositoryPath, DirectoryPath $directoryPath, SplFileInfo $file) { $pageFile = new PageFile($repositoryPath->toAbsoluteFileString(), $directoryPath->toRelativeFileString(), $file->getRelativePathName()); $pageFile->setTitle($pageFile->getRelativePath()->getFileName()); return $pageFile; }