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

Convert seo_author_* logic to a drop #184

Merged
merged 32 commits into from
Apr 11, 2017
Merged

Convert seo_author_* logic to a drop #184

merged 32 commits into from
Apr 11, 2017

Conversation

benbalter
Copy link
Collaborator

This PR moves the seo_author_* logic in the template to Ruby, where it can be implemented as a drop. The goal is readability, testability, and performance.

The resulting output should be identical, save the absence of whitespace in the JSON-LD output.

I believe the original tests should pass with the small whitespace change.

One thing to call out, I'm not 100% sold on the JSON-LD approach, but was trying to find the most efficient way to generate the hash and DRY things up.

Thoughts?

Fixes #176.

@DirtyF
Copy link
Member

DirtyF commented Apr 8, 2017

The resulting output should be identical, save the absence of whitespace in the JSON-LD output.

@benbalter This looks great, I dig the move to Ruby.

I did a manual test on a blog post of mine and I notice minor differences between 2.2.0 and this PR (after beautifying the content in Atom)

diff-jekyll-seo-tag-drop

If I copy the JSON-LD output to https://search.google.com/structured-data/testing-tool I got fewer errors than before. (errors with author and publisher name and type are gone ✅ )

So apart from email that went missing - but is it useful? - this looks rather pretty good to me. 👏 👏 👏

@benbalter
Copy link
Collaborator Author

@DirtyF Nice. It looks like what should be the name string is being returned as the entire author hash in the new version? How are you supplying the author? Looking at the code and tests I'm not sure how to recreate that. Unless I'm reading the diff backwards, in which case, shouldn't the name field be a string, not a hash with the key name in it?

Added datePublished back in via d2f053d. Good catch.

@benbalter
Copy link
Collaborator Author

Also to note, testing with my own site, I'm consistently seeing a 30%-40% performance improvement over master.

@DirtyF
Copy link
Member

DirtyF commented Apr 10, 2017

It looks like what should be the name string is being returned as the entire author hash in the new version?

Sorry for the confusion, to be clearer the new version returns correct values:

"name":"Frank Taillandier",
"author":{"@type":"Person","name":"Frank Taillandier"}

How are you supplying the author?

Via a key in the config file

I've got only a dozen posts on this blog, but I see a gain of 10% 😄

@benbalter
Copy link
Collaborator Author

the new version returns

What is it supposed to return?

let(:metadata) do
{
"title" => "title",
"author" => "author",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a test for author provided as a Hash in metadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DirtyF
Copy link
Member

DirtyF commented Apr 10, 2017

@benbalter Everything is fine.

https://search.google.com/structured-data/testing-tool displays one warning left related to image in BlogPosting schema but it was already the case before this PR.

Copy link
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaaace ♠️

require "jekyll-seo-tag/version"

module Jekyll
class SeoTag < Liquid::Tag
autoload :JSONLD, "jekyll-seo-tag/json_ld"
autoload :Drop, "jekyll-seo-tag/drop"
autoload :Filters, "jekyll-seo-tag/filters"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently ran into an issue with this because I didn't add lib to the $LOAD_PATH, so local tests didn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Should the `<title>` tag be generated for this page?
def title?
return false unless title
@text !~ %r!title=false!i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be good to memoize, right?

def title?
  return false unless title
  return @is_title if defined?(@is_title)
  @is_title = @test !~ %r!title=false!i
end

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Page title with site title or description appended
def title
@title ||= begin
if page["title"] && site_title
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With jekyll-titles-from-headings have populated this by the time this code is called? If so, then 😍!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

97% sure? A generator should be be called the render phase.

def name
@name ||= begin
return seo_name if seo_name
return unless homepage_or_about?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that none of these nil values will be memoized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def description
@description ||= begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the begin here necessary? I believe you can keep this on 2 lines if needed without the begin...end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def homepage_or_about?
["/", "/index.html", "/about/"].include? page["url"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are about.html, /index.htm, /index/ also valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to regex and added tests via cfe7e56.

I'm not super excited to support /index/ or about.html. (GitHub Pages lazy indexes and ugly permalinks). I could see a case for the second if there was strong desire.

attr_reader :context

def fallback_data
{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to memoize this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def absolute_url?(string)
string.include? "://"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good call. 8cb5953.

def format_string(string)
FORMAT_STRING_METHODS.each do |method|
string = filters.public_send(method, string)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good use-case for reduce, or each_with_object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL'd 650fe5c.

Copy link
Member

@pathawks pathawks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍👍🏼

@benbalter benbalter mentioned this pull request Apr 11, 2017
2 tasks
@benbalter benbalter merged commit 6a37336 into master Apr 11, 2017
@benbalter benbalter deleted the drop branch April 11, 2017 21:35
@benbalter benbalter mentioned this pull request Apr 12, 2017
@jekyll jekyll locked and limited conversation to collaborators Apr 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move seo_author_* logic to Ruby
5 participants