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 author, image, and JSON-LD to dedicated drops #229

Merged
merged 13 commits into from
Aug 24, 2017

Conversation

benbalter
Copy link
Collaborator

I began this PR by trying to simplify the author, author_string_or_hash, and site_author_hash methods by moving the author logic to its own dedicated drop with smaller methods.

Having done that, I saw that the image could be similarly pushed into its own drop and that or existing JSON-LD implementation, was essentially a drop (although we were including it in the main class, rather than subclassing it).

In the end, this PR (or potentially three PRs, I made the commits distinct) should be fully backwards compatible, but should move the author, image, and json_ld logic out of the already-very-long Jekyll::SeoTag::Drop and into their own drop-based classes.

A few things to call out:

  • I wrote the author drop, such that, it could be pulled out into its own library, and theoretically, be a drop-in replacement for page.author, in that PageDrop#to_s will return the author name, as if it were a string (e.g. via liquid), and it can also be accessed as a hash to retrieve additional metadata, when present.

  • The tests pass almost entirely unchanged. All I did was move the tests from drop_spec to foo_drop_spec and update the method calls form e.g., subject.author to just author.

  • The integration spec was unchanged, save the order of the elements in the JSON output.

  • In the long run, I'd ideally like Jekyll SEO to expose really good drops to the HTML template, and allow users to override the template with their own if they want logic/optimization beyond the majority use case (but have the tools to do so without starting from scratch).

Thoughts? Is this easier to maintain? Harder? Too much for one PR? Won't be offended either way, but wanted to push up the idea.

@benbalter benbalter requested review from DirtyF and pathawks August 23, 2017 20:40
alias_method :to_s, :name

def twitter
return @twitter if defined? @twitter
Copy link
Member

Choose a reason for hiding this comment

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

@twitter made me look twice. When Ruby and Twitter semantics collide.

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.

This is fantastic!

I love that you have setup AuthorDrop so it could be easily extracted into its own helper gem.

drop it like it's hot

@@ -18,62 +17,6 @@ module JSONLD
:links => "sameAs",
:canonical_url => "url",
}.freeze

def json_ld
Copy link
Member

Choose a reason for hiding this comment

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

If the goal is backwards compatibility, do we need to keep this method as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drop extended JsonLD (which is where I moved this method to). Theoretically, if someone extended the module into another class, this would be a breaking change. I'll can duplicate it here with a note that it should be removed at the next major release.

Copy link
Member

@DirtyF DirtyF left a comment

Choose a reason for hiding this comment

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

Seems like a smart move, really appreciate the effort you make to share your vision @benbalter.

The code is more modular and it's great if this helps provide more extensibility to the developers.

Didn't know much about Drops before, but starting to get the big picture.

Best branch name ever on 🔝 of that.

obama-drop-mic

@benbalter
Copy link
Collaborator Author

Didn't know much about Drops before, but starting to get the big picture.

Learning the power of drops myself. They're intended to be lazy loaders, but essentially act as super smart hashes. The TL;DR is that any public method is exposed to liquid as both foo.bar and foo["bar"] with fallback_data providing a hash of defaults if no public method matches. It's a really elegant/simple way to expose discrete pieces of calculated content to the user without giving them direct access to lower-level Ruby functions.

@benbalter benbalter merged commit 9dc5b01 into master Aug 24, 2017
@benbalter benbalter deleted the drop-it-like-its-hot branch August 24, 2017 17:07
@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.

4 participants