This commit is contained in:
Miraty 2022-01-03 19:22:55 +01:00
parent 450299e95a
commit 7a2272a263
2 changed files with 96 additions and 109 deletions

View file

@ -23,12 +23,6 @@ else
if (file_exists(SITE . "/config.ini"))
$config = parse_ini_file(SITE . "/config.ini");
if (!isset($config['trueBlack']))
$config['trueBlack'] = false;
if (!isset($config['siteTitle']))
$config['siteTitle'] = "Site";
if (!isset($config['css']))
$config['css'] = true;
@ -52,18 +46,11 @@ require ROOT . "/less.php/lib/Less/Autoloader.php";
Less_Autoloader::register();
$colorScheme = array(
"darkColor" => "#2a2a2a",
"darkerColor" => "#222222",
"darkColor" => "black",
"lightColor" => "white",
"lightlessColor" => "#eeeeee",
"mainColor" => "red",
);
if ($config['trueBlack']) {
$colorScheme['darkColor'] = "#000000";
$colorScheme['darkerColor'] = "#000000";
}
$options = array(
'cache_dir' => SITE . '/css',
'compress' => true,
@ -114,21 +101,11 @@ foreach ($pages as $page) {
if ($pathParts['extension'] === "gmi") {
$gmilines = explode("\n", file_get_contents($pathParts['dirname'] . "/" . $pathParts['basename']));
if (substr($gmilines[0], 0, 2) === "# ")
$title = substr($gmilines[0], 2);
else
$title = NULL;
foreach ($gmilines as $key => $line) {
if (substr($line, 0, 2) === "=>") {
preg_match("/=> +(.[^ ]+)/", $line, $lnUrl);
preg_match("/=> +.[^ ]+ +(.+)/", $line, $lnTitle);
// Escape Markdown special characters
$mdSpecial = array("[", "]", "(", ")");
$htmlEntities = array("[", "]", "(", ")");
$lnUrl[1] = str_replace($mdSpecial, $htmlEntities, $lnUrl[1]);
$urlPathParts = pathinfo(parse_url($lnUrl[1], PHP_URL_PATH));
// .gmi > .md for local links
@ -136,7 +113,6 @@ foreach ($pages as $page) {
$lnUrl[1] = $urlPathParts['dirname'] . "/" . $urlPathParts['filename'] . ".md";
if (isset($lnTitle[1])) {
$lnTitle[1] = str_replace($mdSpecial, $htmlEntities, $lnTitle[1]);
$gmilines[$key] = "[" . $lnTitle[1] . "](" . $lnUrl[1] . ")";
} else {
$gmilines[$key] = "[" . $lnUrl[1] . "](" . $lnUrl[1] . ")";
@ -152,13 +128,18 @@ foreach ($pages as $page) {
// Compile Markdown to HTML with Parsedown
$markdown = file_get_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md");
if (preg_match("/# (.*)\\n/", $markdown, $matches)) // If a main heading is found
$title = $matches[1]; // Then it will be the HTML page <title>
else
$title = NULL;
require_once ROOT . "/parsedown/Parsedown.php";
require_once ROOT . "/parsedown-extra/ParsedownExtra.php";
$Parsedown = new ParsedownExtra;
$Parsedown = $Parsedown->setUrlsLinked(false);
$Parsedown = $Parsedown->setMarkupEscaped(false);
$Parsedown = $Parsedown->setBreaksEnabled(true);
$pageContent = $Parsedown->text(file_get_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".md"));
$pageContent = $Parsedown->text($markdown);
// .md > .html for local links
@ -167,31 +148,38 @@ foreach ($pages as $page) {
// Add header and footer to HTML
$urlPath = str_replace(SITE, "", $pathParts['dirname']);
$relativePathToRoot = "";
for ($i = substr_count($urlPath, "/") ; $i > 0 ; $i--)
$relativePathToRoot .= "../";
ob_start();
?>
<!DOCTYPE html>
<html lang="<?php
preg_match("#\.([a-zA-Z-]{2,5})\.#", $pathParts['basename'], $lang);
preg_match("#\.([a-zA-Z-]{2,5})\.#", $pathParts['basename'], $lang);
if (isset($lang[1]))
echo $lang[1];
else
echo $config['defaultLang'];
if (isset($lang[1]))
echo $lang[1];
else
echo $config['defaultLang'];
?>">
<head>
<meta charset="UTF-8">
<title><?php
if (isset($title) AND !is_null($title))
echo $title . " · " . $config['siteTitle'];
else
echo $config['siteTitle'];
?></title>
<?php
if (isset($title) AND !is_null($title) AND isset($config['siteTitle']))
echo "<title>" . $title . " · " . $config['siteTitle'] . "</title>";
else if (isset($title) AND !is_null($title))
echo "<title>" . $title . "</title>";
else if (isset($config['siteTitle']))
echo "<title>" . $config['siteTitle'] . "</title>";
?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php if ($config['css']) { ?>
<link type="text/css" rel="stylesheet" media="screen" href="/css/<?= CSS_FILENAME ?>">
<link rel="stylesheet" media="screen" href="<?= $relativePathToRoot ?>css/<?= CSS_FILENAME ?>">
<?php } ?>
<?php
if (file_exists(SITE . "/head.inc.html"))
@ -204,7 +192,7 @@ else
if ($config['header']) {
?>
<header>
<a id="lienHeader" href="/">
<a id="lienHeader" href="./<?= $relativePathToRoot ?>">
<?php
if (file_exists(SITE . "/img/logo.webp"))
echo '<img src="img/logo.webp" ' . getimagesize(SITE . "/img/logo.webp")[3] . ' alt="' . $config['siteTitle'] . '" />';

View file

@ -1,30 +1,6 @@
@light: ~"(prefers-color-scheme: light)";
@dark: ~"(prefers-color-scheme: dark)";
@fontSize: 30px;
* {
padding: 0px;
margin: 0px;
font-family: system-ui, sans-serif;
font-size: @fontSize;
line-height: 42px;
&:hover, &:focus {
color: inherit;
}
@media @light {
background-color: @lightColor;
color: @darkColor;
scrollbar-color: @darkColor @lightColor;
}
@media @dark {
background-color: @darkColor;
color: @lightColor;
scrollbar-color: @lightColor @darkColor;
}
}
@smallWidthScreen: ~"(max-width: 420px)";
::selection {
@media @light {
@ -37,18 +13,42 @@
}
}
* {
padding: 0px;
margin: 0px;
@media @light {
scrollbar-color: @darkColor @lightColor;
}
@media @dark {
scrollbar-color: @lightColor @darkColor;
}
}
body {
font-family: system-ui, sans-serif;
font-size: 30px;
line-height: 42px;
margin: 20px;
@media @light {
background-color: @lightColor;
color: @darkColor;
}
@media @dark {
background-color: @darkColor;
color: @lightColor;
}
@media @smallWidthScreen {
font-size: 26px;
line-height: 38px;
}
}
main {
padding: 15px;
@media (max-width: 500px) {
padding-left: 10px;
padding-right: 10px;
}
margin-left: 20%;
margin-right: 20%;
@ -60,16 +60,28 @@ main {
@media (max-width: 800px) {
margin-left: 0px;
margin-right: 0px;
padding-left: 0px;
padding-right: 0px;
}
}
a, a:visited {
text-decoration: underline;
transition-property: color, border-color;
transition-duration: 0.1s;
transition-duration: 0.05s;
transition-timing-function: linear;
&:hover, &:focus {
@media @light {
background-color: @lightColor;
color: @darkColor;
}
@media @dark {
background-color: @darkColor;
color: @lightColor;
}
&:hover, &:focus {
text-decoration: none;
color: @mainColor;
}
@ -134,22 +146,12 @@ strong {
font-weight: bold;
}
pre, *:not(pre) > code, var, samp {
padding: 5px;
}
pre, code, var, samp {
font-family: monospace;
overflow: auto;
border-radius: 10px;
font-style: normal;
@media @dark {
background-color: @darkerColor;
}
@media @light {
background-color: @lightlessColor;
}
border-radius: 15px;
word-break: break-all;
}
abbr[title] {
@ -183,6 +185,11 @@ header, footer, .centered {
justify-content: center;
}
footer {
display: flex;
flex-direction: column;
}
// ----- TITLES -----
h1, h2, h3, h4, h5, h6 {
@ -190,41 +197,33 @@ h1, h2, h3, h4, h5, h6 {
line-height: 100%;
}
h1, h1 > * {
font-size: @fontSize + 40;
}
h1 {
font-size: 70px;
text-align: center;
padding-top: 15px;
}
margin-bottom: 20px;
h2, h2 > * {
font-size: @fontSize + 30;
@media @smallWidthScreen {
font-size: 45px;
}
}
h2 {
margin-top: 50px;
margin-bottom: 20px;
}
font-size: 60px;
margin-top: 30px;
margin-bottom: 15px;
h3, h3 > * {
font-size: @fontSize + 25;
@media @smallWidthScreen {
font-size: 40px;
}
}
h3 {
font-size: 42px;
margin-top: 30px;
margin-bottom: 10px;
}
margin-bottom: 15px;
h4, h4 > * {
font-size: @fontSize + 18;
}
h5, h5 > * {
font-size: @fontSize + 12;
}
h6, h6 > * {
font-size: @fontSize + 6;
@media @smallWidthScreen {
font-size: 35px;
}
}