aboutsummaryrefslogtreecommitdiff
path: root/_site/includes/articles
diff options
context:
space:
mode:
authorMinteck <46352972+Minteck@users.noreply.github.com>2021-06-29 20:00:07 +0200
committerMinteck <46352972+Minteck@users.noreply.github.com>2021-06-29 20:00:07 +0200
commitd2733aa17b7932dfb78e97639e7d568ac41b9ee1 (patch)
tree1e77dbe51e192c42f993e79e53532d3558d36bcb /_site/includes/articles
parent9f3bd84cb82a7f57a49701018a7fb43eb77c65aa (diff)
downloadunchainedtech-d2733aa17b7932dfb78e97639e7d568ac41b9ee1.tar.gz
unchainedtech-d2733aa17b7932dfb78e97639e7d568ac41b9ee1.tar.bz2
unchainedtech-d2733aa17b7932dfb78e97639e7d568ac41b9ee1.zip
Let's finally commit stuff!
Diffstat (limited to '_site/includes/articles')
-rw-r--r--_site/includes/articles/getlist.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/_site/includes/articles/getlist.php b/_site/includes/articles/getlist.php
new file mode 100644
index 0000000..5f55574
--- /dev/null
+++ b/_site/includes/articles/getlist.php
@@ -0,0 +1,86 @@
+<?php
+
+function getArticlesList() {
+ global $Parsedown;
+
+ $list = [];
+ $files = scandir($_SERVER['DOCUMENT_ROOT'] . "/../_posts");
+
+ foreach ($files as $file) {
+ if (is_file($_SERVER['DOCUMENT_ROOT'] . "/../_posts/" . $file)) {
+ $content = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/../_posts/" . $file);
+ $lines = explode("\n", $content);
+ $unlined = [];
+
+ $id = substr($file, 0, -3);
+ $list[$id] = [
+ "date" => date("Y-m-d"),
+ "title" => $id,
+ "author" => "Blogchain",
+ "cover" => null,
+ "extract" => ""
+ ];
+
+ $propertiesMode = false;
+ $propertiesDone = false;
+ $cline = 0;
+ $upline = 0;
+ foreach ($lines as $line) {
+ if (!$propertiesDone) {
+ if (trim($line) === "---") {
+ if ($propertiesMode) {
+ $propertiesDone = true;
+ $propertiesMode = false;
+ $upline = $cline + 1;
+ } else {
+ $propertiesMode = true;
+ }
+ } else if ($propertiesMode) {
+ $parts = explode(":", $line);
+ $p_ins = trim($parts[0]);
+ array_shift($parts);
+ $p_data = trim(implode(":", $parts));
+
+ switch ($p_ins) {
+ case "date":
+ $pp_dt = DateTime::createFromFormat('Y-m-d', $p_data);
+ $list[$id]["date"] = $pp_dt->format("Ymd");
+ break;
+
+ case "title":
+ $list[$id]["title"] = $p_data;
+ break;
+
+ case "author":
+ $list[$id]["author"] = explode("|", $p_data);
+ break;
+
+ case "cover":
+ $list[$id]["cover"] = $p_data;
+ break;
+ }
+ }
+ }
+ $cline++;
+ }
+
+ $i = 0;
+ while ($i++ < $upline) {
+ array_shift($lines);
+ }
+
+ $text = implode("\n", $lines);
+
+ $list[$id]["content"] = [];
+ $list[$id]["content"]["full"] = $Parsedown->text($text);
+ $list[$id]["content"]["clean"] = strip_tags($list[$id]["content"]["full"]);
+ if (strlen($list[$id]["content"]["clean"]) > 100) {
+ $list[$id]["content"]["mini"] = substr($list[$id]["content"]["clean"], 0, 100) . "…";
+ } else {
+ $list[$id]["content"]["mini"] = $list[$id]["content"]["clean"];
+ }
+ }
+ }
+
+ return $list;
+} \ No newline at end of file