PhileCMS / Phile

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

only .md files can be referred to with relative links, not other file types. #184

Closed dahlo closed 9 years ago

dahlo commented 9 years ago

Hi there

Thanks for a wonderful CMS, it's really everything i have been looking for! I noticed an irregularity while trying to link to a .pdf i have in the same directory as my .md files. I could not use a relative link to work for anything but .md files.

Ex.

I serve my phile on it's own domain, eg http://domain.com serves the content in my phile/ directory.

I have 3 files as follows: phile/content/index.md phile/content/sub/index.md phile/content/sub/file.pdf

From index.md i can link to sub/index.md by using a relative link, [link to sub](sub/index.md) but i cannot get the web server to serve the pdf file by linking to it with a relative link, [link to pdf](sub/file.pdf)

The only way i could get the server to serve the pdf file was to link it like this, [link to pdf](content/sub/file.pdf), that is a link that is relative the web server root.

Any suggestions?

Cheers Martin

Schlaefer commented 9 years ago

The only way i could get the server to serve the pdf file was to link it like this, link to pdf, that is a link that is relative the web server root.

For existing files you have to prepend content/, because that points to the physical directory on the server and Phile doesn't do any URL magic except for the markdown files.

Any suggestions?

You could use an additional rewrite rule to serve files from content/. This should work:

RewriteCond </path/to/phile/>/content/$1 -f
RewriteRule (.*)$ content/$1 [L]

But I suggest to filter for file types if you don't want to serve everything (e.g. raw .md files).

Frodox commented 9 years ago

Yeah, I was also confused with that some time ago, and I think all newbies also did.

I do not test RewriteCond yet, but it is apache/nginx/webserver spesific.

Solution may also be a plugin

@Schlaefer, what do you think about that?

Schlaefer commented 9 years ago

@Frodox plugin is possible too.

I want to use standard markdown

A generic replacement of URLs in the document feels like a pita:

I would probably not alter the links in the document but intercept the incoming request in Phile and serve the appropriate file through PHP. If performance ever becomes a problem switch to a web-server rewrite.

I have no problem using a custom markup

Write your own plugin like phileInlineImage. Or create a simple snippet with the snippet plugin.

dahlo commented 9 years ago

Ah, i see, thank you very much for the suggestions! I ended up going with modifying the .htaccess file in Phile and added this:

RewriteCond %{REQUEST_URI} .*\.(jpe?g|gif|png|ppt|pptx|doc|docx|pps|ppsx|pdf)$
RewriteCond <path/to/phile>/content/$1 -f
RewriteRule (.*)$ content/$1 [L]

Seems to be working for my purposes. Thanks again!

Frodox commented 9 years ago

Is "foo/bar.png" really content/foo/bar.png or does foo/bar.png exist?

Yes, I thought about that too and it is not best choice.

Or create a simple snippet with the snippet plugin.

Oh, I seen some plugin but forgot it's name. That is! So alternative way will be to create snippet and include it into @infostreams 's repo. Plugin will extand syntax so we can link to files in same folder (I do not know how to get .ms's folder, but I believe it's possible:) ).

@dahlo feel free to close the Issue.

kicken commented 9 years ago

I use the following additional rewrite rule so that I can reference additional resources relatively from my pages:

RewriteCond %{DOCUMENT_ROOT}/content/$1 -f
RewriteCond $1 !\.(md)$
RewriteRule ^(.*) content/$1 [L]

Would something like this be worth including in the standard .htaccess, even if just commented out as an example? If the Phile is setup as the document root it works as is. Otherwise one would just need to add the path to Phile into the RewriteCond which is a minor modification.