Skip to content

Commit

Permalink
Move enforceTrailingSlash to PageVariable; skip any paths that are files
Browse files Browse the repository at this point in the history
  • Loading branch information
damiani committed May 17, 2024
1 parent 538a15f commit 69e6bee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
24 changes: 20 additions & 4 deletions src/PageVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function __call($method, $args)
public function getPath($key = null)
{
if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
return enforceTrailingSlash($this->_meta->path->get($key ?: $this->getExtending()));
return $this->enforceTrailingSlash($this->_meta->path->get($key ?: $this->getExtending()));
}

return enforceTrailingSlash((string) $this->_meta->path);
return $this->enforceTrailingSlash((string) $this->_meta->path);
}

public function getPaths()
Expand All @@ -46,10 +46,10 @@ public function getPaths()
public function getUrl($key = null)
{
if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
return enforceTrailingSlash($this->_meta->url->get($key ?: $this->getExtending()));
return $this->enforceTrailingSlash($this->_meta->url->get($key ?: $this->getExtending()));
}

return enforceTrailingSlash((string) $this->_meta->url);
return $this->enforceTrailingSlash((string) $this->_meta->url);
}

public function getUrls()
Expand All @@ -61,4 +61,20 @@ protected function missingHelperError($functionName)
{
return 'No function named "' . $functionName . '" was found in the file "config.php".';
}

protected function enforceTrailingSlash($path)
{
return $path && app()->config->get('trailing_slash') && ! $this->pathIsFile($path)
? Str::finish($path, '/')
: $path;
}

protected function pathIsFile($path)
{
$final_extension = $this->_meta->extending
? (Str::contains(Str::afterLast($path, '/'), '.') ? Str::afterLast($path, '.') : null)
: Str::afterLast($this->_meta->extension, '.');

return $final_extension && $final_extension !== 'md' && $final_extension !== 'php';
}
}
7 changes: 0 additions & 7 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ function trimPath($path)
return rightTrimPath(leftTrimPath($path));
}

function enforceTrailingSlash($path)
{
$c = Container::getInstance();

return Arr::get($c['config'], 'trailing_slash') ? Str::finish($path, '/') : $path;
}

function resolvePath($path)
{
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
Expand Down

0 comments on commit 69e6bee

Please sign in to comment.