diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 98e59c73a3..95a1b3a9a6 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -88,6 +88,7 @@ @use 'pages/octave'; @use 'pages/openjdk'; @use 'pages/openlayers'; +@use 'pages/opentofu'; @use 'pages/perl'; @use 'pages/phalcon'; @use 'pages/phaser'; diff --git a/assets/stylesheets/pages/_opentofu.scss b/assets/stylesheets/pages/_opentofu.scss new file mode 100644 index 0000000000..c8c9106c0f --- /dev/null +++ b/assets/stylesheets/pages/_opentofu.scss @@ -0,0 +1,22 @@ +@use 'pages/simple'; + +._opentofu { + .theme-code-block figure { + margin-inline-start: 0; + } + + // "sr" means screen reader + .sr-only { + clip: rect(0,0,0,0); + border-width: 0; + height: 1px; + margin: -1px; + padding: 0; + position: absolute; + width: 1px + } + + .font-bold { + font-weight: var(--boldFontWeight); + } +} diff --git a/lib/docs/filters/opentofu/clean_html.rb b/lib/docs/filters/opentofu/clean_html.rb new file mode 100644 index 0000000000..7854d401f4 --- /dev/null +++ b/lib/docs/filters/opentofu/clean_html.rb @@ -0,0 +1,29 @@ +module Docs + class Opentofu + class CleanHtmlFilter < Filter + def fix_syntax_highlight + css('pre').each do |node| + node.remove_attribute('class') + node.remove_attribute('style') + node.css('.token-line').remove_attribute('style') + end + + css('[class*="buttonGroup_"]').remove + end + + # Some SVG icons are just too big and not needed. + def remove_svg_icons + css('[role="alert"] svg').remove + end + + def call + @doc = at_css("main article > .prose") + + remove_svg_icons + fix_syntax_highlight + + doc + end + end + end +end diff --git a/lib/docs/filters/opentofu/entries.rb b/lib/docs/filters/opentofu/entries.rb new file mode 100644 index 0000000000..88f2c1146a --- /dev/null +++ b/lib/docs/filters/opentofu/entries.rb @@ -0,0 +1,21 @@ +module Docs + class Opentofu + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('main article h1').content + end + + def get_type + segments = slug.split('/') + if segments[0..1] == ['language', 'functions'] + # We have too many functions (120+ out of ~300 pages) + "Function" + elsif segments.first == 'cli' + "CLI" + else + segments.first.titlecase + end + end + end + end +end diff --git a/lib/docs/scrapers/opentofu.rb b/lib/docs/scrapers/opentofu.rb new file mode 100644 index 0000000000..7719fc5879 --- /dev/null +++ b/lib/docs/scrapers/opentofu.rb @@ -0,0 +1,39 @@ +module Docs + class Opentofu < UrlScraper + self.name = 'Opentofu' + self.type = 'opentofu' + self.links = { + home: 'https://opentofu.org/', + } + + html_filters.push 'opentofu/entries', 'opentofu/clean_html' + + # Empty spans are used by Prism for code highlighting. + # Don't clean them + options[:clean_text] = false + options[:trailing_slash] = true + options[:attribution] = <<-HTML + Copyright © OpenTofu a Series of LF Projects, LLC and its contributors. Documentation materials incorporate content licensed under the MPL-2.0 license from other authors. + HTML + + def get_latest_version(opts) + contents = get_latest_github_release('opentofu', 'opentofu', opts) + contents.sub("v", "") + end + + version '1.11' do + self.release = '1.11.5' + self.base_url = "https://opentofu.org/docs/v#{self.version}/" + end + + version '1.10' do + self.release = '1.10.9' + self.base_url = "https://opentofu.org/docs/v#{self.version}/" + end + + version '1.9' do + self.release = '1.9.4' + self.base_url = "https://opentofu.org/docs/v#{self.version}/" + end + end +end diff --git a/public/icons/docs/opentofu/16.png b/public/icons/docs/opentofu/16.png new file mode 100644 index 0000000000..2c18bbedef Binary files /dev/null and b/public/icons/docs/opentofu/16.png differ diff --git a/public/icons/docs/opentofu/16@2x.png b/public/icons/docs/opentofu/16@2x.png new file mode 100644 index 0000000000..073cc5053a Binary files /dev/null and b/public/icons/docs/opentofu/16@2x.png differ diff --git a/public/icons/docs/opentofu/SOURCE b/public/icons/docs/opentofu/SOURCE new file mode 100644 index 0000000000..893b013fe2 --- /dev/null +++ b/public/icons/docs/opentofu/SOURCE @@ -0,0 +1,2 @@ +https://github.com/opentofu/opentofu.org/blob/main/static/favicons/favicon-16x16.png +https://github.com/opentofu/opentofu.org/blob/main/static/favicons/favicon-32x32.png