Skip to content

Commit c2c6312

Browse files
authored
Remove edit links form non-live versions (elastic#1533)
This removes the `edit` links from versions of books that aren't "live" because, for the most part, we don't want folks opening PRs against them. I mean, we'd *prefer* folks open PRs against the master branch, but that isn't really a simple thing to do when fixing docs so we're pretty happy with whatever. But we'd really prefer PRs to target live branches.
1 parent 0964fcb commit c2c6312

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

integtest/spec/all_books_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ def self.setup_example(repo, lang, hash)
617617
book.branches << 'nonlive'
618618
book.live_branches = ['master']
619619
end
620+
let(:repo) { @src.repo 'repo' }
620621
page_context 'the live branch', 'html/test/master/index.html' do
621622
it "doesn't contain the noindex flag" do
622623
expect(contents).not_to include(<<~HTML.strip)
@@ -631,7 +632,15 @@ def self.setup_example(repo, lang, hash)
631632
end
632633
end
633634
end
634-
page_context 'the dead branch', 'html/test/nonlive/index.html' do
635+
page_context "the live branch's chapter", 'html/test/master/chapter.html' do
636+
let(:edit_url) { "#{repo.root}/edit/master/index.asciidoc" }
637+
it 'contains an edit_me link' do
638+
expect(body).to include <<~HTML.strip
639+
<a href="#{edit_url}" class="edit_me" title="Edit this page on GitHub" rel="nofollow">edit</a>
640+
HTML
641+
end
642+
end
643+
page_context "the dead branch's index", 'html/test/nonlive/index.html' do
635644
it 'contains the noindex flag' do
636645
expect(contents).to include(<<~HTML.strip)
637646
<meta name="robots" content="noindex,nofollow" />
@@ -645,6 +654,13 @@ def self.setup_example(repo, lang, hash)
645654
end
646655
end
647656
end
657+
page_context "the dead branch's chapter",
658+
'html/test/nonlive/chapter.html' do
659+
let(:edit_url) { "#{repo.root}/edit/master/index.asciidoc" }
660+
it "doesn't contain an edit_me link" do
661+
expect(body).not_to include('class="edit_me"')
662+
end
663+
end
648664
end
649665

650666
context 'when run with --announce_preview' do

lib/ES/Book.pm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ sub _build_book {
265265
version => $branch,
266266
lang => $lang,
267267
edit_urls => $edit_urls,
268-
private => $self->private,
269-
noindex => $self->noindex($branch),
268+
private => $self->private( $branch ),
269+
noindex => $self->noindex( $branch ),
270270
multi => $self->is_multi_version,
271271
page_header => $self->_page_header($branch),
272272
section_title => $section_title,
@@ -290,8 +290,8 @@ sub _build_book {
290290
version => $branch,
291291
lang => $lang,
292292
edit_urls => $edit_urls,
293-
private => $self->private,
294-
noindex => $self->noindex($branch),
293+
private => $self->private( $branch ),
294+
noindex => $self->noindex( $branch ),
295295
chunk => $self->chunk,
296296
multi => $self->is_multi_version,
297297
page_header => $self->_page_header($branch),
@@ -448,6 +448,15 @@ sub noindex {
448448
return 1;
449449
}
450450

451+
#===================================
452+
sub private {
453+
#===================================
454+
my ( $self, $branch ) = @_;
455+
return 1 if $self->{private};
456+
return 0 if grep( /^$branch$/, @{ $self->{live_branches} } );
457+
return 1;
458+
}
459+
451460

452461
#===================================
453462
sub title { shift->{title} }
@@ -461,7 +470,6 @@ sub branches { shift->{branches} }
461470
sub branch_title { shift->{branch_titles}->{ shift() } }
462471
sub current { shift->{current} }
463472
sub is_multi_version { @{ shift->branches } > 1 }
464-
sub private { shift->{private} }
465473
sub tags { shift->{tags} }
466474
sub subject { shift->{subject} }
467475
sub source { shift->{source} }

0 commit comments

Comments
 (0)