|
17 | 17 | <% if @next.present? %><link rel="next" title="<%= h(@next_title)%>" href="<%= h(@next.id.to_s+"."+@book.config['htmlext']) %>" /><% end %> |
18 | 18 | <% if @prev.present? %><link rel="prev" title="<%= h(@prev_title)%>" href="<%= h(@prev.id.to_s+"."+@book.config['htmlext']) %>" /><% end %> |
19 | 19 | <meta name="generator" content="Re:VIEW" /> |
20 | | - <title><%= @title %> | <%=h @book.config.name_of("booktitle")%></title> |
| 20 | + <title><%= h(@title) %> | <%=h @book.config.name_of("booktitle")%></title> |
21 | 21 | </head> |
22 | 22 | <body<%= @body_ext %>> |
23 | 23 | <div class="book"> |
|
63 | 63 | </div> |
64 | 64 | <footer> |
65 | 65 | <% if @book.config["copyright"].present? %> |
66 | | - <p class="copyright"><%=h @config["copyright"] %></p> |
| 66 | + <p class="copyright"><%=h @book.config["copyright"] %></p> |
67 | 67 | <% end %> |
68 | 68 | </footer> |
69 | 69 | <script> |
70 | 70 | (function() { |
71 | | - var currentPage = location.pathname.split('/').pop().replace(/\.html$/, ''); |
| 71 | + function normalizePage(value) { |
| 72 | + var page = (value || '').split('#')[0].split('?')[0]; |
| 73 | + page = page.replace(/\.html$/, ''); |
| 74 | + if (page === '' || page === '.' || page === './' || page.charAt(page.length - 1) === '/') { |
| 75 | + return 'index'; |
| 76 | + } |
| 77 | + var last = page.split('/').pop(); |
| 78 | + return (last === '' || last === '.' || last === 'index') ? 'index' : last; |
| 79 | + } |
| 80 | + |
| 81 | + var currentPage = normalizePage(location.pathname); |
72 | 82 | var tocItems = document.querySelectorAll('.book-toc > li'); |
73 | 83 | var headings = document.querySelectorAll('.book-page h2'); |
74 | 84 |
|
75 | 85 | function matchPage(href) { |
76 | | - return href.replace(/\.html$/, '') === currentPage; |
| 86 | + return normalizePage(href) === currentPage; |
77 | 87 | } |
78 | 88 |
|
79 | 89 | // Fix TOP link to use relative directory path instead of index.html |
|
138 | 148 | var resultsDiv = document.getElementById('search-results'); |
139 | 149 | var searchIndex = null; |
140 | 150 |
|
141 | | - input.addEventListener('focus', function() { |
142 | | - if (searchIndex) return; |
143 | | - fetch('search-index.json') |
144 | | - .then(function(r) { return r.json(); }) |
145 | | - .then(function(data) { searchIndex = data; }) |
146 | | - .catch(function() { searchIndex = []; }); |
147 | | - }); |
148 | | - |
149 | | - input.addEventListener('input', function() { |
| 151 | + function runSearch() { |
150 | 152 | var q = input.value.trim().toLowerCase(); |
151 | 153 | if (!q || !searchIndex) { |
152 | 154 | resultsDiv.innerHTML = ''; |
|
172 | 174 | }).join(''); |
173 | 175 | } |
174 | 176 | resultsDiv.style.display = 'block'; |
| 177 | + } |
| 178 | + |
| 179 | + input.addEventListener('focus', function() { |
| 180 | + if (searchIndex) return; |
| 181 | + fetch('search-index.json') |
| 182 | + .then(function(r) { return r.json(); }) |
| 183 | + .then(function(data) { searchIndex = data; runSearch(); }) |
| 184 | + .catch(function() { searchIndex = []; }); |
175 | 185 | }); |
176 | 186 |
|
| 187 | + input.addEventListener('input', runSearch); |
| 188 | + |
177 | 189 | // Close results on outside click |
178 | 190 | document.addEventListener('click', function(e) { |
179 | 191 | if (!e.target.closest('.search-box')) { |
|
0 commit comments