Browse Source

fix(docs): Fix search - listing headless Pages & bad anchor links

Michael Bromley 7 years ago
parent
commit
bb6091ba4b

+ 7 - 1
docs/assets/scripts/search-widget.ts

@@ -95,7 +95,7 @@ export class SearchWidget {
             }
             }
             html += matches.map((result) => {
             html += matches.map((result) => {
                 const { section, title, heading, url } = result.original;
                 const { section, title, heading, url } = result.original;
-                const anchor = heading !== title ? '#' + heading.toLowerCase().replace(/\s/g, '-') : '';
+                const anchor = heading !== title ? '#' + this.headingToAnchor(heading) : '';
                 const inner = `<div class="title">${title}</div><div class="heading">${result.string}</div>`;
                 const inner = `<div class="title">${title}</div><div class="heading">${result.string}</div>`;
                 const selected = i === this.selectedIndex ? 'selected' : '';
                 const selected = i === this.selectedIndex ? 'selected' : '';
                 i++;
                 i++;
@@ -195,4 +195,10 @@ export class SearchWidget {
         }
         }
         return this.searchIndex;
         return this.searchIndex;
     }
     }
+
+    private headingToAnchor(heading: string): string {
+        return heading.toLowerCase()
+            .replace(/\s/g, '-')
+            .replace(/[:]/g, '');
+    }
 }
 }

+ 2 - 1
docs/layouts/searchindex/searchindex.html

@@ -1,11 +1,12 @@
 {
 {
 result :[
 result :[
-    {{- range .Site.Pages -}}
+    {{- range .Site.RegularPages -}}
         {{ $titles := findRE "<h(2|3).*?>(.|\n)*?</h(2|3)>" .Content -}}
         {{ $titles := findRE "<h(2|3).*?>(.|\n)*?</h(2|3)>" .Content -}}
         {{ $plain := apply $titles "plainify" "." -}}
         {{ $plain := apply $titles "plainify" "." -}}
         {{ $cleaned := $plain | complement (slice "constructor" "Signature" "Members") -}}
         {{ $cleaned := $plain | complement (slice "constructor" "Signature" "Members") -}}
         {{ $quoted := apply $cleaned "replaceRE" ".*" "'$0'" "." -}}
         {{ $quoted := apply $cleaned "replaceRE" ".*" "'$0'" "." -}}
         {{ $section := cond (in .Dir "configuration") "config" (cond (in .Dir "graphql-api") "gql" "guides") }}
         {{ $section := cond (in .Dir "configuration") "config" (cond (in .Dir "graphql-api") "gql" "guides") }}
+
         { section: '{{ $section }}', title: '{{ .Title }}', headings: [{{ delimit $quoted ", " }}], url: '{{ .RelPermalink }}' },
         { section: '{{ $section }}', title: '{{ .Title }}', headings: [{{ delimit $quoted ", " }}], url: '{{ .RelPermalink }}' },
     {{- end }}
     {{- end }}
 ]
 ]