<?php
require_once 'functions/init.php';
require_once 'functions/functions.php';

include_once 'components/head.php';

include_once 'functions/article_functions.php';

// TODO: Move to a grid, where the left hand column is either a search and filtering system, or...Table of Contents?

// Default view, it'll show articles by recency
if (!isset($_GET['article_id']) && !isset($_GET['tag']) && !isset($_GET['author_id'])) {
    $ids = article_ids_by_recency();

    foreach ($ids as $id)
        echo article_card($id);
} else if (isset($_GET['article_id'])) {
    increment_read_counter($_GET['article_id']);
    echo article_page_from_markdown($_GET['article_id']);
} else if (isset($_GET['author_id'])) {
    $ids = articles_ids_by_author($_GET['author_id']);

    foreach ($ids as $id)
        echo article_card($id);
} else if (isset($_GET['tag'])) {
    $ids = article_ids_by_tag($_GET['tag']);

    foreach ($ids as $id)
        echo article_card($id);
}

include_once 'components/foot.php';
