Giter Club home page Giter Club logo

Comments (27)

nogweii avatar nogweii commented on July 23, 2024

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 (.*)?)

from toto.

jerodsanto avatar jerodsanto commented on July 23, 2024

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 load method.

I'd love to see this feature make it in though, so if somebody else wants to take a crack at it please do!

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

Yea I need to look into this.

from toto.

nogweii avatar nogweii commented on July 23, 2024

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.

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

: |

I could just give the option between /article/ vs /2010/12/12/article - that should mostly work.

But the date is there for a reason: so you can have two posts with the same name, at different dates.

from toto.

nogweii avatar nogweii commented on July 23, 2024

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)

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

that's an interesting idea, but it gets hairy when dealing with dates..

from toto.

nogweii avatar nogweii commented on July 23, 2024

hm, true. Here's an idea:

  • :date matches the generated date (from the config). e.g. "31 March 2010"
  • :year matches the machine year (e.g. 2010)
  • :month, :day - the same as :year

So the default path would be /:year/:month/:day/:title, but it would be also possible to have "/31March2010/where-ive-been/" as the permalink (/:date/:title, with set :date {|date| date.strftime(..)} in config.ru)

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

ah so :year :month :day are 'generated', and the rest is from the metadata

from toto.

nogweii avatar nogweii commented on July 23, 2024

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?

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

I guess it'd overwrite the generated one

from toto.

nogweii avatar nogweii commented on July 23, 2024

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 :prefix's functionality? What's different between:
set :prefix, "blog"
set :permalink, ":year/:title"
and
set :permalink, "blog/:year/:title"
?

from toto.

nogweii avatar nogweii commented on July 23, 2024

Getting close now!

http://github.com/evaryont/toto/tree/custom_permalinks

Tests are failing, however. I'm working on it! :-)

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

cool. The permalinks are specifically for articles, while the prefix is site-wide.. You could theoretically use both, together, such as:

set :prefix, "blog"
set :permalink, "articles/:title"

resulting in /blog/articles/my-title for an article, and /blog/ for the index

from toto.

cloudhead avatar cloudhead commented on July 23, 2024

I'm wondering if :format is not a better name for the permalink option

from toto.

nogweii avatar nogweii commented on July 23, 2024

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")

from toto.

benjholla avatar benjholla commented on July 23, 2024

Has this been worked into the main branch yet?

from toto.

ixti avatar ixti commented on July 23, 2024

It's not in the upstream. But it's in @evaryont's master branch.

from toto.

nogweii avatar nogweii commented on July 23, 2024

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. :-)

from toto.

benjholla avatar benjholla commented on July 23, 2024

@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.

from toto.

ixti avatar ixti commented on July 23, 2024

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 ;))

from toto.

ixti avatar ixti commented on July 23, 2024

@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? :))

from toto.

benjholla avatar benjholla commented on July 23, 2024

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
not
/blog/2011/09/01/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.

from toto.

ixti avatar ixti commented on July 23, 2024

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 /archives/2011 possibilities):

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).

from toto.

benjholla avatar benjholla commented on July 23, 2024

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.

from toto.

ixti avatar ixti commented on July 23, 2024

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 :((

from toto.

nogweii avatar nogweii commented on July 23, 2024

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. :-) )

from toto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.