URL mapping

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

URL mapping

Hugo <Nabble>
We need URL mapping.
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
Why?
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

Hugo <Nabble>
If I create a blog for myself, I would like to have urls like /articles/123/article-name.html

If someone searches for a specific tag, I would like the URL like /tag/tag-name (e.g. /tag/java)

How can I do this with luan?
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
The only reason for this is SEO, and since none of us really understand SEO, I don't even know if this matters anymore.  Forgetting SEO, the right URLs are:

/articles?id=123&name=I+love+pizza
/search?query=java
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

Hugo <Nabble>
This isn't only for SEO. The clean look of a website is also reflected in the URLs. This is part of the web design. People share links in social networks and strange characters in the URL make things look crappy. I don't see a reason why we shouldn't have this.
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
This is worth discussing because this is exactly the kind of feature that I never want to see in Luan.

First, the "clean" look is actually the modern look.  Let's compare:

/articles/123/I+love+pizza.html
/articles?id=123&name=I+love+pizza

The difference in length is marginal.  Non-tech users won't even look at the URL.  To them it is a black box, just something to click on.  Who will care about the URL?  The trendy techie will care.  But these are the people I hate, and who will hate Luan no matter what.  So I don't care about them.

The reason that I am so strongly against URL mapping is that it adds one level of indirection to understanding the site.  With URL mapping, the person trying to understand the code will have to look at that mapping to understand any URL.  This adds significant complexity/work to understanding the site.  Without URL mapping, the meaning of URL is immediately obvious from the URL itself.  In the second URL above, you just look at /articles.luan and you know it will receive 2 parameters named "id" and "name".

My primary goal is simplicity which means, above all, that code should be easy to read.  Imagine that you developed a site and then forgot about it for years.  Now you want to go back to it to make a small change.  The test of Luan is how long will it take you to make that small change.  I think URL mapping would significantly increase the time to make that change.  It's not just looking at the URL mapping code, it's also remembering or figuring out how URL mapping works in the first place.

By the way, I looked at the forums I use and all of them (except Nabble) use unmapped URLs.  Here is a typical URL:

http://www.happierabroad.com/forum/viewtopic.php?f=46&t=25346

Using this style, the above URLs would just be:

/articles?id=123
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

Hugo <Nabble>
We discussed this. We agreed that URL mapping is important because sites that move to luanhost could use it and keep old URLs working.
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
This post was updated on .
In reply to this post by Hugo <Nabble>
To do this, in an init file, do:
local old_site = Io.schemes.site

function Io.schemes.site(path)
	if path.match[[/articles/\d+/.+\.html\.luan]] ~= nil then
		return Io.schemes.string[[return require 'site:/article']]
	end
	return old_site(path)
end
article.luan should parse the path to get the info it needs.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

Hugo <Nabble>
In the jeans project I added this to server.luan:
--- START TEST
local old_site = Io.schemes.site

function Io.schemes.site(path)
	if path.match[[/articles/\d+/.+\.html\.luan]] ~= nil then
		return Io.schemes.string[[return require 'site:/article']]
	end
	return old_site(path)
end
--- END TEST

Then I created a file called article.luan like this:
import "luan:Io"
import "luan:web/Http"

function service()
	Io.stdout = Http.response.text_writer()
%>
<!DOCTYPE html>
<html>
	<head>
		<title>Article 123</title>
	</head>
	<body>
		ok
	</body>
</html>
<%
end
This doesn't work. I tried printing the "path" variable inside the Io.schemes.site function, but it doesn't print anything. What am I missing?
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
You shouldn't touch server.luan .  Remember that any solution should also work on luanhost and you have no access to server.luan there.  Io.schemes.site should be redefined in an init file (as described in the "initialization" thread).
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

Hugo <Nabble>
Okay, this works with luanhost. You can close this thread.
Reply | Threaded
Open this post in threaded view
|

Re: URL mapping

fschmidt
Administrator
closing
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture