<div>
    {% if not action %}
        {% if page is not none %}
            {% if page > 1 %}
                <a href="{{ url_for('topic', path=topic.path, p=page-1) }}">Previous</a>
                {% if page < topic.page_count %}/{% endif %}
            {% endif %}
            {% if page < topic.page_count %}<a href="{{ url_for('topic', path=topic.path, p=page+1) }}">Next</a>{% endif %}
            {% if topic.page_count > 1 %}
                -
                <a href="{{ url_for('topic', path=topic.path, p=topic.page_count) }}">Last Page</a> ({{ topic.page_count }})
            {% endif %}
        {% endif %}
    {% else %}
        {% if page is not none %}
            {% if page > 1 %}
                <a href="{{ url_for('topic', path=topic.path, p=page-1, a=action) }}">Previous</a>
                {% if page < topic.page_count %}/{% endif %}
            {% endif %}
            {% if page < topic.page_count %}
                <a href="{{ url_for('topic', path=topic.path, p=page+1, a=action) }}">Next</a>
            {% endif %}
            {% if topic.page_count > 1 %}
                -
                <a href="{{ url_for('topic', path=topic.path, p=topic.page_count, a=action) }}">Last Page</a> ({{ topic.page_count }})
            {% endif %}
        {% endif %}
    {% endif %}
</div>
