diff --git a/mkht.php b/mkht.php index d79fcdf..662b754 100755 --- a/mkht.php +++ b/mkht.php @@ -24,12 +24,13 @@ foreach ($argv as $arg) { } $opt['force'] ??= false; -define('SITE', $args[1] ?? getcwd()); +$site = $args[1] ?? getcwd(); +define('SITE', str_ends_with($site, '/') ? $site : $site . '/'); define('DESTINATION', $args[2] ?? 'dns'); -if (file_exists(SITE . '/config.ini')) - $config = parse_ini_file(SITE . '/config.ini'); +if (file_exists(SITE . 'config.ini')) + $config = parse_ini_file(SITE . 'config.ini'); $config['header'] ??= false; $config['author'] ??= NULL; @@ -41,7 +42,7 @@ $config['announce-feed'] ??= false; if (!isset($config['id'])) { $config['id'] = bin2hex(random_bytes(32)); - file_put_contents(SITE . '/config.ini', 'id = "' . $config['id'] . '"' . LF, FILE_APPEND); + file_put_contents(SITE . 'config.ini', 'id = "' . $config['id'] . '"' . LF, FILE_APPEND); } // Determine whether links need to use Onion or DNS @@ -57,9 +58,10 @@ $nodes = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(SITE, Recu foreach($nodes as $node) { $node_info = new SplFileInfo($node->getPathName()); $src = $node_info->getPathname(); - if (str_starts_with($src, SITE . '/target')) + if (str_starts_with($src, SITE . 'target/')) continue; - $target = str_replace(SITE, SITE . '/target', $src); + $target = str_replace(SITE, SITE . 'target/', $src); + $path_parts_src = pathinfo($src); $path_parts_target = pathinfo($target); if (strstr($src, '/.') !== false AND !str_ends_with($src, '/.htaccess')) // Skip hidden nodes (except for .htaccess) @@ -90,7 +92,7 @@ foreach($nodes as $node) { foreach ($pages as $node) { $node_info = new SplFileInfo($node->getPathName()); $src = $node_info->getPathname(); - $target = str_replace(SITE, SITE . '/target', $src); + $target = str_replace(SITE, SITE . 'target/', $src); $path_parts_src = pathinfo($src); $path_parts_target = pathinfo($target); @@ -141,7 +143,7 @@ foreach ($pages as $node) { // .md > .html for local links $content = preg_replace('/ href="([^:"]+)\.md"/', ' href="$1.html"', $content); - $relative_root_path = str_repeat('../', substr_count(str_replace(SITE . '/target', '', $path_parts_target['dirname']), '/')); + $relative_root_path = str_repeat('../', substr_count(str_replace(SITE . 'target', '', $path_parts_target['dirname']), '/')); ob_start(); @@ -170,13 +172,13 @@ foreach ($pages as $node) { echo ' ' . LF; if ($config['announce-css']) { - if (file_exists(SITE . '/style.css')) + if (file_exists(SITE . 'style.css')) echo ' ' . LF; echo ' ' . LF; } - if (file_exists(SITE . '/head.inc.html')) - echo file_get_contents(SITE . '/head.inc.html'); + if (file_exists(SITE . 'head.inc.html')) + echo file_get_contents(SITE . 'head.inc.html'); ?> @@ -209,15 +211,15 @@ foreach ($pages as $node) { ' . file_get_contents(SITE . '/header.inc.php')); + if (file_exists(SITE . 'header.inc.php')) + eval('?>' . file_get_contents(SITE . 'header.inc.php')); if ($config['center-index'] AND $path_parts_target['filename'] === 'index') echo '