Skip to content

Commit 564cbed

Browse files
authored
Only relativize links build with --all (#1308)
I don't particularly like building different books with `--all` vs `--doc`, but in this case it seems like it is the best solution.... We want to relativize links to `www.elastic.co` because it prevent linking off into "nowhere" when you use the docs in a air gapped network. And it makes it less likely that you'll accidentally get linked to production when browsing the docs preview. On the other hand, when you are building docs with `--doc` the URL space looks nothing like when you build all the docs so links into the docs that aren't already part of the book aren't going to resolve properly if we relativize them. So, this does what I don't really want to do but think is probably the right thing to do anyway: it only relativizes the links if you build all of the books and skips it if you build with `--doc`. Relates to #1300
1 parent 801bc01 commit 564cbed

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

build_docs.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ sub build_local {
115115
build_single( $index, $raw_dir, $dir, %$Opts,
116116
latest => $latest,
117117
alternatives => \@alternatives,
118+
relativize => 0,
118119
);
119120
}
120121
else {
121122
build_chunked( $index, $raw_dir, $dir, %$Opts,
122123
latest => $latest,
123124
alternatives => \@alternatives,
125+
relativize => 0,
124126
);
125127
}
126128

integtest/spec/all_books_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@ def self.override_edit_me(respect)
292292
end
293293
end
294294
end
295+
296+
context 'when there is a link to elastic.co' do
297+
convert_all_before_context do |src|
298+
repo = src.repo_with_index 'repo', <<~ASCIIDOC
299+
https://www.elastic.co/cloud/[link]
300+
ASCIIDOC
301+
book = src.book 'Test'
302+
book.source repo, 'index.asciidoc'
303+
end
304+
page_context 'raw/test/master/chapter.html' do
305+
it 'contains a relative link to www.elatic.co' do
306+
expect(body).to include(<<~HTML.strip)
307+
<a class="ulink" href="/cloud/" target="_top">link</a>
308+
HTML
309+
end
310+
end
311+
end
312+
295313
context 'for a book that uses {source_branch}' do
296314
convert_all_before_context do |src|
297315
repo = src.repo_with_index 'repo', <<~ASCIIDOC

integtest/spec/single_book_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,24 @@
273273
end
274274
end
275275
end
276+
context 'when there is a link to elastic.co' do
277+
convert_single_before_context do |src|
278+
src.write 'index.asciidoc', <<~ASCIIDOC
279+
= Title
280+
281+
[[chapter]]
282+
== Chapter
283+
https://www.elastic.co/cloud/[link]
284+
ASCIIDOC
285+
end
286+
page_context 'chapter.html' do
287+
it 'contains an absolute link to www.elatic.co' do
288+
expect(body).to include(<<~HTML.strip)
289+
<a class="ulink" href="https://www.elastic.co/cloud/" target="_top">link</a>
290+
HTML
291+
end
292+
end
293+
end
276294

277295
context 'regarding the xpack tag' do
278296
let(:edit_me) do

lib/ES/Book.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ sub _build_book {
287287
alternatives => $alternatives,
288288
branch => $branch,
289289
roots => $roots,
290+
relativize => 1,
290291
);
291292
}
292293
else {
@@ -312,6 +313,7 @@ sub _build_book {
312313
alternatives => $alternatives,
313314
branch => $branch,
314315
roots => $roots,
316+
relativize => 1,
315317
);
316318
}
317319
$checkout->rmtree;

lib/ES/Toc.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ sub write {
4242
root_dir => '', # Required but thrown on the floor with asciidoctor
4343
latest => 1, # Run all of our warnings
4444
private => 1, # Don't generate edit me urls
45-
branch => '' # TOCs don't have a branch but it is a required arg
45+
branch => '', # TOCs don't have a branch but it is a required arg
46+
relativize => 1,
4647
);
4748
$adoc_file->remove;
4849
}

lib/ES/Util.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ sub build_chunked {
5555
my $alternatives_summary = $raw_dest->file('alternatives_summary.json');
5656
my $branch = $opts{branch};
5757
my $roots = $opts{roots};
58+
my $relativize = $opts{relativize};
5859

5960
die "Can't find index [$index]" unless -f $index;
6061

@@ -121,7 +122,7 @@ sub build_chunked {
121122
'-a' => "alternative_language_report=$raw_dest/alternatives_report.json",
122123
'-a' => "alternative_language_summary=$alternatives_summary",
123124
) : (),
124-
'-a' => 'relativize-link=https://www.elastic.co/',
125+
$relativize ? ('-a' => 'relativize-link=https://www.elastic.co/') : (),
125126
roots_opts( $roots ),
126127
'--destination-dir=' . $raw_dest,
127128
docinfo($index),
@@ -230,6 +231,7 @@ sub build_single {
230231
my $alternatives_summary = $raw_dest->file('alternatives_summary.json');
231232
my $branch = $opts{branch};
232233
my $roots = $opts{roots};
234+
my $relativize = $opts{relativize};
233235

234236
die "Can't find index [$index]" unless -f $index;
235237

@@ -300,7 +302,7 @@ sub build_single {
300302
# Disable warning on missing attributes because we have
301303
# missing attributes!
302304
# '-a' => 'attribute-missing=warn',
303-
'-a' => 'relativize-link=https://www.elastic.co/',
305+
$relativize ? ('-a' => 'relativize-link=https://www.elastic.co/') : (),
304306
roots_opts( $roots ),
305307
'--destination-dir=' . $raw_dest,
306308
docinfo($index),

0 commit comments

Comments
 (0)