Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
Initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangs-code committed Mar 23, 2021
1 parent 6fc190e commit 5d34034
Show file tree
Hide file tree
Showing 12 changed files with 2,518 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# No custom pages
pages/*
!pages/index.md
108 changes: 108 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
require './lib/Parsedown.php';
require './lib/ParsedownExtra.php';
$Parsedown = new Parsedown();
$Extra = new ParsedownExtra();

# Defines the settings declared in meta.json
define("USERSET", json_decode(file_get_contents("./meta.json"), true));

# If no page is specified, show index.md
$page = isset($_GET["page"]) ? $_GET["page"] : "index";

function getURL($page)
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$url = "https://";
} else {
$url = "http://";
}
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url .= "?page=" . $page;
return $url;
}

# Load all plugins and defines them into an array
foreach (glob("./plugins/*.php") as $plugin) {
include $plugin;
$pluginClasses[] = basename($plugin, ".php");
}
define("AC_PLUGINS", $pluginClasses);

$apath = getcwd() . "/pages/" . $page . ".md";

# Gets content inside tags to get metadata directly from Markdown
function insideTag($string, $tagname)
{
$pattern = "#<\s*?$tagname\b[^>]*>(.*?)</$tagname\b[^>]*>#s";
preg_match($pattern, $string, $matches);
return $matches[1];
}

# Only compose page if the Markdown file exists
if (file_exists($apath)) {
$md = file_get_contents($apath);
$html = $Extra->setBreaksEnabled(true)->text($md);
# TODO: Make firing plugin functions cleaner
foreach (AC_PLUGINS as $class) {
$plugin = new $class;
if (method_exists($plugin, "changeText")) {
$html = $plugin->changeText($html);
}
}
# Uses regex to find the first image in the page,
# And uses that as the Open Graph thumbnail
if (preg_match('/!\[.*\]\((.*)\)/i', $md, $match)) {
define('metaImg', true);
$image = $match[1];
}
# Get the modified date directly from the markdown file,
# Then get the title and description for the HTML from it as well.
$date = date("Y-m-d", filemtime($apath));
$title = insideTag($html, "h1");
$description = insideTag($html, "h2");
} else {
# If there is no Markdown file for the request,
# Return a 404 Error
http_response_code(404);
echo $page . " Not Found";
include USERSET["errorPath"]["404"];
exit;
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:type" content="website">
<meta property="og:url" content="<?=getURL($page)?>">
<title><?=$title . " - " . USERSET["siteName"]?></title>
<meta property="og:site_name" content="<?=USERSET["siteName"]?>" />
<meta name="theme-color" content="<?=USERSET["themeColor"]?>">
<meta name="author" content="<?=USERSET["author"]?>">
<meta property="og:title" content="<?=$title?>" />
<meta name="description" content="<?=$description?>">
<meta property="og:description" content="<?=$description?>" />
<meta name="twitter:card" content="summary_large_image" />
<?php if (defined('metaImg')) {echo "<meta property=\"og:image\" content=\"" . $image . "\">";}?>
<meta property="article:author" content="<?=USERSET["author"]?>" />
<meta property="article:published_time" content="<?=$date?>">
<?php foreach (USERSET["styles"] as $style) {print("<link rel=\"stylesheet\" href=\"./resource/css/" . $style . "\">\n\t");}?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
# TODO: Make firing plugin functions cleaner
foreach (AC_PLUGINS as $class) {
$plugin = new $class;
if (method_exists($plugin, "addHead")) {
$html = $plugin->addHead($html);
}
}
?>
</head>
<body>
<h3 class="banner right"><?=USERSET["siteName"]?></h3>
<p class="info"><span class="date">Last Updated: <?php echo $date . "</span>"; ?></p>
<?=$html?>
<h4 class="banner left">&copy; <?=date("Y") . " " . USERSET["copyright"]?></h4>
</body>
</html>
Loading

0 comments on commit 5d34034

Please sign in to comment.