Module: JekyllAeo::Generators::UrlMap

Defined in:
lib/jekyll-aeo/generators/url_map.rb

Constant Summary collapse

COLUMN_HEADERS =
{
  "page_id" => "Page ID",
  "url" => "Url",
  "lang" => "Lang",
  "layout" => "Layout",
  "path" => "Path",
  "redirects" => "Redirects",
  "url_dotmd" => "Url DotMd",
  "excluded" => "Excluded",
  "dotmd_mode" => "DotMd Mode"
}.freeze
DEFAULT_COLUMNS =
%w[layout url url_dotmd dotmd_mode excluded path page_id lang redirects].freeze

Class Method Summary collapse

Class Method Details

.generate(site) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jekyll-aeo/generators/url_map.rb', line 22

def self.generate(site)
  config = JekyllAeo::Config.from_site(site)
  return if config["enabled"] == false

  url_map_config = config["url_map"] || {}
  return if url_map_config["enabled"] == false

  columns = url_map_config["columns"] || DEFAULT_COLUMNS
  items = collect_all_items(site, config, columns)
  sections = build_sections(items)
  markdown = build_markdown(sections, columns, url_map_config)

  root = project_root(site)
  output_file = File.join(root, url_map_config["output_filepath"] || "docs/Url-Map.md")
  unless File.expand_path(output_file).start_with?(File.expand_path(root))
    Jekyll.logger.error "AEO Url Map:", "output_filepath escapes project root — skipped"
    return
  end
  FileUtils.mkdir_p(File.dirname(output_file))
  File.write(output_file, markdown)
end