PAGENODE

About Documentation Github

Getting Started

This guide will show you how to use the Pagenode library and how to get something on the screen quickly.

  1. Download the latest pagenode.php
  2. Create a directory called nodes/ next to it
  3. Create nodes/hello.md with some Markdown content
  4. Create an index.php with the following content:
<?php
require_once('pagenode.php');

route('/', function() {
    $node = select('nodes/')->one(['keyword' => 'hello']);
    include('templates/node.html.php');
});

dispatch();

This will set up a handler for the route "/", which will look for a file called hello.md in the nodes/ directory.

In Pagenode, a keyword is the file name minus the .md extension. By definition, a keyword is unique – you can't have two files with the same name.

After the node has been loaded, the route handler will include our template templates/node.html.php, so let's create it:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?= $node->title ?? 'Pagenode' ?></title>
</head>
<body>

    <?= $node->body ?>

    <p class="foot">
        Created at <?= $node->date->format('Y.m.d') ?>
    </p>
</body>
</html>

You can now start PHPs built-in Web Server to have a quick look at your page. Issue the following command in the directory where your index.php is located:

php -S localhost:8080

You should now be able to load localhost:8080 in your browser and read your hello.md file.

Setup for Apache and Nginx

In order to make the URL routing work with clean URLs, you have to let your index.php handle all requests.

For Apache, you can place Pagenode's .htacces file in the directory where your index.php is located.

For Nginx you can use the following configuration for your host:

server {
    server_name yourdomain.com;
    root /var/www/yourdomain;

    location ~ /\.git {
        deny all;
    }

    include php-fastcgi.conf;

    # Let Pagenode handle all requests
    try_files $uri $uri/ /index.php?$query_string;
}

If you don't want to setup clean URLs, you can also route requests via a GET parameter.

E.g. for URLs like example.com/?path=blog/some-keyword you can change the dispatch() call to use the path GET parameter:

dispatch($_GET['path']);

Or, a bit cleaner, for URLs like example.com/?blog/some-keyword use the first $_GET key:

dispatch(key($_GET));

Up Next: Adding Content »

© 2024 Dominic Szablewski – rendered in (2.74ms)