Skip to content

Commit 7e2f47e

Browse files
authored
Add support for switching books to asciidoctor (#606)
Adds support for switching individual books to Asciidoctor in `conf.yaml`. It then cuts the glossary over to Asciidoctor. This is what the changed docs look like: https://github.com/elastic/built-docs-nik/commit/dfafa93c3c483bf74c2091f832c916f1ccc842ba There are some line break changes which we can ignore. There is a change to the HTML - in a `<dd>` AsciiDoc added a `<p class="simpara">` tag. Asciidoctor does not. The rendered result looks ever so slightly better to me so I'm personally fine with it. The font size is `15px` instead of `16px` and the weight is `400` instead of `normal`.
1 parent 2461d32 commit 7e2f47e

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ contents:
8181
branches: [ master ]
8282
tags: Elastic Stack/Glossary
8383
subject: Elastic Stack
84+
asciidoctor: true
8485
sources:
8586
-
8687
repo: stack-docs

doc_build_aliases.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ alias docbldlsold='$GIT_HOME/docs/build_docs.pl --doc $GIT_HOME/logstash/docs/in
4141
# Stack
4242
alias docbldstk='$GIT_HOME/docs/build_docs.pl --doc $GIT_HOME/stack-docs/docs/index.asciidoc'
4343

44-
alias docbldgls='$GIT_HOME/docs/build_docs.pl --doc $GIT_HOME/stack-docs/docs/en/glossary/index.asciidoc'
44+
alias docbldgls='$GIT_HOME/docs/build_docs --asciidoctor --doc $GIT_HOME/stack-docs/docs/en/glossary/index.asciidoc'
4545

4646
alias docbldgs='$GIT_HOME/docs/build_docs.pl --doc $GIT_HOME/stack-docs/docs/en/getting-started/index.asciidoc --chunk 1'
4747

lib/ES/Book.pm

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ sub new {
114114

115115
my $lang = $args{lang} || 'en';
116116

117+
# be careful about true/false here so there are no surprises.
118+
# otherwise someone is bound to set `asciidoctor` to `false`
119+
# and perl will evaluate that to true....
120+
my $asciidoctor = 0;
121+
if (exists $args{asciidoctor}) {
122+
$asciidoctor = $args{asciidoctor};
123+
if ($asciidoctor eq 'true') {
124+
$asciidoctor = 1;
125+
} elsif ($asciidoctor eq 'false') {
126+
$asciidoctor = 0;
127+
} else {
128+
die 'asciidoctor must be true or false but was ' . $asciidoctor;
129+
}
130+
}
131+
117132
bless {
118133
title => $title,
119134
dir => $dir->subdir($prefix),
@@ -132,7 +147,7 @@ sub new {
132147
private => $args{private} || '',
133148
noindex => $args{noindex} || '',
134149
lang => $lang,
135-
asciidoctor => $args{asciidoctor} || 0,
150+
asciidoctor => $asciidoctor,
136151
}, $class;
137152
}
138153

@@ -153,7 +168,7 @@ sub build {
153168
$Opts->{procs},
154169
sub {
155170
my ( $pid, $error, $branch ) = @_;
156-
$self->source->mark_done( $title, $branch );
171+
$self->source->mark_done( $title, $branch, $self->asciidoctor );
157172
}
158173
);
159174

@@ -219,7 +234,7 @@ sub _build_book {
219234
if -e $branch_dir
220235
&& !$rebuild
221236
&& !$template->md5_changed($branch_dir)
222-
&& !$source->has_changed( $self->title, $branch );
237+
&& !$source->has_changed( $self->title, $branch, $self->asciidoctor );
223238

224239
my ( $checkout, $first_path ) = $source->prepare($branch);
225240

lib/ES/Repo.pm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ sub _reference_args {
132132
sub has_changed {
133133
#===================================
134134
my $self = shift;
135-
my ( $title, $branch, $path ) = @_;
135+
my ( $title, $branch, $path, $asciidoctor ) = @_;
136136

137137
my $old
138138
= $self->tracker->sha_for_branch( $self->name,
@@ -145,6 +145,7 @@ sub has_changed {
145145
or die "Remote branch <origin/$branch> doesn't exist "
146146
. "in repo "
147147
. $self->name;
148+
$new .= '|asciidoctor' if $asciidoctor;
148149

149150
return if $old eq $new;
150151

@@ -162,11 +163,12 @@ sub has_changed {
162163
sub mark_done {
163164
#===================================
164165
my $self = shift;
165-
my ( $title, $branch, $path ) = @_;
166+
my ( $title, $branch, $path, $asciidoctor ) = @_;
166167

167168
local $ENV{GIT_DIR} = $self->git_dir;
168169

169170
my $new = sha_for($branch);
171+
$new .= '|asciidoctor' if $asciidoctor;
170172
$self->tracker->set_sha_for_branch( $self->name,
171173
$self->_tracker_branch(@_), $new );
172174

@@ -296,7 +298,9 @@ sub all_repo_branches {
296298
my $shas = $repo->tracker->shas_for_repo( $repo->name );
297299

298300
for my $branch ( sort keys %$shas ) {
299-
my $log = run( qw(git log --oneline -1), $shas->{$branch} );
301+
my $sha = $shas->{$branch};
302+
$sha =~ s/\|.+$//; # Strip |asciidoctor if it is in the hash
303+
my $log = run( qw(git log --oneline -1), $sha );
300304
my ($msg) = ( $log =~ /^\w+\s+([^\n]+)/ );
301305
push @out, sprintf " %-35s %s %s", $branch,
302306
substr( $shas->{$branch}, 0, 8 ), $msg;

lib/ES/Source.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ sub has_changed {
5050
my $self = shift;
5151
my $title = shift;
5252
my $branch = shift;
53+
my $asciidoctor = shift;
5354
for my $source ( $self->_sources_for_branch($branch) ) {
5455
return 1
55-
if $source->{repo}->has_changed( $title, $branch, $source->{path} );
56+
if $source->{repo}->has_changed( $title, $branch, $source->{path}, $asciidoctor );
5657
}
5758
return;
5859
}
@@ -63,8 +64,9 @@ sub mark_done {
6364
my $self = shift;
6465
my $title = shift;
6566
my $branch = shift;
67+
my $asciidoctor = shift;
6668
for my $source ( $self->_sources_for_branch($branch) ) {
67-
$source->{repo}->mark_done( $title, $branch, $source->{path} );
69+
$source->{repo}->mark_done( $title, $branch, $source->{path}, $asciidoctor );
6870
}
6971
return;
7072
}

lib/ES/Util.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ sub build_chunked {
112112
file('resources/website_chunked.xsl')->absolute,
113113
"$dest/index.xml"
114114
);
115-
# unlink "$dest/index.xml";
115+
unlink "$dest/index.xml";
116116
1;
117117
} or do { $output = $@; $died = 1; };
118118
}

0 commit comments

Comments
 (0)