Browse Source

Add config.ini

master
Miraty 8 months ago
parent
commit
7dd07f5f86
  1. 14
      antopie/config.ini
  2. 67
      compil.php
  3. 18
      inc/debut.php
  4. 18
      inc/url.php
  5. 6
      style.less

14
antopie/config.ini

@ -0,0 +1,14 @@
; Used in <title> and <header>
siteTitle = "Antopie"
; Whether to use dark and white or black and white
trueBlack = false
; Whether to advertise of the CSS files in the HTML document or not
css = true
; Whether to add a <header> tag to the HTML document or not
header = true
; Whether to center text on indexes or not
centerIndex = true

67
compil.php

@ -3,6 +3,8 @@
if (php_sapi_name() !== "cli")
exit("Must be run from CLI");
// Initialization
define("FIND", "/usr/bin/find");
define("GZIP", "/usr/bin/gzip");
@ -13,17 +15,43 @@ if (isset($argv[2]))
else
define("DESTINATION", "local");
if (isset($argv[3]))
define("SITE_TITLE", $argv[3]);
else
define("SITE_TITLE", SITE);
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;
if (!isset($config['header']))
$config['header'] = true;
if (!isset($config['centerIndex']))
$config['centerIndex'] = false;
require ROOT . "/bibli/parsedown/Parsedown.php";
require ROOT . "/bibli/parsedown-extra/ParsedownExtra.php";
// Less > CSS
require ROOT . "/bibli/less.php/lib/Less/Autoloader.php";
Less_Autoloader::register();
$colorScheme = array(
"darkColor" => "#2a2a2a",
"darkerColor" => "#222222",
"lightColor" => "white",
"lightlessColor" => "#eeeeee",
"mainColor" => "red",
);
if ($config['trueBlack']) {
$colorScheme['darkColor'] = "#000000";
$colorScheme['darkerColor'] = "#000000";
}
$options = array('cache_dir' => SITE . '/css', 'compress' => true);
if (file_exists(SITE . "/style.less"))
@ -31,11 +59,27 @@ if (file_exists(SITE . "/style.less"))
else
$lessFiles = array(ROOT . '/style.less' => '');
define("CSS_FILENAME", Less_Cache::Get($lessFiles, $options));
define("CSS_FILENAME", Less_Cache::Get($lessFiles, $options, $colorScheme));
exec(FIND . " " . SITE . " -name '*.gmi' -o -name '*.md'", $pages);
require "inc/url.php";
// URLs don't end with .html on the Antopie website
function formerUrlLocale($page) {
if (DESTINATION === "dns" OR DESTINATION === "onion") {
echo $page;
} else {
echo $page . ".html";
}
}
// Determine whether links need to use Onion or DNS
function clearnetOrOnion($clearnetUrl, $onionUrl) {
if (DESTINATION === "onion") {
return $onionUrl;
} else {
return $clearnetUrl;
}
}
foreach ($pages as $page) {
@ -90,6 +134,8 @@ foreach ($pages as $page) {
// Compile Markdown to HTML with Parsedown
require_once ROOT . "/bibli/parsedown/Parsedown.php";
require_once ROOT . "/bibli/parsedown-extra/ParsedownExtra.php";
$Parsedown = new ParsedownExtra;
$Parsedown = $Parsedown->setUrlsLinked(false);
$Parsedown = $Parsedown->setMarkupEscaped(false);
@ -106,13 +152,13 @@ foreach ($pages as $page) {
ob_start();
require "inc/debut.php";
if ($pathParts['filename'] === "index") {
if ($config['centerIndex'] AND $pathParts['filename'] === "index") {
echo "<div class='centre'>";
} else {
echo "<article>";
}
echo $pageContent;
if ($pathParts['filename'] === "index") {
if ($config['centerIndex'] AND $pathParts['filename'] === "index") {
echo "</div>";
} else {
echo "</article>";
@ -121,7 +167,6 @@ foreach ($pages as $page) {
file_put_contents($pathParts['dirname'] . "/" . $pathParts['filename'] . ".html", ob_get_contents());
ob_end_clean();
// Gzip compression
exec(GZIP . " --keep --fast --force " . $pathParts['dirname'] . "/" . $pathParts['filename'] . ".html");
}

18
inc/debut.php

@ -4,14 +4,16 @@
<meta charset="UTF-8">
<title><?php
if (isset($title) AND !is_null($title))
echo $title . " · " . SITE_TITLE;
echo $title . " · " . $config['siteTitle'];
else
echo SITE_TITLE;
echo $config['siteTitle'];
?></title>
<meta name="distribution" content="global">
<meta name="robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" rel="stylesheet" href="/css/<?= CSS_FILENAME ?>">
<?php if ($config['css']) { ?>
<link type="text/css" rel="stylesheet" href="/css/<?= CSS_FILENAME ?>">
<?php } ?>
<?php
if (file_exists(SITE . "/head.inc.html"))
echo file_get_contents(SITE . "/head.inc.html");
@ -19,17 +21,23 @@
</head>
<body>
<?php
if ($config['header']) {
?>
<header>
<a id="lienHeader" href="/">
<div class="logo">
<?php
if (file_exists(SITE . "/img/logo.webp"))
echo '<img src="img/logo.webp" ' . getimagesize(SITE . "/img/logo.webp")[3] . ' alt="' . SITE_TITLE . '" />';
echo '<img src="img/logo.webp" ' . getimagesize(SITE . "/img/logo.webp")[3] . ' alt="' . $config['siteTitle'] . '" />';
else
echo SITE_TITLE;
echo $config['siteTitle'];
?>
</div>
</a>
</header>
<?php
}
?>
<main>

18
inc/url.php

@ -1,18 +0,0 @@
<?php
// Les URL n'ont pas le .php sur le site d'Antopie
function formerUrlLocale($page) {
if (DESTINATION === "dns" OR DESTINATION === "onion") {
echo $page;
} else {
echo $page . ".html";
}
}
// Détermine si il faut utiliser les liens en .onion ou pas
function clearnetOrOnion($clearnetUrl, $onionUrl) {
if (DESTINATION === "onion") {
return $onionUrl;
} else {
return $clearnetUrl;
}
}

6
style.less

@ -1,12 +1,6 @@
@light: ~"(prefers-color-scheme: light)";
@dark: ~"(prefers-color-scheme: dark)";
@darkColor: #2a2a2a;
@darkerColor: #222222;
@lightColor: white;
@lightlessColor: #eeeeee;
@mainColor: red;
::selection {
@media @light {
color: @lightColor;