sub build_chunked()

in lib/ES/Util.pm [34:140]


sub build_chunked {
#===================================
    my ( $index, $raw_dest, $dest, %opts ) = @_;

    my $single    = 0;
    my $chunk     = $opts{chunk}         || 0;
    my $version   = $opts{version}       || '';
    my $multi     = $opts{multi}         || 0;
    my $lenient   = $opts{lenient}       || '';
    my $lang      = $opts{lang}          || 'en';
    my $edit_urls = $opts{edit_urls};
    my $section   = $opts{section_title} || '';
    my $subject   = $opts{subject}       || '';
    my $private   = $opts{private}       || '';
    my $resources = $opts{resource}      || [];
    my $noindex   = $opts{noindex}       || '';
    my $page_header = custom_header($index) || $opts{page_header} || '';
    my $latest    = $opts{latest};
    my $respect_edit_url_overrides = $opts{respect_edit_url_overrides} || '';
    my $alternatives = $opts{alternatives} || [];
    my $alternatives_summary = $raw_dest->file('alternatives_summary.json');
    my $branch = $opts{branch};
    my $roots = $opts{roots};
    my $relativize = $opts{relativize};

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

    $dest->rmtree;
    $dest->mkpath;
    $raw_dest->rmtree;
    $raw_dest->mkpath;

    my ( $output, $died );

    my $chunks_path = dir("$raw_dest/.chunked");
    $chunks_path->mkpath;
    # Emulate asciidoc_dir because we use it to find shared asciidoc files
    # but asciidoctor doesn't support it.
    my $asciidoc_dir = dir('resources/asciidoc-8.6.8/')->absolute;
    # We use the admonishment images from asciidoc so add it as a resource
    # so we can find them
    push @$resources, $asciidoc_dir;
    eval {
        $output = run(
            'asciidoctor', '-v', '--trace',
            '-r' => dir('resources/asciidoctor/lib/extensions.rb')->absolute,
            '-b' => 'html5',
            '-d' => 'book',
            '-a' => 'showcomments=1',
            '-a' => "lang=$lang",
            '-a' => "source_branch=$branch",
            # Use ` to delimit monospaced literals because our docs
            # expect that
            '-a' => 'compat-mode=legacy',
            !$private ? () : ( '-a' => "private_edit_urls" ),
            !$edit_urls ? () : ( '-a' => "edit_urls=" .
                edit_urls_for_asciidoctor($edit_urls) ),
            # Disable warning on missing attributes because we have
            # missing attributes!
            # '-a' => 'attribute-missing=warn',
            '-a' => 'asciidoc-dir=' . $asciidoc_dir,
            '-a' => 'resources=' . join(',', @$resources),
            $latest ? () : ('-a' => "migration-warnings=false"),
            $respect_edit_url_overrides ? ('-a' => "respect_edit_url_overrides=true") : (),
            @{ $alternatives } ? (
                '-a' => _format_alternatives($alternatives),
                '-a' => "alternative_language_report=$raw_dest/alternatives_report.json",
                '-a' => "alternative_language_summary=$alternatives_summary",
            ) : (),
            $relativize ? ('-a' => 'relativize-link=https://www.elastic.co/') : (),
            roots_opts( $roots ),
            # Turn off style options because we'll provide our own
            '-a' => 'stylesheet!',
            '-a' => 'icons!',
            # Turn off asciidoctor's default footer because we make our own
            '-a' => 'nofooter',
            # Pass chunking down
            '-a' => 'chunk_level=' . ( $chunk + 1 ),
            # Render the table of contents
            '-a' => 'toc',
            # Lock the destination file name to one we expect
            '--out-file' => 'index.html',
            # Asciidoctor doesn't pass the destination directory down to
            # the converter so we do so here explicitly
            '-a' => 'outdir=' . $raw_dest,
            # Add some metadata
            '-a' => 'dc.type=Learn/Docs/' . $section,
            '-a' => 'dc.subject=' . $subject,
            '-a' => 'dc.identifier=' . $version,
            $multi ? ( '-a' => "title-extra= [$version]" ) : (),
            $noindex ? ('-a' => 'noindex') : (),
            $page_header ? ('-a' => "page-header=$page_header") : (),
            '--destination-dir=' . $raw_dest,
            docinfo($index),
            $index
        );
        1;
    } or do { $output = $@; $died = 1; };
    _check_build_error( $output, $died, $lenient );

    # Extract the TOC from the index.html page *before* we (potentially) replace
    # the TOC on the index.html page with a custom title page.
    extract_toc_from_index( $raw_dest );

    _customize_title_page( $index, $raw_dest->file('index.html'), $single );
    finish_build( $index->parent, $raw_dest, $dest, $lang, 0 );
}