From aaf28e581b5c32285617198d9bef17256fcf1a5b Mon Sep 17 00:00:00 2001 From: Whyme Lyu Date: Wed, 1 Apr 2026 15:30:47 +0800 Subject: [PATCH] New docs: Opentofu --- assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_opentofu.scss | 22 +++++++++++++ lib/docs/filters/opentofu/clean_html.rb | 29 ++++++++++++++++++ lib/docs/filters/opentofu/entries.rb | 21 +++++++++++++ lib/docs/scrapers/opentofu.rb | 39 ++++++++++++++++++++++++ public/icons/docs/opentofu/16.png | Bin 0 -> 632 bytes public/icons/docs/opentofu/16@2x.png | Bin 0 -> 1125 bytes public/icons/docs/opentofu/SOURCE | 2 ++ 8 files changed, 114 insertions(+) create mode 100644 assets/stylesheets/pages/_opentofu.scss create mode 100644 lib/docs/filters/opentofu/clean_html.rb create mode 100644 lib/docs/filters/opentofu/entries.rb create mode 100644 lib/docs/scrapers/opentofu.rb create mode 100644 public/icons/docs/opentofu/16.png create mode 100644 public/icons/docs/opentofu/16@2x.png create mode 100644 public/icons/docs/opentofu/SOURCE 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 0000000000000000000000000000000000000000..2c18bbedefe1e1df4a8734a707ba8271360132e4 GIT binary patch literal 632 zcmV-;0*C#HP)?##~W`mxS+X2fA#cUS*#VCJ54e&;{Kxj+RG8Xyl<8aj*#hfNUe0N(v?As3)E{O-AIPYTU<0rIUj9O58;eFTDeL z!z6ElELTB4DrpVCurIio2`Yqa0>DXKNvA&DW&&0~TFC|_qoViuOMQXZ*qVf~WsxHd zsRwbIW2RWHx-f#Q0oi8r88N~p5LS`{0~D&Istb>+3;u0HyAz@T~7h4i1*1@3o~J9?OefG>M9cbj5AFi zla>CEzq$_!^Ak`Pm0&IlUwAHFfof*(rDpsBGQP8~l8h0cO8 z$4i;W$jJEv-NH(J z$JCGztqs)`kD;euhCL0lgaO6j0Kcya)~{OwMq$W6s*&H_gJ>ihYeX4I2?=l8vRVk| zIqYUA%^4t2TDE!n(aa0*Y{~;>n+Oho0q8qkrK%f+HZnCwVM zDOX~5(nFpOeRZT?t7yG;Q~b*OwbmO3WLa)u41%-=P`GK)nJlzjy$P;g7eU?rqqq~X zmRR)mxlsmae~w2we#8yC@?n=0qI@sLS)flxtHO&bD#ZpA?u^EWyC>3Ko;qe!Lg~a3 zk9N$#bD*y+XbZVkDx&zz7zsa&Le=K&Lb&z%tr&61w%$3WkL^l+k!CL_31H*Ywr-fq zA6!v6zn?Ff$MYTcEcbF9vFwn#Nn^3(VH_&)8qZs51S zmyZ&*tFBA*j1g{AA0|0!i5n~UEFD;BYSQ{Z$ivO3J02GW#_{0U+u7b?l+)6uS?bAo rxGTgZR%u3fQa}e;yE@McA2VJ7Dap0=$VUF#00000NkvXXu0mjfO>Y0* literal 0 HcmV?d00001 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