-
Notifications
You must be signed in to change notification settings - Fork 440
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
Add support for meta tags #1091
Conversation
I'd like to see improvements to Ruby documentation SEO as well. Metatags can still be useful, but I'm not sure defining global metatags is the right approach. |
I like the idea of using declaration information as part of the meta tags. How does Sdoc handle a scenario where there's no single declaration on the top level? For example this code: class Foo
end
class Bar
end Does it consider the first declaration as the one to be used in meta tags? Or does it only support one top level namespace per file? Also, how can we support meta tags for the main page (often the README)? |
Each class has it's own page. So both Foo and Bar would have their own pages.
Sdoc gets the description from the README I think. |
eace592
to
07c4313
Compare
In the latest commit, I changed the implementation to follow the approach suggested by @p8. I agree that page specific meta tags will definitely be better than a global definition. And it solves the issue of the weird JSON arguments. I studied the approach SDoc is using a bit. It's using Nokogiri to find the first paragraph of text in any given page and then it uses that for the description. I assumed that we cannot have a dependency on Nokogiri in RDoc, so I took a much simpler approach. The idea is to try to extract an excerpt of the class/module comment or the page's content up until the second period, the first period or at most 150 characters (which ever matches first). It's definitely not perfect and it will be thrown off by other unrelated dot characters like the ones present in URLs or inside examples of method invocations in documented code. If you have any other ideas, please let me know. @nobu I'd love to hear your thoughts on the approach. |
Sorry to be lazy. |
c3ff437
to
db44e21
Compare
db44e21
to
518bb40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested against ruby/ruby
and it works great. Thank you!
Motivation
Without being able to add SEO meta tags, such as
description
orkeywords
, documentation websites generated by RDoc often don't rank well in search engines. For example, Ruby's official documentation (generated by RDoc), is rarely the first result when searching for "Ruby documentation".I think it would be really beneficial to allow developers to define meta tags for improving the SEO of their RDoc generated websites - and Ruby itself can benefit from it.
Implementation
I split the implementation by commit:
meta_tags
to optionsmeta_tags
to theRDoc::Task
meta_tags
to create the entries in the HTMLmeta_tags
for RDoc's own documentationConcerns
My main concern with this implementation is the format of the
meta_tags
option. I used a hash to provide flexibility in which meta tags the users can define. I believe the flexibility is important, because there are many meta tags and trying to account for all of them would be impractical (e.g.:keywords
,description
,og:description
,og:title
and so many others).However, the current implementation of RDoc only allows for CLI-style options. Every option has to be passed as if it were coming from the command line (e.g.:
--something=otherthing
). This makes passing a hash to themeta_tags
option quite weird. I'm currently converting it into a JSON, so that I can parse it back into a hash after theOptionParse
extracts the options.I don't really like the approach, but my two arguments for proposing this solution are:
keywords
anddescription
as two hardcoded optionsLet me know what you think about this.
Testing this change
bundle exec rake rerdoc
to generate the website_site/index.html
contains the following tags