Welcome Demo
This is a self styled project to create a blog that doesn't rely on Database systems. This project is a blog with dynamic generated pages populated by using markdown text files. The projects will be based around a MVC design model with a single access point using REST api calls to get different features and information. One of the main insperation to this project is codeigniter framework and dokuwiki. I liked the text files dokuwiki uses to store and view page data. Codeigniters MVC and Uri request help create simple api's.
This is going to be a dev log in the development of some of the stuff we throw at the wall.
New features and options will be coming in the future posts.
Going to start with the first few files and the starting file structure.
require_once('app/config.php');
defined("SELF") or define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
defined("ROOT_PATH") or define('ROOT_PATH', realpath(dirname(__FILE__)).'/');
defined("SYS_PATH") or define('SYS_PATH', ROOT_PATH.$system_folder);
include(SYS_PATH."/autoload.php");
$router = new Route();
$app = new App();
The index page will be the landing location that will load the config settings and the autoload a registered auto loader that will allow us to call classes without having to preload classes used in the framework.
--NOTE: autoloader maybe removed if size of the project remains small. Backwards thought.
Then the Route and the App classes will load to start building the framework object.
The Route class handles the routing of HTTP requests to the appropriate controller and method based on the URL. It parses the URL, loads the corresponding controller, and invokes the appropriate method if it exists.
The App class provides a centralized mechanism for managing settings, objects, models, and views within an application. It also supports URL parsing and template rendering, and enforces the Singleton pattern to ensure a single instance. This class is crucial for handling App functionalities and maintaining consistency across the application.
This is the default controller that will load the welcome message we extend the controller with the App class to use the app functionalities.
class start extend app{
public function __construct(){
$this->view('welcome');
}
}
it will load the welcome view from the view folder.
Will be a simple welcome message to test the site loads. This is where html and the data will be desplied.
echo '<p>Welcome to the Site</p>';
No we can create our own controllers, using the start controller as the default structure. we will start by creating a site controller and have our first function be index and have the construct function emptry.
When we call /site/index we will be loading the site controller and the index method. we can create static pages by loading views with the veiw method in our app class. first parmater is calling the name of the view
$this->view('page');
the view function has a second parmater to pass data to the view.
$this->view('page',$this->data);
This is a key factor when we want to load our markdown files in the view.
The MarkdownArticleReader class is designed to read markdown files, extract any JSON data from a specific format within the markdown file, convert the remaining markdown content to HTML, and return the combined result.
The json contains the meta data for each markdown file so that the content can be crawlable for search engines.
$this->articleReader = new MarkdownArticleReader('/path/to/markdown/files');
$this->data = $this->articleReader->displayArticle('example.md');
$this->view('page',$this->data);
<title><?= $site['title']; ?></title>
<meta name="keywords" content="<?= $site['keywords']; ?>">
<meta name="description" content="<?= $site['description']; ?>">
<p><?= $markdownContent; ?><p>
This part of the project will be looing at 2 forms of modeling that will be used in the site. one using php files as a class object, and one using JSON files.
-- NOTE: This part may be change how the model object will be passted.
Model are designed like controller design
Below are 2 examples of model code
class pages{
public function default(){
$data['title'] = "";
$data['description'] = "";
$data['keywords'] = "";
return $data;
}
}
public function log(){
$this->linkGenerator = new DirectoryLinkGenerator('path/to/markdown/files');
$this->view('page');
}
public function resources(){
$this->linkListHtml = new LinkGenerator('path/to/json/model');
$this->view('resources');
}
public function pages_model(){
$this->model('pages');
$this->data['site'] = $this->model->default();
$this->view('page',$this->data);
}
<?php if(isset($this->linkGenerator)): ?>
<?php $this->linkGenerator->generateLinks(); ?>
<?php endif; ?>
The DirectoryLinkGenerator
class generates HTML links for files and directories within a specified directory. It recursively traverses the directory structure and creates nested lists of links.
Root directory has to be avabliable when loading. Consider placing in the config file.
<?php if(isset($this->linkListHtml)): ?>
<p><?= $this->linkListHtml->generateLinkList(); ?></p>
<?php endif; ?>
The LinkGenerator
class is designed to generate HTML lists of links from a JSON file containing link data. It organizes links by category and formats them into HTML for display.
<?php if(isset($site)): ?>
<?php foreach($site as $key => $val): ?>
<p><?= $key .' - '. $val; ?></p>
<?php endforeach; ?>
<?php endif; ?>
# /site/index/
class site extends app{
public function index(){
$this->model('pages'); // model/pages.model.php
$data['site'] = $this->model->index(); // calls index method
$this->view('header', $data); // view/header.php
$this->view('menu'); // view/menu.php
$this->view('page', $data); // view/page.php
$this->view('footer'); // view/footer.php
}
}
To read a artical, the name is passed into a method named after the folder.
class log extends app{
public function tips($file = null){
}
}
Site controller will have the main links for the site, log controller will controller site log files