File indexing completed on 2024-05-19 04:03:42
0001 #!/usr/bin/env ruby 0002 # 0003 # Generates the keyword lists for directives and variables used in nginx and 0004 # prints them to stdout, ready to be copy & pasted into nginx.xml. 0005 # 0006 # SPDX-FileCopyrightText: 2023 Georg Gadinger <nilsding@nilsding.org> 0007 # SPDX-License-Identifier: MIT 0008 # 0009 # Usage: 0010 # % ./generate-nginx-lists.rb 0011 # 0012 # if you want to install the required dependencies provide `INSTALL_GEMS` in 0013 # your ENV: 0014 # % INSTALL_GEMS=1 ./generate-nginx-lists.rb 0015 0016 require "bundler/inline" 0017 0018 gemfile(ENV["INSTALL_GEMS"]) do 0019 source "https://rubygems.org" 0020 0021 gem "nokogiri", "~> 1.14" 0022 gem "faraday", "~> 2.7" 0023 gem "builder", "~> 3.2" 0024 end 0025 0026 def fetch_vars(url) 0027 Faraday.get(url) 0028 .then { Nokogiri::HTML.parse _1.body } 0029 .css("div#content a[href]") 0030 .map(&:text) 0031 .reject { _1.end_with?("_") } # some vars are just a prefix, ignore those 0032 .sort 0033 .uniq 0034 end 0035 0036 def build_xml_list(name, url: nil, items: []) 0037 builder = Builder::XmlMarkup.new(indent: 2) 0038 0039 builder.comment! "see #{url} for a full list of #{name}" 0040 builder.list(name:) do |b| 0041 items.each do |item| 0042 b.item item 0043 end 0044 end 0045 end 0046 0047 { 0048 directives: "https://nginx.org/en/docs/dirindex.html", 0049 variables: "https://nginx.org/en/docs/varindex.html", 0050 }.each do |name, url| 0051 items = fetch_vars(url) 0052 0053 puts build_xml_list(name, url:, items:).gsub(/^/, ' ' * 4) 0054 puts 0055 end