picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

Sub pages extention #178

Closed djangsta closed 9 years ago

djangsta commented 9 years ago

How do I create a page with the .html extension? For example: http://picocms.org/docs.html

phanos commented 9 years ago

you could create a file content/docs.html.md

bricebou commented 9 years ago

What is your goal ? Because, maybe you are going to exclude this page from the variables Pico defines (as the pages array).

Wouldn't it be better to use the template meta inside a simple md files:

Title: Your Title
Template : docs

With no content of course ; then in your active theme root you crete a docs.html files with what you want.

CodeAlDente commented 8 years ago

It's just common to use extensions for pages. I'd like to have all pages named foobar.html instead of having a directory structure. Also, it would be nice not to go way too deep with the structure, but to use dashes or underscores.

So instead of /foo/bar/sub/page it should be /foo-bar-sub-page.html or /foo_bar_sub_page.html. For ethically reasons and for Google (= http://www.thesempost.com/the-importance-of-url-structure-according-to-google/).

PhrozenByte commented 8 years ago

I don't agree, the article consists of wrong assumptions (the file structure has nothing to do with how "far away" contents are from root - it's a matter of how many links Google must follow to reach this page), obviously false pretences (did you ever see a file extension on Google?) and a completely contradictory conclusion that is radically opposed to this quote:

Illyes stressed again that there are no ranking benefits dependent on how you create your URL structure.

Anyway, you can still write a simple plugin to let Pico understand URLs like /foo-bar-sub-page.html (= content file /foo/bar/sub/page.md):

<?php

class FlatUrls extends AbstractPicoPlugin
{
    public function onRequestUrl(&$url)
    {
        if (substr($url, -5) === '.html') {
            $url = substr($url, 0, -5);
            $url = str_replace('-', '/', $url);
        }
    }
}

You can then use a Twig macro like the following to create URLs in your theme:

{% macro flat_url(base_url, page_id) %}
    {{ base_url }}/{{ page_id|replace({ "/": "-" }) }}.html
{% endmacro %}

{% import _self as util %}
{% for page in pages %}
    <a href="{{ util.flat_url(base_url, page.id) }}">{{ page.title }}</a>
{% endfor %}

I didn't test these code snippets, but they should do what you want (at least basically). It's very likely that plugins which depend on Pico's URL structure don't work with this. Pico neither recommends nor supports something like this.