mirror of https://github.com/kiwix/libkiwix.git
Introduce a results intermediate object in the template rendering.
Url in href must not be html encoded. As we already url encode the path, it is ok to have `'` in the url.
This commit is contained in:
parent
f0dd34b6db
commit
aad95e3413
|
@ -164,28 +164,28 @@ kainjow::mustache::data buildPagination(
|
||||||
std::string SearchRenderer::getHtml()
|
std::string SearchRenderer::getHtml()
|
||||||
{
|
{
|
||||||
// Build the results list
|
// Build the results list
|
||||||
kainjow::mustache::data results{kainjow::mustache::data::type::list};
|
kainjow::mustache::data items{kainjow::mustache::data::type::list};
|
||||||
|
|
||||||
for (auto it = m_srs.begin(); it != m_srs.end(); it++) {
|
for (auto it = m_srs.begin(); it != m_srs.end(); it++) {
|
||||||
kainjow::mustache::data result;
|
kainjow::mustache::data result;
|
||||||
result.set("title", it.getTitle());
|
|
||||||
result.set("url", it.getPath());
|
|
||||||
result.set("snippet", it.getSnippet());
|
|
||||||
std::string zim_id(it.getZimId());
|
std::string zim_id(it.getZimId());
|
||||||
result.set("resultContentId", mp_nameMapper->getNameForId(zim_id));
|
result.set("title", it.getTitle());
|
||||||
if (!mp_library) {
|
result.set("absolutePath", protocolPrefix + urlEncode(mp_nameMapper->getNameForId(zim_id), true) + "/" + urlEncode(it.getPath()));
|
||||||
result.set("bookTitle", kainjow::mustache::data(false));
|
result.set("snippet", it.getSnippet());
|
||||||
} else {
|
if (mp_library) {
|
||||||
result.set("bookTitle", mp_library->getBookById(zim_id).getTitle());
|
result.set("bookTitle", mp_library->getBookById(zim_id).getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.getWordCount() >= 0) {
|
if (it.getWordCount() >= 0) {
|
||||||
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push_back(result);
|
items.push_back(result);
|
||||||
}
|
}
|
||||||
|
kainjow::mustache::data results;
|
||||||
|
results.set("items", items);
|
||||||
|
results.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
||||||
|
results.set("hasResults", estimatedResultCount != 0);
|
||||||
|
results.set("start", kiwix::beautifyInteger(resultStart+1));
|
||||||
|
results.set("end", kiwix::beautifyInteger(min(resultStart+pageLength, estimatedResultCount)));
|
||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
auto pagination = buildPagination(
|
auto pagination = buildPagination(
|
||||||
|
@ -194,26 +194,17 @@ std::string SearchRenderer::getHtml()
|
||||||
resultStart
|
resultStart
|
||||||
);
|
);
|
||||||
|
|
||||||
auto resultEnd = min(resultStart+pageLength, estimatedResultCount);
|
|
||||||
|
|
||||||
kainjow::mustache::data query = buildQueryData(
|
kainjow::mustache::data query = buildQueryData(
|
||||||
searchProtocolPrefix,
|
searchProtocolPrefix,
|
||||||
searchPattern,
|
searchPattern,
|
||||||
searchContent
|
searchContent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string template_str = RESOURCE::templates::search_result_html;
|
std::string template_str = RESOURCE::templates::search_result_html;
|
||||||
kainjow::mustache::mustache tmpl(template_str);
|
kainjow::mustache::mustache tmpl(template_str);
|
||||||
|
|
||||||
kainjow::mustache::data allData;
|
kainjow::mustache::data allData;
|
||||||
allData.set("results", results);
|
allData.set("results", results);
|
||||||
allData.set("hasResults", estimatedResultCount != 0);
|
|
||||||
allData.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
|
||||||
allData.set("resultStart", to_string(resultStart + 1));
|
|
||||||
allData.set("resultEnd", to_string(resultEnd));
|
|
||||||
allData.set("protocolPrefix", this->protocolPrefix);
|
|
||||||
allData.set("pagination", pagination);
|
allData.set("pagination", pagination);
|
||||||
allData.set("query", query);
|
allData.set("query", query);
|
||||||
|
|
||||||
|
|
|
@ -106,26 +106,26 @@
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{#hasResults}}
|
{{#results.hasResults}}
|
||||||
Results
|
Results
|
||||||
<b>
|
<b>
|
||||||
{{resultStart}}-{{resultEnd}}
|
{{results.start}}-{{results.end}}
|
||||||
</b> of <b>
|
</b> of <b>
|
||||||
{{count}}
|
{{results.count}}
|
||||||
</b> for <b>
|
</b> for <b>
|
||||||
"{{{query.pattern}}}"
|
"{{{query.pattern}}}"
|
||||||
</b>
|
</b>
|
||||||
{{/hasResults}}
|
{{/results.hasResults}}
|
||||||
{{^hasResults}}
|
{{^results.hasResults}}
|
||||||
No results were found for <b>"{{{query.pattern}}}"</b>
|
No results were found for <b>"{{{query.pattern}}}"</b>
|
||||||
{{/hasResults}}
|
{{/results.hasResults}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
<ul>
|
<ul>
|
||||||
{{#results}}
|
{{#results.items}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{protocolPrefix}}{{resultContentId}}/{{url}}">
|
<a href="{{{absolutePath}}}">
|
||||||
{{title}}
|
{{title}}
|
||||||
</a>
|
</a>
|
||||||
{{#snippet}}
|
{{#snippet}}
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
<div class="informations">{{wordCount}} words</div>
|
<div class="informations">{{wordCount}} words</div>
|
||||||
{{/wordCount}}
|
{{/wordCount}}
|
||||||
</li>
|
</li>
|
||||||
{{/results}}
|
{{/results.items}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1158,7 +1158,7 @@ R"SEARCHRESULT(
|
||||||
)SEARCHRESULT",
|
)SEARCHRESULT",
|
||||||
|
|
||||||
R"SEARCHRESULT(
|
R"SEARCHRESULT(
|
||||||
<a href="/ROOT/zimfile/A/Catchin'_Some_Rays:_The_Music_of_Ray_Charles">
|
<a href="/ROOT/zimfile/A/Catchin'_Some_Rays:_The_Music_of_Ray_Charles">
|
||||||
Catchin' Some Rays: The Music of Ray Charles
|
Catchin' Some Rays: The Music of Ray Charles
|
||||||
</a>
|
</a>
|
||||||
<cite>...<b>jazz</b> singer Roseanna Vitro, released in August 1997 on the Telarc <b>Jazz</b> label. Catchin' Some Rays: The Music of Ray Charles Studio album by Roseanna Vitro Released August 1997 Recorded March 26, 1997 at Sound on Sound, NYC April 4,1997 at Quad Recording Studios, NYC Genre Vocal <b>jazz</b> Length 61:00 Label Telarc <b>Jazz</b> CD-83419 Producer Paul Wickliffe Roseanna Vitro chronology Passion Dance (1996) Catchin' Some Rays: The Music of Ray Charles (1997) The Time of My Life: Roseanna Vitro Sings the Songs of......</cite>
|
<cite>...<b>jazz</b> singer Roseanna Vitro, released in August 1997 on the Telarc <b>Jazz</b> label. Catchin' Some Rays: The Music of Ray Charles Studio album by Roseanna Vitro Released August 1997 Recorded March 26, 1997 at Sound on Sound, NYC April 4,1997 at Quad Recording Studios, NYC Genre Vocal <b>jazz</b> Length 61:00 Label Telarc <b>Jazz</b> CD-83419 Producer Paul Wickliffe Roseanna Vitro chronology Passion Dance (1996) Catchin' Some Rays: The Music of Ray Charles (1997) The Time of My Life: Roseanna Vitro Sings the Songs of......</cite>
|
||||||
|
@ -1167,7 +1167,7 @@ R"SEARCHRESULT(
|
||||||
)SEARCHRESULT",
|
)SEARCHRESULT",
|
||||||
|
|
||||||
R"SEARCHRESULT(
|
R"SEARCHRESULT(
|
||||||
<a href="/ROOT/zimfile/A/That's_What_I_Say:_John_Scofield_Plays_the_Music_of_Ray_Charles">
|
<a href="/ROOT/zimfile/A/That's_What_I_Say:_John_Scofield_Plays_the_Music_of_Ray_Charles">
|
||||||
That's What I Say: John Scofield Plays the Music of Ray Charles
|
That's What I Say: John Scofield Plays the Music of Ray Charles
|
||||||
</a>
|
</a>
|
||||||
<cite>That's What I Say: John Scofield Plays the Music of Ray Charles Studio album by John Scofield Released June 7, 2005 (2005-06-07) Recorded December 2004 Studio Avatar Studios, New York City Genre <b>Jazz</b> Length 65:21 Label Verve Producer Steve Jordan John Scofield chronology EnRoute: John Scofield Trio LIVE (2004) That's What I Say: John Scofield Plays the Music of Ray Charles (2005) Out Louder (2006) Professional ratings Review scores Source Rating Allmusic All About <b>Jazz</b> All About <b>Jazz</b>...</cite>
|
<cite>That's What I Say: John Scofield Plays the Music of Ray Charles Studio album by John Scofield Released June 7, 2005 (2005-06-07) Recorded December 2004 Studio Avatar Studios, New York City Genre <b>Jazz</b> Length 65:21 Label Verve Producer Steve Jordan John Scofield chronology EnRoute: John Scofield Trio LIVE (2004) That's What I Say: John Scofield Plays the Music of Ray Charles (2005) Out Louder (2006) Professional ratings Review scores Source Rating Allmusic All About <b>Jazz</b> All About <b>Jazz</b>...</cite>
|
||||||
|
@ -1437,7 +1437,7 @@ R"SEARCHRESULT(
|
||||||
)SEARCHRESULT",
|
)SEARCHRESULT",
|
||||||
|
|
||||||
R"SEARCHRESULT(
|
R"SEARCHRESULT(
|
||||||
<a href="/ROOT/zimfile/A/Don't_Let_the_Sun_Catch_You_Cryin'">
|
<a href="/ROOT/zimfile/A/Don't_Let_the_Sun_Catch_You_Cryin'">
|
||||||
Don't Let the Sun Catch You Cryin'
|
Don't Let the Sun Catch You Cryin'
|
||||||
</a>
|
</a>
|
||||||
<cite>...R&B Sides" and No. 95 on the Billboard Hot 100. It was also recorded by Jackie DeShannon on her 1965 album This is Jackie De Shannon, Paul McCartney on his 1990 live album Tripping the Live Fantastic, Jex Saarelaht and Kate Ceberano on their album Open the Door - Live at Mietta's (1992) and <b>jazz</b> singer Roseanna Vitro on her 1997 album Catchin’ Some Rays: The Music of Ray Charles. Karin Krog and Steve Kuhn include it on their 2005 album, Together Again. Steve Alaimo released a version in 1963...</cite>
|
<cite>...R&B Sides" and No. 95 on the Billboard Hot 100. It was also recorded by Jackie DeShannon on her 1965 album This is Jackie De Shannon, Paul McCartney on his 1990 live album Tripping the Live Fantastic, Jex Saarelaht and Kate Ceberano on their album Open the Door - Live at Mietta's (1992) and <b>jazz</b> singer Roseanna Vitro on her 1997 album Catchin’ Some Rays: The Music of Ray Charles. Karin Krog and Steve Kuhn include it on their 2005 album, Together Again. Steve Alaimo released a version in 1963...</cite>
|
||||||
|
@ -1446,7 +1446,7 @@ R"SEARCHRESULT(
|
||||||
)SEARCHRESULT",
|
)SEARCHRESULT",
|
||||||
|
|
||||||
R"SEARCHRESULT(
|
R"SEARCHRESULT(
|
||||||
<a href="/ROOT/zimfile/A/I_Don't_Need_No_Doctor">
|
<a href="/ROOT/zimfile/A/I_Don't_Need_No_Doctor">
|
||||||
I Don't Need No Doctor
|
I Don't Need No Doctor
|
||||||
</a>
|
</a>
|
||||||
<cite>...<b>jazz</b> guitar player John Scofield recorded a version for his album That's What I Say: John Scofield Plays the Music of Ray Charles in 2005, featuring the blues guitarist John Mayer on additional guitar and vocals. Mayer covered the song again with his band during his tour in summer 2007. A recorded live version from a Los Angeles show during that tour is available on Mayer's CD/DVD release Where the Light Is. A Ray Charles tribute album also provided the impetus for <b>jazz</b> singer Roseanna Vitro's......</cite>
|
<cite>...<b>jazz</b> guitar player John Scofield recorded a version for his album That's What I Say: John Scofield Plays the Music of Ray Charles in 2005, featuring the blues guitarist John Mayer on additional guitar and vocals. Mayer covered the song again with his band during his tour in summer 2007. A recorded live version from a Los Angeles show during that tour is available on Mayer's CD/DVD release Where the Light Is. A Ray Charles tribute album also provided the impetus for <b>jazz</b> singer Roseanna Vitro's......</cite>
|
||||||
|
|
Loading…
Reference in New Issue