mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Add New Glossary Page And Developer Search Feature
This commit adds the code necessary to generate a new en/developre-glossary page with entry pages in the en/glossary/ directory, e.g. en/glossary/51-percent-attack. The glossary page and the individual term pages feature a JavaScript search engine (no CGI) for just glossary terms. This search box has also been added to the following pages: * Developer Documentation (the index page) * Developer Guide * Developer Reference * Developer Examples The search box requires the following MIT-licensed libraries: * JQuery * JQuery UI * JQuery UI CSS stylesheet These allow our JS code to be almost trivially simple in js/devsearch.js This commit adds only code. Actual glossary entry data will be added in a subsequent commit.
This commit is contained in:
parent
c2bc8edff3
commit
037cd4553a
17 changed files with 609 additions and 11 deletions
|
@ -35,12 +35,37 @@ require 'yaml'
|
|||
|
||||
## Workaround for inconsistent relative directory
|
||||
path = File.expand_path(File.dirname(__FILE__)) + "/.."
|
||||
## Load terms from file
|
||||
## Load terms from file only if we haven't loaded them before
|
||||
site = context.registers[:site].config
|
||||
if !site.has_key?("crossref")
|
||||
site['crossref'] = YAML.load_file(path + "/_autocrossref.yaml")
|
||||
if !site.has_key?("crossref_loaded")
|
||||
|
||||
## Load refs from file and then downcase them all so we can
|
||||
## easily detect when we define xrefs more than once
|
||||
mixed_case_refs = YAML.load_file(path + "/_autocrossref.yaml")
|
||||
unvalidated_refs = Hash.new
|
||||
mixed_case_refs.each { |key, value|
|
||||
unvalidated_refs[key.to_s.downcase] = value.to_s.downcase
|
||||
}
|
||||
|
||||
if site.has_key?("crossref")
|
||||
## We already have refs loaded, so merge
|
||||
site['crossref'].merge!(unvalidated_refs) {
|
||||
|key, old_value, new_value|
|
||||
|
||||
if old_value != new_value
|
||||
abort("Error: autocrossref key '#{key}' wants to point to both '#{old_value}' and '#{new_value}'")
|
||||
end
|
||||
|
||||
new_value
|
||||
}
|
||||
else
|
||||
## We don't have refs loaded yet, so copy
|
||||
site['crossref'] = unvalidated_refs
|
||||
end
|
||||
site['crossref_loaded'] = true
|
||||
end
|
||||
|
||||
|
||||
## Sort terms by reverse length, so longest matches get linked
|
||||
## first (e.g. "block chain" before "block"). Otherwise short
|
||||
## terms would get linked first and there'd be nothing for long
|
||||
|
@ -76,7 +101,7 @@ require 'yaml'
|
|||
(?!\w) ## Don't match inside words
|
||||
(?!`) ## Don't match strings ending with a tic, unless the xref itself ends with a tic
|
||||
/xmi) {|s|
|
||||
if term[1] == "DO NOT AUTOCROSSREF"
|
||||
if term[1] == "do not autocrossref"
|
||||
s.gsub(/( |$)/, "<!--noref-->\\&")
|
||||
else
|
||||
"[#{s}][#{term[1]}]{:.auto-link}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue