Skip to content
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

Error :Liquid Exception: comparison of Array with Array failed in page #1

Open
daxiawj opened this issue Dec 17, 2013 · 2 comments
Open

Comments

@daxiawj
Copy link

daxiawj commented Dec 17, 2013

When I added example tags.html tag_cloud to my custom aside with tag_cloud plugin, and run "rake generate", it said error:

/Users/daxiawj/Workspace/octopress/plugins/tag_cloud.rb:76:in sort!' /Users/daxiawj/Workspace/octopress/plugins/tag_cloud.rb:76:inrender'

I don't know what's wrong with my files or configurations.

btw, my tag_pages works fine.

@themlee
Copy link

themlee commented Feb 15, 2014

It's a math problem in the plugin.
You only have too change:

      weighted = count.map do |name, count|
        # logarithmic distribution
          weight = (Math.log(count) - Math.log(min))/(Math.log(max) - Math.log(min))
        [name, weight]
      end

to this:

      weighted = count.map do |name, count|
        # logarithmic distribution
        if min == max
          weight = 1
        else
          weight = (Math.log(count) - Math.log(min))/(Math.log(max) - Math.log(min))
        end
        [name, weight]
      end

I hope it works for everybody...

@honwsn
Copy link

honwsn commented May 23, 2014

weighted = count.map do |name, count|
    # logarithmic distribution
    if min == max
      weight = 1
    else
      weight = (Math.log(count) - Math.log(min))/(Math.log(max) - Math.log(min))
    end
    [name, weight]
  end

or

    " # Add this check for NaN to close #2 
    weight = 0 if weight.nan?"

-----------------yeah,, these can remove that exception。。。
if not have a same tag in three(or more ) posts,all tags in main page will have same font size ,either large or small..
but small may be better, so weight = 0 if weight.nan?" is better. may weight = 0.5 is the best..

I

taringamberini added a commit to taringamberini/octopress-tag-cloud that referenced this issue Jul 5, 2015
PROBLEM

When every page which declares tag has the same tags then running:

    $ rake generate

the plugins breaks with the following exception:

    ## Generating Site with Jekyll
        write source/stylesheets/screen.css
    Configuration file: ... /_config.yml
                Source: source
           Destination: public
          Generating...
      Liquid Exception: comparison of Array with Array failed in _layouts/page.html
    jekyll 2.5.3 | Error:  comparison of Array with Array failed

CAUSE

When each tag occures the same number of times, calculated over all the posts,
then in the logarithmic distribution expression:

    # logarithmic distribution
    weight = (Math.log(count) - Math.log(min))/(Math.log(max) - Math.log(min))

`min` is equal to `max` so `weight` assume the value `NaN` which make comparison
with numbers fails.

SOLUTION

Use logarithmic distribution only if `min` is not equals to `max` otherwise use
the value:

    # value which makes the font-size calculated below equal to 100%
    weight = (100 - size_min) / (size_max - size_min)

The value proposed for `weight` is the one which makes the font-size calculated
few lines below equals to 100%:

    size = size_min + ((size_max - size_min) * weight).to_f

in other words as none of each tag occures more then another one then all tags
font-size must be the same: 100% is exactly the font-size of the text in the
same block either `<article>` or `<aside>`.

robbyedwards#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants