I’m almost done completing my migration of WordPress server-side SQL views blogs to Hugo, and the last remaining step is migrating those membership-based ones. The architecture I have in mind is this:
- private_html/
404.html
- non-members/ → Hugo-rendered website
- members/ → Hugo-rendered website
- public_html/
.htaccess
index.php
login.php
subscribe.php
account.php
.htaccess
would handle URL rewriting to index.php
:
RewriteEngine On
RewriteBase /
# Redirect all traffic to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]
index.php
would do the triage:
// Get the full URL before redirection by .htaccess
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
// Separate domain from path
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
$PUBLIC = '../public_html/non-members';
$PRIVATE = '../public_html/members';
$is_logged_in = is_valid($_COOKIE["token"]);
// Redirect the path to the static website pages
switch($path) {
// PHP endpoints
case "/login.php":
case "/account.php":
case "/subscribe.php":
require_once($path);
break;
// Regular pages
default:
$member_target = $PRIVATE . $path . 'index.html';
$nomember_target = $PUBLIC . $path . 'index.html';
if($is_logged_in && file_exists($member_target))
require_once($member_target);
else if(file_exists($nomember_target))
require_once($nomember_target);
else
require_once('../public_html/404.html');
break;
}
Now, given that Hugo doesn’t seem to have ways of producing content alternatives, I’m thinking of using a shortcode that would output the full page content if some compilation flag is set, otherwise a truncated content or notification message. Then, private_html/members
and private_html/non-members
would each have the full website, one compiled with full content, the other with the truncated content.
Question is: how can I map a shortcode output to a custom building flag ?
Or is it a better way ?