Hi,
According to Google, the author attribute is now very important.
I propose to add this feature as Drupal is SEO friendly and should do its best to be.
Patch coming.
| Comment | File | Size | Author |
|---|---|---|---|
| #53 | 1184472-rel-author.patch | 2.05 KB | bleen |
| #50 | username-link-1184472-50.patch | 1.96 KB | kathyh |
| #48 | username-link-1184472-46.patch | 1.92 KB | kathyh |
| #46 | username_link-1184472-46.patch | 1.92 KB | kathyh |
| #44 | username_link.patch | 1.88 KB | robloach |
Comments
Comment #1
ralt commentedPatch attached.
Comment #3
ralt commentedHmf. Stupid mistake.
Comment #4
ralt commentedComment #5
ralt commentedComment #6
aspilicious commentedIf I'm correct this is html5 only? Adding a tag.
Comment #7
ralt commentedActually, the rel attribute can already be used in XHTML 1.1.
Just like rel=external (widely used), which's been added officially in HTML5, it can already be used in HTML4. Thus, it is not HTML5 only.
Comment #8
Everett Zufelt commentedIs rel=author valid xhtml 1.0?
What about when user is rendered outside of an authoring context? Does Who's online, or Who's new, use the same preprocess for User?
Comment #9
ralt commentedrel="author" is not xhtml 1.0 strict valid, rel="nofollow" isn't either (both are xhtml 1.0 transitional valid, though). But having better SEO (and the link in the first post indicates that Google will work with this attribute) is still a better way to go (if you don't think so, then remove the nofollow...).
I didn't think about having it rendered outside of the authoring context. I do think that Who's new/online use the same preprocess. I don't see a way to separate them, though :/. Any idea?
Comment #10
ralt commentedAlright, found a solution. This may look like a dirty solution, but template_preprocess_username() only has one argument : &$variables. So it is not possible to add any option. A cleaner way would be to change the signature of this function so that I can add an option correctly. But it just doesn't look like right to me.
Comment #11
Everett Zufelt commentedDrupal 8 will be html5, but is also going to need to be able to fallback to valid xhtml 1.0, so however we add this, we are going to need to make sure it is easily removed.
Have you looked at either:
1. What can be done in hook_preprocess_node(), where the name is being used in the context of authorship
2. adding a boolean variable to $variables that can be set to true when the username is being rendered in an authorship context
Comment #12
ralt commentedrel="author" is exactly the same as rel="nofollow", used a lot in D7 already. Having a fallback is not necessary.
1. The patch at #10 actually changes template_preprocess_node(), this is what you meant by "hook_preprocess_node" ?
2. Good idea, this is what the attached patch does. It does look cleaner.
Comment #14
ralt commentedI think I see why it's failing. Posting patch fixing this.
Comment #16
ralt commented...
Comment #17
ralt commentedThe not 0 bytes file... (it sure is hard with my new pc ;()
Comment #19
ralt commentedHm. The tests failed are these lines :
$comment1, $comment2 and $comment3 were created this way :
I just don't see how my patch affects this. Any help?
Comment #20
aspilicious commented#17: adding-author-to-submitted-by-link-1184472-15.patch queued for re-testing.
Comment #21
aspilicious commentedThats a broken test
Comment #22
droplet commentedredundant comment?
12 days to next Drupal core point release.
Comment #23
Everett Zufelt commentedI haven't read through the comments, just the patch. I'm not sure why we are adding a line to set title twice?
This should be:
Comment #24
ralt commentedHello,
@22 : Why is that a redundant comment ? I may add a comma after the first line to avoid any ambiguity ?
@23 : I didn't know I could use this syntax. But yeah, it is indeed a better way to go if this works.
I cannot change the patch yet, will do that ASAP.
Comment #25
robloach:-)
Comment #26
jcnventuraThe way it's now, I don't think it's future-proof enough..
Instead of
it should be something like:
That way, you can actually set the rel tag to something other than 'author' simply by setting the value to something else.. Drupal could even start to support XFN natively :)
And it needs a test..
Comment #27
ralt commentedFixed #22, #23 and #26. About the tests, what should I test? That the variable exists?
Comment #28
rickmanelius commentedI think I see a problem in #27. $variables for hook_preprocess_node is different than the variables for hook_preprocess_username. So while you're setting $variables['username_rel'], that key is not available when you're checking it in the hook_preprocess_username.
The only way I'm able to get rel="author" to show up is to remove the if statement altogether, undermining the ability to set the author attribute in the specific, applicable instances.
I'm trying to think if there is another way to do this...
Comment #29
rickmanelius commentedThere seems to be an issue of context... and I'm not sure how easy it'll be to for the theme_link theme to know that context at the block level.
Comment #30
ralt commentedActually, the rel="author" tag should not appear anywhere else than in node's context. This tag is there to show, on a content page, who is the author of this content. This is not there to say "hey, this guy is a user". That's why I think we do not have to extend the tag to the block level.
Comment #31
Everett Zufelt commentedAgree with #30. rel=author is only applicable in an authoring context, e.g. the display of a node.
Comment #32
Everett Zufelt commented@ralt
I expect that testing that the attribute exists, and is set to author is a reasonable test.
Comment #33
rickmanelius commentedRalt. I totally understand when it's only in the node itself. What I found in my digging is that the function used to render said link has no idea if it's being rendered within a node versus some other page element.
Case in point. I applied your patch and then went to a node with the "who's online" block to the left. In the patch, it's using node_preprocess to add an key to the $variables array and then using the variable to check in the username preprocess function to determine if we're in the node.
The problem is that nodes $variable array is not the same passed to the username function, and thus that if control statement returns false everytime based on my testing.
I totally understand the context when it should be added. What I'm trying to figure out is the best way to pass the hook_preprocess_username the variable necessary to alert it that it's within a node and thus should use the rel="author" tag.
Comment #34
jcnventura@Ralt: nice to adopt the definition I suggested, but the objective is to use the content of the variable also...
Or else, you gain nothing from changing it from the previous 'true' value.
I've slightly modified your patch to make it even more extensible. Notice the use of an array, so that more than one rel value can be set (i.e. rel="author me").
Comment #36
jcnventura#34: adding-author-to-submitted-by-link-1187442-33.patch queued for re-testing.
Comment #38
oriol_e9gOnly #34 reroll
Comment #39
ralt commented@jcnventura : Oh nice, I didn't understand what you meant indeed :)
@rickmanelius : I'm not sure I've understood what you said. I don't have time yet to dive deeper into that. I guess I'll see the problem when I'll write the tests.
Comment #40
rickmanelius commentedMy point was that the variables being set in template_node_preprocess are not made available in template_preprocess_username and thus it may never validate as true and add the rel="author" information.
But I'll check against #38 to see if there was another way around this based on the suggestions of jcnventura
Comment #41
rickmanelius commented#37 does not work because the template_preprocess_username does not have the $variables['username_rel'] variable passed to it.
Comment #42
ralt commentedI totally see what you mean.
I can think of two ways for solving this.
Comment #43
robloachWow, template_preprocess_username, theme_username and template_process_username are absolutely disgusting.
Comment #44
robloachHere's a fixed patch.... Would be good to clean those functions up though, they're so gross to work with.
Comment #45
ralt commentedThanks Rob Loach ! Couldn't think of this way :-)
Also, what do you mean by cleaning up those functions ? Except for the fact that they're comment-verbose, I don't see anything wrong... (after your patch)
Maybe you could explain more what you meant?
Comment #46
kathyh commentedUpdated for #22336: Move all core Drupal files under a /core folder to improve usability and upgrades - reviewed with patch applied and noted use of rel="author".
Comment #48
kathyh commentedrenaming patch - I don't know why this is failing - works on localhost.
Comment #50
kathyh commentedresubmitting patch (this has wrong EOL conversion). stumped - am curious what the fix would be.
Comment #52
cosmicdreams commentedI'll take a look after turkey. If I can't knock it out this weekend I'll unassign.
Comment #53
bleen commentedThis should fix it ...
Comment #54
robloachYup! That does it.
Comment #55
dries commentedCommitted to 8.x. Thanks.
Comment #57
ereq commentedHello, where do you upload this file?
Comment #58
klonosCan this be backported to D7? If not, how does one achieve the same thing? ...in the theme level perhaps? Is there any contrib D7 module that takes care of it?
PS: I might be asking this question here for D7, but I'm sure people would want to know the same for D6 too.
Comment #59
bleen commentedthis definitely *could* be back-ported ... but I suspect that Dries/Webchick would consider that an API change (albeit minor) and wouldnt agree to commit it
If you want to achieve something like this in D7 you could always write a mytheme_preprocess_node(&$variabels) function & mytheme_preprocess_username(&$variables) function in your template.php file and then just follow the same basic idea as the patch in #53
Comment #60
klonosThanx Alexander. ...still digesting your pointers :/
Any chance for someone to provide a code snippet ready to go in the template.php file (or a D7 contrib module perhaps)?
Comment #61
bleen commentedUNTESTED, but something like this should work (put it in template.php):
Comment #62
klonos...well sticking the two functions at the end of the core Garland theme's template.tpl (renaming
mytheme_*togarland_*and removing the wrapping php tag of course) simply gives me a WSOD :/Comment #63
klonos...garland already has a garland_preprocess_node function, so I moved the code from the one you provided in it. That got rid of the WSOD. Also had to change
&$variablesto&$vars. After making sure I cleared caches, still Google's Rich Snippets Testing Tool sees no authorship markup in my pages.Comment #64
klonos...and inspecting the link:
<a class="username" title="View user profile." href="/my-site/el/user/1">admin</a>Comment #65
klonos...here it is:
Notice: Undefined variable: node in garland_preprocess_node() (line 123 of /var/www/my-site/themes/garland/template.php).line 123 is
'account' => $node,of course.Don't know why this didn't come up before with all the page refreshes & cache purging :?
Comment #66
klonos...garland_preprocess_node
...moving the line so that
$vars['submitted']is set after$vars['name']Now the submitted info when the node is rendered replaces the actual username link with plain text "Anonymous (not verified)":
Fri, 02/10/2012 - 18:07 — Anonymous (not verified)
Will try to get some sleep and fight this a bit more once my brain is back in place :p ...I'll probably open a new support request against D7 so I don't add noise here any more - sorry people.
Comment #67
bleen commentedComment #68
klonos...filed #1444856: D7: how to add rel="author" to the "Submitted by" link? as a support request.
Comment #69
SamuelChris commentedthanks for this info , helpful me