/** * __construct */ protected function __construct(SplFileInfo $file, $relativePath = null) { $this->title = Content::filename_to_title($file->getFilename()); $this->slug = Content::str_to_slug($file->getFilename()); $relativePath = !is_null($relativePath) && !empty($relativePath) ? $relativePath : $file->getRelativePath(); $this->path = $relativePath . (ends_with($relativePath, '/') ? '' : '/') . $this->slug; $this->file = $file; }
/** * __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); }