forked from OrchardCMS/OrchardDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
@using System.Configuration | ||
@using System.Xml.Linq | ||
@using App_Code | ||
@{ | ||
const int pageSize = 10; | ||
XNamespace web = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web"; | ||
var appid = ConfigurationManager.AppSettings["bingAppId"]; | ||
var pageNumber = int.Parse(Request.QueryString["p"] ?? "0"); | ||
var q = Request.QueryString["q"] ?? ""; | ||
var q = Request.QueryString["q"]; | ||
var page = int.Parse(Request.QueryString["p"] ?? "1"); | ||
Page.Title = "Orchard Documentation - Search - " + q; | ||
var requestString = "http://api.bing.net/xml.aspx?" | ||
+ "AppId=" + appid | ||
+ "&Query=" + Html.Encode(q) + "%20site:docs.orchardproject.net" | ||
+ "&Sources=Web" | ||
+ "&Version=2.0" | ||
+ "&Market=en-us" | ||
+ "&Adult=Moderate" | ||
+ "&Options=EnableHighlighting" | ||
+ "&Web.Count=" + pageSize | ||
+ "&Web.Offset=" + (pageNumber*pageSize) | ||
+ "&Web.Options=DisableHostCollapsing+DisableQueryAlterations"; | ||
var request = (HttpWebRequest) WebRequest.Create(requestString); | ||
var response = request.GetResponse().GetResponseStream(); | ||
var webElement = XElement.Load(response).Element(web + "Web"); | ||
|
||
if (webElement != null) { | ||
var resultSet = webElement.Element(web + "Results"); | ||
if (resultSet != null) { | ||
var resultSet = SearchHelpers.Query(HttpContext.Current, q, page); | ||
var documents = resultSet.Documents; | ||
if (resultSet.TotalCount == 0) { | ||
@:No results found. | ||
} | ||
else { | ||
<div class="searchResultCount">@resultSet.TotalCount @(resultSet.TotalCount > 1 ? "documents" : "document") found.</div> | ||
<ul id="SearchResultsDiv"> | ||
@foreach (var result in resultSet.Elements(web + "WebResult")) { | ||
@foreach (var doc in documents) { | ||
<li> | ||
<article> | ||
<header> | ||
<h2><a href="@result.Element(web + "Url").Value">@result.Element(web + "Title").Value</a></h2> | ||
<h2><a href="@Href(doc.Url)">@doc.Title</a></h2> | ||
</header> | ||
<p>@result.Element(web + "Description").Value</p> | ||
<blockquote>@Html.Raw(doc.Summary)</blockquote> | ||
<div><a href="@Href(doc.Url)">Read more...</a></div> | ||
</article> | ||
</li> | ||
} | ||
</ul> | ||
} | ||
if (resultSet.TotalCount > SearchHelpers.PageSize) { | ||
int pages = (resultSet.TotalCount / SearchHelpers.PageSize) + 1; | ||
<ul class="searchPagination"> | ||
@for (var p = 1; p <= pages; p++) { | ||
<li>@if (p == page) {<text>@p</text>} else {<a href="?q=@(q)&p=@p">@p</a>}</li> | ||
} | ||
</ul> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,12 @@ | ||
@using MarkdownWebPages | ||
@using System.Text.RegularExpressions | ||
|
||
@functions { | ||
string ProcessIncludes(string content, MarkdownWebPage page) { | ||
return Regex.Replace(content, @"^@include\((?<include>~/.*?)\)", match => MarkdownWebPage.RenderFile(match.Groups["include"].Value, page), RegexOptions.Multiline); | ||
} | ||
|
||
string ProcessComments(string content, MarkdownWebPage page) { | ||
return Regex.Replace(content, @"^//(.*?)$", match => String.Empty, RegexOptions.Multiline); | ||
} | ||
|
||
// First Header | Second Header | ||
// ------------- | ------------- | ||
// Content Cell | Content Cell | ||
// Content Cell | Content Cell | ||
string ProcessTables(string content, MarkdownWebPage page) { | ||
return Regex.Replace(content, | ||
@"\r\n(\s*(.*?)\s+\|)+\s+(.*?)\s*" + | ||
@"\r\n(\s*(-+?)\s+\|)+\s+(-+?)\s*" + | ||
@"\r\n((\s*(.*?)\s+\|)+\s+(.*?)\s*\r\n)+", | ||
match => { | ||
var writer = new StringWriter(); | ||
writer.WriteLine("<table><thead><tr>"); | ||
foreach (Capture header in match.Groups[1].Captures) { | ||
writer.WriteLine(" <td>" + header.Value.Substring(0, header.Length - 1).Trim() + "</td>"); | ||
} | ||
writer.WriteLine(" <td>" + match.Groups[3].Value.Trim() + "</td>"); | ||
writer.WriteLine("</tr></thead><tbody>"); | ||
var rows = match.Groups[7].Captures; | ||
var cells = match.Groups[9].Captures; | ||
var colCount = cells.Count/rows.Count; | ||
var i = 0; | ||
foreach (Capture row in rows) { | ||
writer.WriteLine(" <tr>"); | ||
for (var j = 0; j < colCount; j++ ) { | ||
writer.WriteLine(" <td>" + cells[colCount * i + j] + "</td>"); | ||
} | ||
writer.WriteLine(" <td>" + match.Groups[10].Captures[i++] + "</td>"); | ||
writer.WriteLine(" </tr>"); | ||
} | ||
writer.WriteLine("</tbody></table>"); | ||
return writer.ToString(); | ||
} | ||
, RegexOptions.Multiline); | ||
} | ||
} | ||
|
||
@using App_Code | ||
@using MarkdownWebPages | ||
@{ | ||
MarkdownWebPage.TransformUrls = true; | ||
MarkdownWebPage.AlterBehaviors(b => b.Clear()); | ||
MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessIncludes)); | ||
MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessComments)); | ||
MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessTables)); | ||
} | ||
|
||
|
||
MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessIncludes)); | ||
MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessComments)); | ||
MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessTables)); | ||
|
||
// Index the whole documentation on app start | ||
SearchHelpers.BuildIndex(HttpContext.Current); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters