Blog...

Add my RSS feed!


Back


A Simple Blog

22 September 2024

An uninteresting post about how this thing works


I gave up on trying to maintain a blog while still hosting this site on Neocities, since maintaining a blog in pure HTML/CSS is a massive pain in the ass. Now, since I'm hosting this on my personal server there are pretty much no limitations, so I've rewritten this site in PHP. My "blogging engine" solution is very rudimentary but it definitely gets the job done miles better than the old way.


I can't be fucked to set up a full content management system or a SQL database for this so I'm just putting all of my posts in a JSON file structured like this:


[

 {

  "title": "Example Blog Entry",

  "entry": 1,

  "subheading": "This is a blog post",

  "date": "22 September 2024",

  "categories": ["Personal" "Technology"],

  "content": [

   "<p>This is a paragraph.</p>",

   "<p>This is another paragraph.</p>"

  ]

 }

]


It's obviously not an optimal solution since I have to SSH into my server and edit a JSON file to make a blog post but it's more than doable. Maybe in the future I'll consider making some kind of UI for it but I'm fairly content with it as-is.


I've also written an RSS feed generator that looks like this:


<?php

require 'dynamic/variables.php';


$jsonStr = file_get_contents('json/blog.json');

$json = json_decode($jsonStr, true);


header("Content-Type: application/rss+xml; charset=UTF-8");

echo "<?xml version='1.0' encoding='UTF-8'?>";

echo "<rss version='2.0'>";

echo "<channel>";

echo "<title>yazoink</title>";

echo "<link>https://$domain</link>";

echo "<description>yazoink's blog</description>";

foreach ($json as $blogEntry) {

 echo "<item>";

 echo "<title>" . $blogEntry['title'] . "</title>";

 echo "<link>https://$domain/index.php?nav=Blog&entry=" . logEntry['entry'] . "</link>";

 echo "<description>" . $blogEntry['subheading'] . "</description>";

 echo "<pubDate>" . date(DATE_RSS, strtotime($blogEntry['date'])) . "</pubDate>";

 echo "</item>";

}

echo "</channel>";

echo "</rss>";

?>


Categories: Technology PHP Self-hosting JSON Programming