getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.53k stars 1.41k forks source link

file loading for pages with prefix number was broken with latest update #457

Closed ichik closed 8 years ago

ichik commented 8 years ago

I use custom CSS loading for some pages like this:

{% if page.header.customcss %}
{% do assets.add('/user/pages' ~ page.url() ~ '/custom.css',10,false) %}
{% endif %}

It worked previously for pages with numbers in folder name previously, but now it returns 404.

e.g.: http://sqncbrk.com/user/pages/metroidvanias/custom.css but http://sqncbrk.com/user/pages/02.metroidvanias/custom.css

What gives? Is there a way to request page slug with number?

ichik commented 8 years ago

I've created duplicating folder for now, so you won't get 404 I guess.

rhukster commented 8 years ago

Ah actually i think this is something I've just fixed. Try adding css to the list of fallback_types in your system.yaml. That should get you working until the next release.

ichik commented 8 years ago

Hm, nope, that didn't work.

ichik commented 8 years ago

For reference part of system.yaml:

pages:
  theme: GrvSqncBrk
  markdown_extra: true
  process:
    markdown: true
    twig: true
  redirect_default_route: true
  fallback_types: [css,png,jpg,gif]
rhukster commented 8 years ago

if you add that, then this url: http://sqncbrk.com/user/pages/metroidvanias/custom.css should work. Basically before any file that was in a page route, would fallback and be downloaded/streamed by Grav. This was considered a bit of a security risk, so i created a fallback_types list to 'whitelist' the types.

However, this only had images in by default and kinda broke other types such as .css, so... I changed it recently in the develop branch so any media type is considered a valid type to fallback to, and there is a new whitelist that will override that list if you want to restrict it even more.

In the meantime, adding css to your fallback types should definitely fix this. There was another issue reported (but for .pdf) and this did work.

rhukster commented 8 years ago

This was the issue, basically the same problem. https://github.com/getgrav/grav/issues/452

rhukster commented 8 years ago

BTW you might need to back out your folder fix.

rhukster commented 8 years ago

Actually i am seeing someing weird.. your url should be: http://sqncbrk.com/metroidvanias/custom.css

hold on...

ichik commented 8 years ago

That is because I've specifically asked for /user/pages:

{% do assets.add('/user/pages' ~ page.url() ~ '/custom.css',10,false) %}

simple page.url didn't work so I've resorted to this some time ago.

Anyway, maybe fallback_types is dependant on some other settings?

rhukster commented 8 years ago

No this should never of worked. /user/pages is basically going directly to the file, which is fine.. however, page.url is going to get the slug for the route, not the path.. these are not the same. Just trying to find a better solution. Stand by...

ichik commented 8 years ago

Checked if requesting http://sqncbrk.com/metroidvanias/custom.css works — it doesn't somehow. While say http://sqncbrk.com/bloodborne/custom.css works.

So it may have something to do with numeric prefix after all.

ichik commented 8 years ago

Requesting http://sqncbrk.com/02.metroidvanias/custom.css doesn't work either though.

rhukster commented 8 years ago

where is the actual css file your trying to reach??? what 'should' work?

rhukster commented 8 years ago

Ok this should work with numeric and non-numeric folders:

{% if page.header.customcss %}
  {% set path = base_url ~ '/' ~ page.filePathClean|replace({('/'~page.name): ''}) %}
  {% do assets.add(path ~ '/custom.css',10,false) %}
{% endif %}
rhukster commented 8 years ago

BTW i've added this to Page object to make it a little easier going forward:

    /**
     * Returns the clean path to the page file
     */
    public function relativePagePath()
    {
        $path = str_replace('/'.$this->name, '', $this->filePathClean());
        return $path;
    }

Basically does that replace bit automatically so after this is in Grav (next version) you can just do this:

{% if page.header.customcss %}
  {% do assets.add(base_url ~ '/' ~ page.relativePagePath ~ '/custom.css',10,false) %}
{% endif %}
ichik commented 8 years ago

Actual CSS was is 02.metroidvanias. Thanks for your help