Skip to content

Commit

Permalink
add $config->prod_hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
atas committed Oct 14, 2023
1 parent e4703c2 commit a8ecfd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"site_top_h1": "ata's ssg",
"site_top_about_line1": "Simple PHP-based Static Site generator",
"site_top_about_line2": "Supports Markdown and deployed to GitHub Pages by GitHub Actions",
"prod_hostname": "ssg-test.atasasmaz.com",
"email": "[email protected]",
"full_title": "Ata's SSG - a Simple PHP-based SSG for GitHub Pages",
"appended_title": " - Ata's SSG",
Expand Down
27 changes: 24 additions & 3 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,40 @@ function get_all_posts(): array
exit;
}

/**
* Are we running like a PHP site or if the build pipeline running this?
* @return bool
*/
function isBuildRunning(): bool
{
return file_exists(__DIR__ . "/../build.lock");
}

/**
* Gets the current full hostname with protocol
* @return string
*/
function getCurrentHostname(): string
{
global $config;

// Check if HTTPS or HTTP is being used
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? "https" : "http";

$host = isBuildRunning() ? $config->prod_hostname : $_SERVER['HTTP_HOST'];
// Get the server port
$port = $_SERVER['SERVER_PORT'];

// Depending on whether the port is standard for the protocol, include it in the URL
if (($protocol === 'http' && $port == 80) || ($protocol === 'https' && $port == 443)) {
// Standard ports for HTTP and HTTPS, respectively. No need to include the port in the URL.
$currentUrl = "{$_SERVER['HTTP_HOST']}";
$currentHost = "{$host}";
} else {
// Non-standard port, include it in the URL.
$currentUrl = "{$_SERVER['HTTP_HOST']}:{$port}";
$currentHost = "{$host}:{$port}";
}

return $currentUrl;
return $currentHost;
}

/**
Expand All @@ -103,3 +115,12 @@ function getCurrentHostnameWithProtocol(): string

return "{$protocol}://" . getCurrentHostname();
}

/**
* Gets the current full URL
* @return string
*/
function getCurrentFullUrl(): string
{
return getCurrentHostnameWithProtocol() . $_SERVER['REQUEST_URI'];
}
22 changes: 0 additions & 22 deletions system/layoutUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,4 @@ function selectedTabCss(string $tab): string
return "";
}

/**
* Are we running like a PHP site or if the build pipeline running this?
* @return bool
*/
function isBuildRunning(): bool
{
return file_exists(__DIR__ . "/../build.lock");
}

/**
* Gets the current full URL
* @return string
*/
function getCurrentFullUrl(): string
{
// Check if HTTPS or HTTP is being used
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? "https" : "http";

// Construct the full URL
$currentUrl = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

return $currentUrl;
}

0 comments on commit a8ecfd7

Please sign in to comment.