Skip to content

Commit

Permalink
Rollup merge of rust-lang#109977 - notriddle:notriddle/data-nosnippet…
Browse files Browse the repository at this point in the history
…, r=jsha,the8472

rustdoc: avoid including line numbers in Google SERP snippets

![image](https://user-images.githubusercontent.com/1593513/230141184-9171c8e0-de92-48e6-85b6-8baee35e6d86.png)
  • Loading branch information
matthiaskrgr committed Apr 6, 2023
2 parents e7376ef + e9daab2 commit f99b844
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pre.item-decl {
.source .content pre {
padding: 20px;
}
.rustdoc.source .example-wrap > pre.src-line-numbers {
.rustdoc.source .example-wrap pre.src-line-numbers {
padding: 20px 0 20px 4px;
}

Expand Down Expand Up @@ -537,17 +537,17 @@ ul.block, .block li {
margin-bottom: 0px;
}

.rustdoc .example-wrap > pre {
.rustdoc .example-wrap pre {
margin: 0;
flex-grow: 1;
}

.rustdoc:not(.source) .example-wrap > pre {
.rustdoc:not(.source) .example-wrap pre {
overflow: auto hidden;
}

.rustdoc .example-wrap > pre.example-line-numbers,
.rustdoc .example-wrap > pre.src-line-numbers {
.rustdoc .example-wrap pre.example-line-numbers,
.rustdoc .example-wrap pre.src-line-numbers {
flex-grow: 0;
min-width: fit-content; /* prevent collapsing into nothing in truncated scraped examples */
overflow: initial;
Expand All @@ -558,7 +558,7 @@ ul.block, .block li {
color: var(--src-line-numbers-span-color);
}

.rustdoc .example-wrap > pre.src-line-numbers {
.rustdoc .example-wrap pre.src-line-numbers {
padding: 14px 0;
}
.src-line-numbers a, .src-line-numbers span {
Expand Down Expand Up @@ -706,7 +706,7 @@ h2.small-section-header > .anchor {
}

.main-heading a:hover,
.example-wrap > .rust a:hover,
.example-wrap .rust a:hover,
.all-items a:hover,
.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
.docblock-short a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/html/templates/source.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div class="example-wrap"> {# #}
<pre class="src-line-numbers">
{# https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr
Do not show "1 2 3 4 5 ..." in web search results. #}
<div data-nosnippet><pre class="src-line-numbers">
{% for line in lines.clone() %}
{% if embedded %}
<span>{{line|safe}}</span>
{%~ else %}
<a href="#{{line|safe}}" id="{{line|safe}}">{{line|safe}}</a>
{%~ endif %}
{% endfor %}
</pre> {# #}
</pre></div> {# #}
<pre class="rust"> {# #}
<code>
{% if needs_expansion %}
Expand Down

0 comments on commit f99b844

Please sign in to comment.