PhileCMS / Phile

A flat file CMS with a swappable parser and template engine.
https://philecms.github.io/
Other
257 stars 49 forks source link

Markdown footnotes always link to base URL #70

Closed miniat-amos closed 10 years ago

miniat-amos commented 10 years ago

Given the following .md extra input...

"Put that pie back!" [^1]

[^1]: Pies are loved by many.

...nice forward and back links are generated, but clicking either takes you to the base URL of the Phile install.

james2doyle commented 10 years ago

I'm not sure what you mean. Can you post the HTML output?

miniat-amos commented 10 years ago

The pertinent HTML generated for the above example is...

<p>"Put that pie back!" <sup id="fnref:1"><a href="#fn:1" class="footnote-ref">1</a></sup></p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>Pies are loved by many.&#160;<a href="#fnref:1" rev="footnote" class="footnote-backref">&#8617;</a></p>
</li>

</ol>
</div>

This is just what I would expect. This issue, I imagine, is with the URL rewriting as clicking either the footnote or return-from-footnote reference links results in you ending up on your Phile homepage. In my case, the footnote Markdown is in the file content/footnote.md. When I click the superscript footnote link,the browser is redirected to http://www.server.com/#fn:1 instead of http://www.server.com/footnote#fn:1. So the homepage loads instead of going to the reference link.

I believe this issue is related to others I've seen in the closed issue list regarding regular reference links. In those discussions, however, the solutions were to hardcode the reference links in HTML directly in the Markdown. While that is doable for general reference links (although contrary to the choice of using Markdown in the first place), it is not when using the MarkdownExtra footnote feature... at least as far as I can tell.

james2doyle commented 10 years ago

Yeah I see what you mean now.

With full URLs it is easy. But I'm not really sure how to fix this. I would say javascript could help, but that is a hack answer.

ItsEricWoodward commented 10 years ago

Not sure if this will work for everyone, but I got it to work by putting a base tag referring to the current page inside my template's <head>.

<base href="{{ current_page.url }}" />
james2doyle commented 10 years ago

The will work for the footnotes, but you would have to make sure that you are using absolute URLs on things like the navigation.

ItsEricWoodward commented 10 years ago

You're right, of course. I don't know if that would be a game breaker for most or not, but it beats trying to hard code footnotes.

Also, I was mistaken about that base tag, as sometimes the current_page.url has a lead slash, and sometimes it doesn't (which killed my "fix" when I tried to test it inside a nested subdirectory).

So, I'd like to amend my recommendation to the following:

 {% if (current_page.url|slice(0,1) == '/') %}
    <base href="{{ base_url }}{{ current_page.url }}" />
  {% else %}
    <base href="{{ base_url }}/{{ current_page.url }}" />
  {% endif %}

There may be a more elegant way to test for a leading slash and decide whether or not one needs to be inserted between 'base_url' and 'current_page.url`, but I'll leave that to those more comfortable with PHP-craft.

By the way, Phile is awesome, and I love the great work that you guys are doing.

Thanks!

james2doyle commented 10 years ago

@EricWritesCode are you using 1.0.0? this may have been fixed in #95

ItsEricWoodward commented 10 years ago

@james2doyle I'm not sure, I just grabbed the latest version from here and from http://philecms.com/, and they both say "version": "0.9.2" in composer.json (even though the web page indicates 0.9.3 is the latest version).

Nevertheless, I am going to upgrade my current install with the latest version, and see if I still run into that issue. Thanks for the heads up.

james2doyle commented 10 years ago

Yeah we are in the process of moving to 1.0.0 so things are a little in flux. Should be ready soon.

ItsEricWoodward commented 10 years ago

@james2doyle Thanks. You were right, that issue was fixed.

New (final) suggestion:

<base href="{{ base_url }}/{{ current_page.url }}" />

As you said, you'd have to make sure that all of your navigation links are then using absolute URLs. For myself, I actually prefer the structure that this gives, since I use a subdomain for each instance of Phile and I like to have all of my links start with "/". However, I know not everyone has the same type of install, so YMMV.

james2doyle commented 10 years ago

Ok then. Let's close this since there are now a few solutions to choose from.