Sculpin\Core\Permalink\SourcePermalinkFactory::generatePermalinkPathname PHP Method

generatePermalinkPathname() protected method

protected generatePermalinkPathname ( Sculpin\Core\Source\SourceInterface $source )
$source Sculpin\Core\Source\SourceInterface
    protected function generatePermalinkPathname(SourceInterface $source)
    {
        $pathname = $source->relativePathname();
        // Make sure that twig files end up as .html files.
        $pathname = preg_replace('/(html\\.)?twig$|twig\\.html$/', 'html', $pathname);
        $date = $source->data()->get('calculated_date');
        $title = $source->data()->get('title');
        $slug = $source->data()->get('slug');
        if (!($permalink = $source->data()->get('permalink'))) {
            $permalink = $this->defaultPermalink;
        }
        switch ($permalink) {
            case 'none':
                return $pathname;
                break;
            case 'pretty':
                if ($response = $this->isDatePath($pathname)) {
                    return implode('/', array_merge($response, array('index.html')));
                } else {
                    $pretty = preg_replace('/(\\.[^\\.\\/]+|\\.[^\\.\\/]+\\.[^\\.\\/]+)$/', '', $pathname);
                    if (basename($pretty) == 'index') {
                        return $pretty . '.html';
                    } else {
                        return $pretty . '/index.html';
                    }
                }
                break;
            case 'date':
                if ($response = $this->isDatePath($pathname)) {
                    return implode('/', $response) . '.html';
                }
                return preg_replace('/(\\.[^\\.]+|\\.[^\\.]+\\.[^\\.]+)$/', '', $pathname) . '.html';
                break;
            default:
                list($year, $yr, $month, $mo, $day, $dy) = explode('-', date('Y-y-m-n-d-j', (int) $date));
                $permalink = preg_replace('/:year/', $year, $permalink);
                $permalink = preg_replace('/:yr/', $yr, $permalink);
                $permalink = preg_replace('/:month/', $month, $permalink);
                $permalink = preg_replace('/:mo/', $mo, $permalink);
                $permalink = preg_replace('/:day/', $day, $permalink);
                $permalink = preg_replace('/:dy/', $dy, $permalink);
                $permalink = preg_replace('/:title/', $this->normalize($title), $permalink);
                $permalink = preg_replace('/:slug_title/', $this->normalize($slug ?: $title), $permalink);
                $filename = $pathname;
                if ($isDatePath = $this->isDatePath($pathname)) {
                    $filename = $isDatePath[3];
                }
                $permalink = preg_replace('/:filename/', $filename, $permalink);
                $permalink = preg_replace('/:slug_filename/', $this->normalize($slug ?: $filename), $permalink);
                if (strrpos($filename, DIRECTORY_SEPARATOR) !== false) {
                    $basename = substr($filename, strrpos($filename, DIRECTORY_SEPARATOR) + 1);
                } else {
                    $basename = $filename;
                }
                $prettyBasename = false !== strrpos($basename, '.') ? substr($basename, 0, strrpos($basename, '.')) : $basename;
                $permalink = preg_replace('/:basename_real/', $basename, $permalink);
                $permalink = preg_replace('/:basename/', $prettyBasename, $permalink);
                if (substr($permalink, -1, 1) == '/') {
                    $permalink .= 'index.html';
                }
                return $permalink;
                break;
        }
    }