I’m well aware of that, but you have to look at how links are usually generated to be able to find a solution.
@PaulMorel: Let me know if this works for you, then we can close the GitHub issue again and wait for a native method to get a permanent URL.
As a file method:
<?php
file::$methods['permanentUrl'] = function($file) {
return site()->url() . DS . $file->page()->id() . DS . $file->filename();
};
This causes a error 500 on the server and Kirby seems to display a JSON response of the error.
{"status":"error","message":"Invalid route or request method"}
I get an error 500 served by the server, not Kirby.
Do you get the error when clicking such a link or just from adding the method as a plugin?
While clicking for the former and while adding the method for the latter.
Edit: my bad, there was a typo.
I just added the file method in a new file “methods.php” and saved that in the plugins folder, that’s all (/site/plugins/methods.php
)
My bad, there was a typo in the file.
I still get a Kirby route error though. From what I can see it’s because neither urls have the language codes.
In my case, it works if you do it like this though.
file::$methods['permanentUrl'] = function($file) {
return site()->url() . DS . site()->language()->code() . DS . $file->page()->id() . DS . $file->filename();
};
Not ideal, but it works.
Note that the DS
constant is not great here. You won’t have a problem on a Linux server, but for URLs you should just use /
.
file::$methods['permanentUrl'] = function($file) {
$site = $file->site();
$lang = $site->multilang() ? $site->language()->code() . '/' : '';
return $site->url() . '/' . $lang . $file->page()->id() . '/' . $file->filename();
};