mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
Added _SUMMARY.md missing files checking
This commit is contained in:
parent
5d4eeb24db
commit
3f4d5607b8
26
_lib/summary_checker.rb
Normal file
26
_lib/summary_checker.rb
Normal file
@ -0,0 +1,26 @@
|
||||
require 'rexml/xpath'
|
||||
require_relative './utils.rb'
|
||||
|
||||
module Docs
|
||||
class SummaryChecker
|
||||
def self.check(path)
|
||||
xml = Docs::Utils.md2xml(path)
|
||||
dir = File.dirname(path)
|
||||
is_ok = true
|
||||
missing_files = []
|
||||
|
||||
xml.elements.each("//a") do |link|
|
||||
href = link.attribute('href').to_s
|
||||
path = "#{dir}/#{href.gsub(/\.html$/, '.md')}"
|
||||
|
||||
if !File.file?(path)
|
||||
is_ok = false unless is_ok
|
||||
missing_files.push href
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
missing_files
|
||||
end
|
||||
end
|
||||
end
|
@ -4,9 +4,24 @@ task :build_toc do
|
||||
toc_file = ENV['dest'] || "#{src_dir}/HelpTOC.json"
|
||||
|
||||
load "#{src_dir}/_lib/toc_generator.rb"
|
||||
load "#{src_dir}/_lib/summary_checker.rb"
|
||||
|
||||
kramdown_config = YAML::load_file("#{src_dir}/_config.yml")['kramdown']
|
||||
toc = Docs::TocGenerator.extract("#{src_dir}/_SUMMARY.md", kramdown_config)
|
||||
missing_files = Docs::SummaryChecker.check("#{src_dir}/_SUMMARY.md")
|
||||
|
||||
puts "Checking _SUMMARY.md\n"
|
||||
|
||||
if missing_files.size > 0
|
||||
msg = ['Error, following files are missing:']
|
||||
missing_files.each do |file|
|
||||
msg.push "- #{file}"
|
||||
end
|
||||
|
||||
raise (msg.join("\n"))
|
||||
else
|
||||
puts "_SUMMARY.md is OK"
|
||||
end
|
||||
|
||||
res = File.write("#{toc_file}", toc.to_json)
|
||||
puts "TOC successfully created in #{toc_file}" if res
|
||||
|
Loading…
x
Reference in New Issue
Block a user