|
1 | 1 | module Docs |
2 | 2 | class Terraform |
3 | 3 | class EntriesFilter < Docs::EntriesFilter |
4 | | - |
5 | | - # Some providers have non-trivial mappings between the directory they live in and their name |
6 | | - # Anything *not* in this list will be capitalized instead. |
7 | | - PROVIDER_NAME_MAP = { |
8 | | - 'aws' => 'AWS', |
9 | | - 'azure' => 'Azure (Legacy)', |
10 | | - 'azurerm' => 'Azure', |
11 | | - 'centurylinkcloud' => 'CenturyLinkCloud', |
12 | | - 'cloudscale' => 'CloudScale.ch', |
13 | | - 'cloudstack' => 'CloudStack', |
14 | | - 'dme' => 'DNSMadeEasy', |
15 | | - 'dns' => 'DNS', |
16 | | - 'dnsimple' => 'DNSimple', |
17 | | - 'do' => 'DigitalOcean', |
18 | | - 'github' => 'GitHub', |
19 | | - 'google' => 'Google Cloud', |
20 | | - 'http' => 'HTTP', |
21 | | - 'mysql' => 'MySQL', |
22 | | - 'newrelic' => 'New Relic', |
23 | | - 'oneandone' => '1&1', |
24 | | - 'opentelekomcloud' => 'OpenTelekomCloud', |
25 | | - 'opsgenie' => 'OpsGenie', |
26 | | - 'opc' => 'Oracle Public Cloud', |
27 | | - 'oraclepaas' => 'Oracle Cloud Platform', |
28 | | - 'ovh' => 'OVH', |
29 | | - 'pagerduty' => 'PagerDuty', |
30 | | - 'panos' => 'Palo Alto Networks', |
31 | | - 'postgresql' => 'PostgreSQL', |
32 | | - 'powerdns' => 'PowerDNS', |
33 | | - 'profitbricks' => 'ProfitBricks', |
34 | | - 'rabbitmq' => 'RabbitMQ', |
35 | | - 'softlayer' => 'SoftLayer', |
36 | | - 'statuscake' => 'StatusCake', |
37 | | - 'tls' => 'TLS', |
38 | | - 'ultradns' => 'UltraDNS', |
39 | | - 'vcd' => 'VMware vCloud Director', |
40 | | - 'nsxt' => 'VMware NSX-T', |
41 | | - 'vsphere' => 'VMware vSphere', |
42 | | - } |
43 | | - |
44 | | - # Some providers have a lot (> 100) entries, which makes browsing them unwieldy. |
45 | | - # Any present in the list below will have an extra set of types added, breaking the pages out into the different |
46 | | - # products they offer. |
47 | | - LARGE_PROVIDERS = { |
48 | | - "aws" => true, |
49 | | - "azurerm" => true, |
50 | | - "google" => true, |
| 4 | + # Fallback types for pages whose sidebar navigation cannot be interpreted, |
| 5 | + # keyed by the first segment of the slug. |
| 6 | + SECTION_NAME_MAP = { |
| 7 | + 'cdktf' => 'CDK for Terraform', |
| 8 | + 'cli' => 'Terraform CLI', |
| 9 | + 'docs' => 'Documentation', |
| 10 | + 'intro' => 'Intro to Terraform', |
| 11 | + 'internals' => 'Internals', |
| 12 | + 'language' => 'Configuration Language', |
| 13 | + 'mcp-server' => 'MCP Server', |
| 14 | + 'migrate' => 'Migrate', |
| 15 | + 'plugin' => 'Plugin Development', |
| 16 | + 'policy' => 'Policy Enforcement', |
| 17 | + 'registry' => 'Registry Publishing', |
| 18 | + 'tutorials' => 'Tutorials', |
51 | 19 | } |
52 | 20 |
|
53 | | - |
54 | 21 | def get_name |
55 | | - name ||= at_css('#inner h1').content |
56 | | - name.remove! "» " |
57 | | - name.remove! "Data Source: " |
58 | | - name |
| 22 | + at_css('#main h1').content.strip |
59 | 23 | end |
60 | 24 |
|
61 | 25 | def get_type |
62 | | - category, subcategory, subfolder, page = *slug.split('/') |
63 | | - provider = page ? subcategory : category |
64 | | - nice_provider = PROVIDER_NAME_MAP[provider] || provider.capitalize |
| 26 | + # The sidebar heading names the section the page belongs to, e.g. "Terraform CLI". |
| 27 | + section = at_css('#sidebar-label').try(:content).try(:strip) |
| 28 | + root = slug.split('/').first |
| 29 | + section = SECTION_NAME_MAP[root] if section.blank? |
| 30 | + return 'Terraform' if section.blank? |
| 31 | + |
| 32 | + # Tutorials reuse the same section names as the reference docs |
| 33 | + # (e.g. "CLI"), so keep the two apart. |
| 34 | + return "Tutorials: #{section}" if root == 'tutorials' && section != 'Tutorials' |
| 35 | + |
| 36 | + group = sidebar_group |
| 37 | + group.present? ? "#{section}: #{group}" : section |
| 38 | + end |
| 39 | + |
| 40 | + private |
| 41 | + |
| 42 | + # Returns the label of the outermost collapsible group containing the |
| 43 | + # current page in the sidebar, e.g. "Provisioning Infrastructure". |
| 44 | + def sidebar_group |
| 45 | + nav = at_css('#sidebar-nav') |
| 46 | + return if nav.nil? |
| 47 | + |
| 48 | + node = nav.at_css('a[aria-current="page"]') |
| 49 | + label = nil |
65 | 50 |
|
66 | | - if LARGE_PROVIDERS[provider] |
67 | | - category_node = at_css('ul > li > ul > li.active') |
68 | | - parent_node = category_node.parent.previous_element if category_node |
69 | | - nice_provider = nice_provider + ": #{parent_node.content}" if category_node |
| 51 | + while node && node != nav |
| 52 | + node = node.parent |
| 53 | + next unless node && node.name == 'li' |
| 54 | + button = node.at_css('> button > span') |
| 55 | + label = button.content.strip if button |
70 | 56 | end |
71 | 57 |
|
72 | | - nice_provider |
| 58 | + label |
73 | 59 | end |
74 | 60 | end |
75 | 61 | end |
|
0 commit comments