Skip to content

Commit

Permalink
More repairs
Browse files Browse the repository at this point in the history
  • Loading branch information
bleroy committed Nov 30, 2011
1 parent 040a128 commit d882f5b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 88 deletions.
51 changes: 22 additions & 29 deletions Search.cshtml
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>
}
}
}
25 changes: 25 additions & 0 deletions Styles/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ html>body #ContainerDiv {height: auto;}
background:url(Images/background_module.gif) no-repeat bottom right;
}

#SidebarDiv h2 {
margin-top: 6px;
}

#SidebarDiv div {
margin-bottom: 19px;
}

/* Contains the contents of a Page */
#MainDiv {
padding:12px 10px 10px 22px;
Expand Down Expand Up @@ -1089,6 +1097,23 @@ img.thumb {
list-style: none;
}

.searchPagination {
margin-top: 20px;
}

.searchPagination li {
list-style: none;
display: inline;
}

.searchButton {
border: none;
background: transparent;
font-size: 1.4em;
color: #006699;
cursor: pointer;
}

/* Search page end */

#siteInfo {
Expand Down
63 changes: 9 additions & 54 deletions _AppStart.cshtml
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);
}
15 changes: 10 additions & 5 deletions _SiteLayout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<!DOCTYPE html>
@{
var isDoc = Request.FilePath.IndexOf("/Documentation/") != -1;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -37,17 +40,19 @@
</header>
<div id="ContainerDiv">
<div id="SidebarDiv">
<div id="SidebarHeaderDiv">
</div>
<div id="SidebarContentDiv">
<form action="Search.cshtml" method="GET">
<input class="txtsearchbox" type="text" name="q"/><big><a href="#" id="search">&raquo;</a></big><br/>
<h2>Search</h2>
<form action="@Href("Search.cshtml")" method="GET">
<input class="txtsearchbox" type="text" name="q" value="@Request.QueryString["q"]"/><button type="submit" class="searchButton" title="Search">&raquo;</button>
</form>
</div>
@if (isDoc) {
<h2>Table of Contents</h2>
<nav class="TocContainer"><ol></ol></nav>
<div id="SidebarFooterDiv">
<a href="@Page.EditUrl">Edit this page</a>
</div>
}
</div>
<article id="MainDiv">
<div id="MainHeaderDiv">
Expand Down

0 comments on commit d882f5b

Please sign in to comment.