Skip to content

Add new version warning with link to docs v3 #3195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions resources/asciidoctor/lib/chunker/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require_relative 'find_related'
require_relative 'footnotes'
require_relative 'nav'
require_relative 'url_to_v3'

##
# HTML5 converter that chunks like docbook.
Expand Down Expand Up @@ -49,6 +50,7 @@ def convert_document(doc)
)
doc.attributes['next_section'] = find_next_in doc, 0
add_nav doc
add_url_to_v3 doc
yield
end

Expand Down Expand Up @@ -81,6 +83,11 @@ def add_nav(doc)
doc.blocks.append nav.footer
end

def add_url_to_v3(doc)
url_to_v3 = UrlToV3.new doc
doc.blocks.insert 0, url_to_v3.url
end

def correct_xref(node)
refid = node.attributes['refid']
return unless (ref = node.document.catalog[:refs][refid])
Expand Down Expand Up @@ -108,6 +115,8 @@ def form_section_into_page(doc, section, html)

def add_subdoc_sections(doc, subdoc, html)
nav = Nav.new subdoc
url_to_v3 = UrlToV3.new subdoc
subdoc << url_to_v3.url
subdoc << nav.header
subdoc << Asciidoctor::Block.new(subdoc, :pass, source: html)
subdoc << footnotes(doc, subdoc) if doc.footnotes?
Expand Down Expand Up @@ -143,6 +152,7 @@ def subdoc_attrs(doc, section)
attrs['subdoc'] = true # Mark the subdoc so we don't try and chunk it
attrs['title-separator'] = ''
attrs['canonical-url'] = section.attributes['canonical-url']
attrs['current-url'] = "#{section.id}.html"
attrs.merge! find_related(section)
attrs
end
Expand Down
61 changes: 61 additions & 0 deletions resources/asciidoctor/lib/chunker/url_to_v3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

module Chunker
# Add a warning to the page with a link to docs v3
class UrlToV3
attr_reader :url

def initialize(doc)
current_url = doc.attr('current-url')
outdir = doc.attr('outdir')
current_url ||= 'index.html'
m = mapping
# This only works in CI.
segments = outdir.sub('/tmp/docsbuild/target_repo/raw', '').split('/')
version = segments[-1] || 'unknown'
actual_url = get_actual_url(outdir, current_url)
new_url = if m.key?(actual_url)
m[actual_url]
else
'/docs'
end
render_warning(doc, version, new_url)
end

def mapping
file_path = File.expand_path('v3-mapping.json', __dir__)
JSON.parse(File.read(file_path)) if File.exist?(file_path)
end

def get_path_dir(outdir)
segments = outdir.sub('/tmp/docsbuild/target_repo/raw', '').split('/')
if segments.empty?
''
elsif segments.length > 1
segments[0...-1].join('/')
else
segments[0]
end
end

def get_actual_url(outdir, current_url)
get_path_dir(outdir) + '/*/' + current_url
end

def render_warning(doc, version, new_url)
if version == '8.18'
@url = Asciidoctor::Block.new(doc, :pass, source: <<~HTML)
<div id="url-to-v3" style="version-warning">
A newer version is available. For the latest information, see the <a href="https://www.elastic.co#{new_url}">current release documentation</a>
</div>
HTML
else
@url = Asciidoctor::Block.new(doc, :pass, source: <<~HTML)
<div id="url-to-v3" class="version-warning">
<bold>IMPORTANT</bold>: No additional bug fixes or documentation updates will be released for this version. For the latest information, see the <a href="https://www.elastic.co#{new_url}">current release documentation</a>
</div>
HTML
end
end
end
end
Loading