-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: Custom permalinks #34
Comments
It would also be nice if it could be extended to support any & all metadata found in the YAML head matter, though go would need a serious redux if it were to support that. (Quick idea: Add an else clause to sant0sk1's go() that matches (.*)?) |
My solution wasn't the DRYest, and I'm pretty sure it won't work any longer since a recent commit added another hardcoded regex that requires year/month/day in the I'd love to see this feature make it in though, so if somebody else wants to take a crack at it please do! |
Yea I need to look into this. |
Not trying to pressure you or whatever, but my brother did say that the only reason why he doesn't want to use toto is because it uses the /yyyy/mm/dd/xyzq format. So instead, he chose Posterous, which uses just the post's name in the URL. Bah. |
: | I could just give the option between But the date is there for a reason: so you can have two posts with the same name, at different dates. |
Exactly! That was my reasoning to him. He still didn't like it. He & I are both stubborn, so meh. Not easy to change his mind. :-) Regardless, I would like some way to map YAML headers to the path matching expression. (e.g. "/:foo/" relates to "foo: xyz" in 2010-3-30-where-ive-been.txt) |
that's an interesting idea, but it gets hairy when dealing with dates.. |
hm, true. Here's an idea:
So the default path would be |
ah so |
Yes, exactly. If we were to do this, one issue does arise, what about collisions? What would happen if year were present in the article's YAML? |
I guess it'd overwrite the generated one |
More implicit goodness: Like with :prefix, should the leading slash be required? This case is a little more fuzzy. Also, a thought occured to me. If custom permalinks work, could they overlap with |
Getting close now! http://github.com/evaryont/toto/tree/custom_permalinks Tests are failing, however. I'm working on it! :-) |
cool. The permalinks are specifically for articles, while the prefix is site-wide.. You could theoretically use both, together, such as:
resulting in |
I'm wondering if |
Alright, just about done. One last issue. Do article paths end in /? Should they not end in anything at all? Right now, they do end in / (e.g. "/foo/bar/" vs "/foo/bar") |
Has this been worked into the main branch yet? |
It's not in the upstream. But it's in @evaryont's master branch. |
Sorry guys, I haven't worked on this in forever. I'll leave my code up for someone else to take a look at, but I don't think it's exactly of the highest quality. :-) |
@evaryont, did you move the changes into your master branch? When I pull your code it doesn't seem to respond to the :permalink flag. In your blog update you mentioned you had left the custom permalink changes in this branch https://github.com/evaryont/toto/tree/custom_permalinks, but that seems to be removed. |
There's a small problem with the idea of this feature... you have to make sure permalink has all the parts needed to recreate filename. And IMHO results does not worth anything - I mean this is useless overkill. At least that seems to me (Ibelieve somebody believes that categories and tags are also overkill - but I was mssing them ;)) |
@benjholla can you describe what exactly do you want to achieve, because I believe tht can be easily done without messing with toto's routings... :)) And do you really need this? :)) |
Sure, if its possible I'd like to just take the date out of the filename itself so that the link results in something like /blog/article-name I'm fine with the idea that I can't have duplicate article names, and the date information is already included in the YAML of the article itself. In all honesty, I don't "really" need it, but I'd like to be able to update articles and their dates without changing the filename and something about having the date in the url just really bugs me. |
Well, probably you're right (but e.g. I need it and it's constant for me :)) Basically it can be done - the easiest way is to override few things. I don't have free time to prepare a full patch that will simply add required feature without any restrictions (you can see my categories and tags branches in order to get idea of how to implement this feature). Basically the most hard thing for me is to prepare tests. If somebody can prepare toto's tests that will cover this feature - I'll prepare an implementation patch without any problems :)) But if you simply need this feature up and running - you can use this snippet to override some of toto's internals and get what you need (but you will loose module Toto
class Article
def path
"/#{@config[:prefix]}/articles/#{slug}/}".squeeze('/')
end
end
class Site
def go route, env = {}, type = :html
route << self./ if route.empty?
type, path = type =~ /html|xml|json/ ? type.to_sym : :html, route.join('/')
context = lambda do |data, page|
Context.new(data, @config, path, env).render(page, type)
end
body, status = if Context.new.respond_to?(:"to_#{type}")
if route.first == 'articles'
context[article(route.slice 1..-1), :article]
elsif respond_to?(path)
context[send(path, type), path.to_sym]
elsif (repo = @config[:github][:repos].grep(/#{path}/).first) &&
!@config[:github][:user].empty?
context[Repo.new(repo, @config), :repo]
else
context[{}, path.to_sym]
end
else
http 400
end
rescue Errno::ENOENT => e
return :body => http(404).first, :type => :html, :status => 404
else
return :body => body || "", :type => type, :status => status || 200
end
end
end That's a quick and dirty idea. Even can't guarantee it will work :)) But to use it simply put it into your config.ru right before toto initialization (you can see how I extend my own toto branch in my blog). |
Thanks for the ideas, it didn't seem to work off the bat. I suppose I will actually need to sit down and figure this one out on my own :) Thanks again. |
Yeah! I assumed it won't work from the first attempt :)) It was some kind of just an idea. To make it real working I believe there should be more than one dummy change ;)) But at least today I realize how I could implement this feature - unfortunately I simply have no time for it :(( |
Well it should work, it's all just Ruby code. :-) However I stopped coding for awhile, then I went to college so I don't have time at the moment to pick this up. @benjholla, feel free to use my code if you want. I'll close this issue for now, if you get something running, please make a new ticket. (This one is old enough. :-) ) |
It seems that sant0sk1 already got it working. You (cloudhead) commented on it already, and you mentioned that go() needs to be patched. He did - sant0sk1/toto@ae4d7a0db960ac33df1200e94d3629ae3247f606 -, so I think it's ready, though, there probably will be a conflict with the newer code base.
The text was updated successfully, but these errors were encountered: