Skip to content

Infer title and heading from comment #223

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

Merged
merged 1 commit into from
Aug 1, 2023
Merged

Conversation

p8
Copy link
Member

@p8 p8 commented May 19, 2023

Some classes in Rails have a h1 heading defined in the RDoc comment.
For example:
https://github.com/rails/rails/blob/4e1fe73028f4b01c8e5179989511b21925f70b20/activesupport/lib/active_support/current_attributes.rb#L8
https://github.com/rails/rails/blob/4e1fe73028f4b01c8e5179989511b21925f70b20/actionpack/lib/action_controller/metal/strong_parameters.rb#L1159
This makes the heading more readable especially when there are a lot of
namespaces.

For SEO it helps if all classes have a h1 heading, but having to add
them by hand is cumbersome when we can generate them instead.

By looking at the comment of the class/module we can see if it has a
h1 heading when it's starting with = or # . If the heading is
missing we can generate a heading with the full name of the class
instead. This will prevent us from having to add the h1 for each class
in Rails.

This change is backwards compatible and works without having to make changes in Rails.

This also adds the @options.title ("Ruby on Rails API") to the title tag of every class, which also helps with SEO.

I looked at the :title: directive, but that only works if it hasn't been set yet and can'be overridden:
https://github.com/ruby/rdoc/blob/cc40a39714d894180713032ac6049e192e72f3db/lib/rdoc/options.rb#L512-L518

@p8 p8 force-pushed the features/default-titles branch 2 times, most recently from 2293c87 to dce7139 Compare May 19, 2023 20:02
@p8
Copy link
Member Author

p8 commented May 19, 2023

I'm not sure if we should humanize the classname. For some modules and error classes I actually prefer the module name:
image

https://deploy-preview-223--sdoc.netlify.app/classes/activejob/deserializationerror
https://deploy-preview-223--sdoc.netlify.app/classes/activejob/queueadapter/classmethods

@zzak
Copy link
Member

zzak commented May 25, 2023

As an alternative, why don't we just put the module name as an <h1> at the top and forgo the humanizing of API titles, we don't really know which performs better yet and what developers are searching for. My thinking though, is that without the module/class name being searchable the rest doesn't matter.

For example, if I'm searching for "Active Record Associations", should I land on the API page that probably has more detail than necessary? Or should I end up on a guide that can gradually introduce me to the concept and link to API parts to dig deeper?

@p8
Copy link
Member Author

p8 commented Jun 2, 2023

@zzak the current PR doesn't humanize the titles, so this is conform your proposal.

Some classes in Rails have a h1 heading defined in the RDoc comment.
For example:
  https://github.com/rails/rails/blob/4e1fe73028f4b01c8e5179989511b21925f70b20/activesupport/lib/active_support/current_attributes.rb#L8
  https://github.com/rails/rails/blob/4e1fe73028f4b01c8e5179989511b21925f70b20/actionpack/lib/action_controller/metal/strong_parameters.rb#L1159
This makes the heading more readable especially when there are a lot of
namespaces.

For SEO it helps if all classes have a h1 heading, but having to add
them by hand is cumbersome when we can generate them instead.

By looking at the comment of the class/module we can see if it has a
`h1` heading when it's starting with `= ` or `# `. If the heading is
missing we can generate a heading with the full name of the class
instead. This will prevent us from having to add the h1 for each class
in Rails.

This also adds the `@options.title` to the `title` tag of every class.
@p8 p8 force-pushed the features/default-titles branch from dce7139 to 60e05b5 Compare August 1, 2023 09:44
@p8 p8 merged commit 11f0df8 into rails:main Aug 1, 2023
@p8 p8 deleted the features/default-titles branch August 1, 2023 09:55
jonathanhefner added a commit to jonathanhefner/sdoc that referenced this pull request Aug 20, 2023
In rails#223, we began generating default `<h1>` headings for modules.
However, these headings were only generated for modules that had a
description.  If a module had no comment to begin with, it would not get
a generated heading.

Furthermore, since rails#280, each module's full name has been prominently
displayed at the top of its page.  These names are visually redundant
with generated headings, which also use the full name.

To unify the design and ensure that all modules have an `<h1>`, this
commit converts each module's full name into an `<h1>` heading inside an
`<hgroup>`, and uses postprocessing to pull any comment-based `<h1>`
into the `<hgroup>`.

This commit also renames the "Included Modules" section to "Inherits
From", and moves any listed base class from the top of the page to the
top of that section.  This change focuses the `<h1>`, both visually and
from an SEO perspective.
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

Successfully merging this pull request may close these issues.

2 participants