marcoarment / secondcrack

A static-file Markdown blogging engine.

Home Page:http://www.marco.org/secondcrack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pagination

jeremygibbs opened this issue · comments

Problem

While testing the new pagination, I discovered that, for pages index-2 and beyond, the "previous_page_url" and "next_page_url" values in $content were wrong. The actual index pages were fine, just not the array values for their link. I believe that I tracked down the culprit:

In engine/Post.php the function write_index_sequence sets a destination uri for the paginated index files:

    $dest_uri = substring_after(substring_before($dest_path, '.', true), Updater::$dest_path);

The problem is that when write_index_sequence is called in engine/Updater.php, it is passed a destination url like so:

    Post::write_index_sequence(  self::$dest_path . "/index", ....

Given a destination url in this form (/some/path/index), the $dest_uri construction fails because there is no '.' in the name.

The Fix

I changed that construction in engine/Post.php to the following and it seems to be working:

    $dest_uri = substring_after(substring_after($dest_path, '/', true), Updater::$dest_path);

Usage

Then to get the pagination working on the front page, simply set public static $frontpage_paginate = true; in engine/Updater.php. Then add the following to your main.php template file:

    <div id="prev_next">
        <span id='newer_posts'>
            <? if ( isset($content['previous_page_url']) && !empty($content['previous_page_url'])) echo "<a href='".$content['previous_page_url'] ."'>Newer Posts &gt;&gt;</a>"; ?>
        </span>
        <span id='older_posts'>
            <? if (isset($content['next_page_url']) && $content['next_page_url'] != end($content['next_page_url'])) echo "<a href='".$content['next_page_url'] ."'>&lt;&lt; Older Posts</a>"; ?>
        </span>
    </div>

I'm sorry not to do a pull request, but I made a mess of my local repo and I am new enough to git that I was afraid of messing things up. Plus, it was only one line.

Thanks. Fixed.