Skip to content

Commit b5b38d7

Browse files
committed
rewrite getURL
1 parent 752203c commit b5b38d7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

resources/lib/utils.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,15 @@ function pathNormalize(string $path)
7979

8080
function getURL(...$relative_url_components)
8181
{
82-
$url_components = array_merge(
83-
[CONFIG["site"]["url"], CONFIG["site"]["prefix"]],
84-
$relative_url_components,
85-
);
86-
$url = join("/", $url_components);
87-
// if URL starts with a "scheme" like "https://", do not try to alter the slashes in the scheme
88-
if (preg_match("#^\w+://#", $url)) {
89-
$matches = [];
90-
preg_match("#(^\w+://)(.*)#", $url, $matches);
91-
return $matches[1] . pathNormalize($matches[2]);
92-
} else {
93-
return pathNormalize($url);
82+
if (!preg_match("#^\w+://#", CONFIG["site"]["url"])) {
83+
throw new RuntimeException('CONFIG[site][url] does not have a scheme! (ex: "https://")');
9484
}
85+
$matches = [];
86+
preg_match("#(^\w+://)(.*)#", CONFIG["site"]["url"], $matches);
87+
[$_, $site_url_scheme, $site_url_noscheme] = $matches;
88+
$path = join("/", [$site_url_noscheme, CONFIG["site"]["prefix"], ...$relative_url_components]);
89+
$path_normalized = pathNormalize($path);
90+
return $site_url_scheme . $path_normalized;
9591
}
9692

9793
function getHyperlink($text, ...$url_components)

0 commit comments

Comments
 (0)