1+
2+ class SearchResultBody < Hyperloop ::Router ::Component
3+
4+ param :history
5+ param :location
6+ param :section
7+
8+
9+ def gotoslug slug , sectionname , pageid
10+
11+ NavigationStore . mutate . slug ""
12+ pagetogo = SiteStore . sections [ sectionname ] . pages [ pageid ]
13+ SiteStore . sections [ sectionname ] . set_current_page pagetogo
14+
15+ NavigationStore . mutate . accordionindex pageid
16+ NavigationStore . mutate . slug slug
17+
18+ history . push "/#{ sectionname } /#{ pagetogo [ :name ] } /#{ slug } "
19+
20+ end
21+
22+ def highlight ( text , search_string )
23+ keywords = search_string . strip . split ( " " ) . compact . uniq
24+ matcher = Regexp . new ( '(' + keywords . join ( "|" ) + ')' )
25+ highlighted = text . gsub ( matcher ) { |match | "<a class='ui teal label'>#{ match } </a>" }
26+ return highlighted
27+ end
28+
29+
30+
31+ render do
32+
33+ DIV ( class : 'searchresultcontent' ) do
34+
35+
36+
37+ SearchEngineStore . allresults . each_with_index do |result , index |
38+
39+ resulthtmlparagraph = ""
40+ resultpagename = ""
41+ resultheadingname = ""
42+ resultheadingslug = ""
43+ resultsectionname = ""
44+ resultpageid = ""
45+
46+ SiteStore . sections [ SearchEngineStore . previoussectionquery ] . pages . each_with_index do |page , index |
47+
48+ page [ :headings ] . each do |heading |
49+ if ( heading [ :id ] == result [ :ref ] )
50+ resultsectionname = heading [ :sectionname ]
51+ resultpageid = heading [ :pageid ]
52+ resultpagename = heading [ :pagename ]
53+ resultheadingname = heading [ :text ]
54+ resultheadingslug = heading [ :slug ]
55+ resulthtmlparagraph = heading [ :paragraphs ] . join ( ' ' )
56+ end
57+ end
58+
59+ end
60+
61+
62+ H2 ( class : 'ui header' ) do
63+ IMG ( src : 'dist/images/icons/gear.png' )
64+ DIV ( class : 'content' ) do
65+
66+ A ( ) do
67+ DIV ( dangerously_set_inner_HTML :
68+ { __html :
69+ "#{ index +1 } . In #{ resultpagename } : #{ highlight ( resultheadingname , result [ :matchingwords ] ) } <a class='ui black label'>#{ result [ :nbresults ] } results</a>"
70+ } )
71+
72+ end . on ( :click ) { gotoslug ( resultheadingslug , resultsectionname , resultpageid ) }
73+
74+ # A(class:'ui black label') {"#{result[:nbresults]} results" }
75+
76+ DIV ( class : 'sub header' ) do
77+ "_______________"
78+ end
79+
80+ end
81+
82+ end
83+
84+ DIV ( dangerously_set_inner_HTML : { __html : highlight ( resulthtmlparagraph , result [ :matchingwords ] ) } )
85+
86+ BR ( )
87+ end
88+
89+ end
90+
91+
92+ end
93+
94+
95+
96+
97+ end
0 commit comments