blob: 577dea47c4c34b6fb2691dcd97402157fdead38f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/usr/bin/env ruby
#
# Generates the keyword lists for directives and variables used in nginx and
# prints them to stdout, ready to be copy & pasted into nginx.xml.
#
# SPDX-FileCopyrightText: 2023 Georg Gadinger <nilsding@nilsding.org>
# SPDX-License-Identifier: MIT
#
# Usage:
# % ./generate-nginx-lists.rb
#
# if you want to install the required dependencies provide `INSTALL_GEMS` in
# your ENV:
# % INSTALL_GEMS=1 ./generate-nginx-lists.rb
require "bundler/inline"
gemfile(ENV["INSTALL_GEMS"]) do
source "https://rubygems.org"
gem "nokogiri", "~> 1.14"
gem "faraday", "~> 2.7"
gem "builder", "~> 3.2"
end
def fetch_vars(url)
Faraday.get(url)
.then { Nokogiri::HTML.parse _1.body }
.css("div#content a[href]")
.map(&:text)
.reject { _1.end_with?("_") } # some vars are just a prefix, ignore those
.sort
.uniq
end
def build_xml_list(name, url: nil, items: [])
builder = Builder::XmlMarkup.new(indent: 2)
builder.comment! "see #{url} for a full list of #{name}"
builder.list(name:) do |b|
items.each do |item|
b.item item
end
end
end
{
directives: "https://nginx.org/en/docs/dirindex.html",
variables: "https://nginx.org/en/docs/varindex.html",
}.each do |name, url|
items = fetch_vars(url)
puts build_xml_list(name, url:, items:).gsub(/^/, ' ' * 4)
puts
end
|