From 2340f1f2c5d95848ef6de73ae25143524489c134 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 24 Oct 2024 13:31:25 +0200 Subject: [PATCH 1/2] Fully support template files including template files This update enables markdown files in the template directory to include other files from the same directory, providing full support for Jinja templates. Previously, when a file included another file that was naturally ordered before it, the templates were already resolved due to in-place modifications. Now, rather than modifying template files directly and renaming them later, they are written to the target location instead. --- build-docs.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build-docs.rb b/build-docs.rb index 90fefe0..385bcc0 100755 --- a/build-docs.rb +++ b/build-docs.rb @@ -103,7 +103,15 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" # Get everything after last slash subfile_name = subfile.match(/([^\/]+$)/) if(is_template_dir) - %x(./parse_template.py -D product "#{product}" -D package "#{package}" -D icingaDocs true "#{full_docs_dir}" "#{subfile_path.gsub(/^doc\//, '')}") + subdir_name = File.basename(file) + new_subdir_name = subdir_name.gsub(/\.md.d$/, '') + + subdir = file.gsub(subdir_name, new_subdir_name) + FileUtils.mkdir_p(subdir) unless File.directory?(subdir) + + subfile = subfile.gsub(subdir_name, new_subdir_name) + + %x(./parse_template.py -o "#{subfile}" -D product "#{product}" -D package "#{package}" -D icingaDocs true "#{full_docs_dir}" "#{subfile_path.gsub(/^doc\//, '')}") content = File.read(subfile) # Adjust self references @@ -112,9 +120,7 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" content = content.gsub(/\[(.*)\]\((?!http|#)(.*)\)/, '[\1](../\2)') File.write(subfile, content) - # Adjust path, the directory will be renamed soon - subdir_name = File.basename(file) - subfile_path = subfile_path.gsub(subdir_name, subdir_name.gsub(/\.md.d$/, '')) + subfile_path = subfile_path.gsub(subdir_name, new_subdir_name) end header = titleize(subfile_name[1]) unless File.symlink?(subfile) @@ -138,7 +144,7 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" # Rename template directory to mimic template references newTemplateDirPath = file.gsub(/\.md.d$/, '') - File.rename(file, newTemplateDirPath) + FileUtils.rm_r(file) # Attempt to create a index file index_content = %x(./parse_template.py -o - -D index true #{full_docs_dir} #{template_path.gsub(/^doc\//, '')}) From 652bbdd8780890f3e35ebdf07f8b863e2bb5dd1d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 24 Oct 2024 13:33:11 +0200 Subject: [PATCH 2/2] Fix whitespaces --- build-docs.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build-docs.rb b/build-docs.rb index 385bcc0..28b81fe 100755 --- a/build-docs.rb +++ b/build-docs.rb @@ -45,7 +45,7 @@ def cleanup_and_clone(clone_target, git, ref, inject_central_docs = false) puts "Checking out #{ref}" %x(git --git-dir=#{clone_target}/.git --work-tree=#{clone_target} checkout #{ref} #{@git_options}) - if inject_central_docs + if inject_central_docs puts "Inject Central Docs" %x(git config --global user.email "info@icinga.com") %x(git config --global user.name "Icinga Docs Tool") @@ -97,7 +97,7 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" subdirectory = [] nav_item = titleize(filename[2]) unless File.symlink?(filepath) is_template_dir = !filename[3].nil? - + Dir.glob("#{file}/*.md", File::FNM_CASEFOLD).sort.each do |subfile| subfile_path = subfile.gsub(full_docs_dir + '/', project_docs_dir + '/') # Get everything after last slash @@ -122,7 +122,7 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" subfile_path = subfile_path.gsub(subdir_name, new_subdir_name) end - + header = titleize(subfile_name[1]) unless File.symlink?(subfile) subdirectory.push(header => subfile_path) if header end @@ -158,9 +158,9 @@ def build_page_index(full_docs_dir, project_docs_dir, package = "", product = "" subdirectory.unshift(filepath.gsub(/.md.d$/, '') + '/index.md') end end - + pages.push(nav_item => subdirectory) if nav_item - else + else header = titleize(filename[2]) unless File.symlink?(filepath) pages.push(header => filepath) if header end