Browse Source

Added Cdn generation to SubRouteUrl.

Added Cdn bundle extension to the rest of the areas.
Added Cdn for Logo images.
Added Logo constants for file paths.
pull/40/head
Teknikode 6 years ago
parent
commit
2d30e33949
  1. 5
      Teknik/Areas/Blog/BlogAreaRegistration.cs
  2. 3
      Teknik/Areas/Contact/ContactAreaRegistration.cs
  3. 3
      Teknik/Areas/Help/HelpAreaRegistration.cs
  4. 16
      Teknik/Areas/Home/Views/Home/Index.cshtml
  5. 9
      Teknik/Areas/Paste/PasteAreaRegistration.cs
  6. 5
      Teknik/Areas/Podcast/PodcastAreaRegistration.cs
  7. 3
      Teknik/Areas/Shortener/ShortenerAreaRegistration.cs
  8. 3
      Teknik/Areas/Transparency/TransparencyAreaRegistration.cs
  9. 7
      Teknik/Areas/User/UserAreaRegistration.cs
  10. 3
      Teknik/Areas/Vault/VaultAreaRegistration.cs
  11. 5
      Teknik/Controllers/DefaultController.cs
  12. 2
      Teknik/Helpers/Constants.cs
  13. 33
      Teknik/Helpers/UrlExtensions.cs
  14. 3
      Teknik/Views/Shared/_Navbar.cshtml

5
Teknik/Areas/Blog/BlogAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Blog
{
@ -60,12 +61,12 @@ namespace Teknik.Areas.Blog @@ -60,12 +61,12 @@ namespace Teknik.Areas.Blog
);
// Register Script Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/blog").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/blog", config.CdnHost).Include(
"~/Scripts/bootbox/bootbox.min.js",
"~/Scripts/MarkdownDeepLib.min.js",
"~/Areas/Blog/Scripts/Blog.js"));
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/blog").Include(
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/blog", config.CdnHost).Include(
"~/Content/mdd_styles.css",
"~/Areas/Blog/Content/Blog.css"));
}

3
Teknik/Areas/Contact/ContactAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Contact
{
@ -36,7 +37,7 @@ namespace Teknik.Areas.Contact @@ -36,7 +37,7 @@ namespace Teknik.Areas.Contact
);
// Register Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/contact").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/contact", config.CdnHost).Include(
"~/Areas/Contact/Scripts/Contact.js"));
}
}

3
Teknik/Areas/Help/HelpAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Help
{
@ -108,7 +109,7 @@ namespace Teknik.Areas.Help @@ -108,7 +109,7 @@ namespace Teknik.Areas.Help
);
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/help").Include(
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/help", config.CdnHost).Include(
"~/Areas/Help/Content/Help.css"));
}
}

16
Teknik/Areas/Home/Views/Home/Index.cshtml

@ -2,6 +2,20 @@ @@ -2,6 +2,20 @@
@using Teknik.Areas.Blog.Models
@using Teknik.Areas.Podcast.Models
@using Teknik.Helpers
@{
string logoPath = "/Images/logo-blue.svg";
// If we are using a CDN, let's replace it
if (Model.Config.UseCdn)
{
if (!string.IsNullOrEmpty(Model.Config.CdnHost))
{
logoPath = Model.Config.CdnHost.TrimEnd('/') + logoPath;
}
}
}
@Styles.Render("~/Content/home")
@Scripts.Render("~/bundles/home")
@ -9,7 +23,7 @@ @@ -9,7 +23,7 @@
<div class="container">
<div class="row">
<center>
<img src="/Images/logo-blue.svg" class="img-responsive" alt="Teknik">
<img src="@logoPath" class="img-responsive" alt="Teknik">
</center>
</div>
<br />

9
Teknik/Areas/Paste/PasteAreaRegistration.cs

@ -3,6 +3,7 @@ using System.Web.Mvc; @@ -3,6 +3,7 @@ using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Controllers;
using Teknik.Helpers;
namespace Teknik.Areas.Paste
{
@ -77,15 +78,15 @@ namespace Teknik.Areas.Paste @@ -77,15 +78,15 @@ namespace Teknik.Areas.Paste
);
// Register Script Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/paste").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/paste", config.CdnHost).Include(
"~/Scripts/Highlight/highlight.pack.js",
"~/Areas/Paste/Scripts/Paste.js"));
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/syntaxWorker").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/syntaxWorker", config.CdnHost).Include(
"~/Areas/Paste/Scripts/SyntaxWorker.js"));
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/highlight").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/highlight", config.CdnHost).Include(
"~/Scripts/Highlight/highlight.pack.js"));
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/paste").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/Content/paste", config.CdnHost).Include(
"~/Content/Highlight/github-gist.css",
"~/Areas/Paste/Content/Paste.css"));
}

5
Teknik/Areas/Podcast/PodcastAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Podcast
{
@ -52,12 +53,12 @@ namespace Teknik.Areas.Podcast @@ -52,12 +53,12 @@ namespace Teknik.Areas.Podcast
);
// Register Script Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/podcast").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/podcast", config.CdnHost).Include(
"~/Scripts/bootbox/bootbox.min.js",
"~/Scripts/jquery.blockUI.js",
"~/Areas/Podcast/Scripts/Podcast.js"));
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/podcast").Include(
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/podcast", config.CdnHost).Include(
"~/Areas/Podcast/Content/Podcast.css"));
}
}

3
Teknik/Areas/Shortener/ShortenerAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Shortener
{
@ -44,7 +45,7 @@ namespace Teknik.Areas.Shortener @@ -44,7 +45,7 @@ namespace Teknik.Areas.Shortener
);
// Register Script Bundles
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/shortener").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/shortener", config.CdnHost).Include(
"~/Areas/Shortener/Scripts/Shortener.js"));
}
}

3
Teknik/Areas/Transparency/TransparencyAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Transparency
{
@ -28,7 +29,7 @@ namespace Teknik.Areas.Transparency @@ -28,7 +29,7 @@ namespace Teknik.Areas.Transparency
);
// Register Script Bundle
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/transparency").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/transparency", config.CdnHost).Include(
"~/Areas/Transparency/Scripts/Transparency.js"));
}
}

7
Teknik/Areas/User/UserAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Users
{
@ -108,18 +109,18 @@ namespace Teknik.Areas.Users @@ -108,18 +109,18 @@ namespace Teknik.Areas.Users
);
// Register Script Bundle
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/user").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/user", config.CdnHost).Include(
"~/Scripts/bootbox/bootbox.min.js",
"~/Scripts/jquery.blockUI.js",
"~/Scripts/bootstrap-switch.js",
"~/Areas/User/Scripts/User.js"));
// Register Script Bundle
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/checkAuthCode").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/checkAuthCode", config.CdnHost).Include(
"~/Areas/User/Scripts/CheckAuthCode.js"));
// Register Style Bundles
BundleTable.Bundles.Add(new StyleBundle("~/Content/user").Include(
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/user", config.CdnHost).Include(
"~/Content/bootstrap-switch/bootstrap3/bootstrap-switch.css"));
}
}

3
Teknik/Areas/Vault/VaultAreaRegistration.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Helpers;
namespace Teknik.Areas.Vault
{
@ -28,7 +29,7 @@ namespace Teknik.Areas.Vault @@ -28,7 +29,7 @@ namespace Teknik.Areas.Vault
);
// Register Script Bundle
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/vault").Include(
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/vault", config.CdnHost).Include(
"~/Areas/Vault/Scripts/Vault.js"));
}
}

5
Teknik/Controllers/DefaultController.cs

@ -10,6 +10,7 @@ using Teknik.Configuration; @@ -10,6 +10,7 @@ using Teknik.Configuration;
using Piwik.Tracker;
using Teknik.Filters;
using Teknik.Helpers;
namespace Teknik.Controllers
{
@ -51,7 +52,7 @@ namespace Teknik.Controllers @@ -51,7 +52,7 @@ namespace Teknik.Controllers
public ActionResult Favicon()
{
// Get favicon
string imageFile = Server.MapPath("~/Images/favicon.ico");
string imageFile = Server.MapPath(Constants.FAVICON_PATH);
return File(imageFile, "image/x-icon");
}
@ -61,7 +62,7 @@ namespace Teknik.Controllers @@ -61,7 +62,7 @@ namespace Teknik.Controllers
public ActionResult Logo()
{
// Get favicon
string imageFile = Server.MapPath("~/Images/logo-black.svg");
string imageFile = Server.MapPath(Constants.LOGO_PATH);
return File(imageFile, "image/svg+xml");
}
}

2
Teknik/Helpers/Constants.cs

@ -11,6 +11,8 @@ namespace Teknik.Helpers @@ -11,6 +11,8 @@ namespace Teknik.Helpers
public const string SERVERUSER = "Server Admin";
public const string AUTHCOOKIE = "TeknikAuth";
public const string TRUSTEDDEVICECOOKIE = "TeknikTrustedDevice";
public const string LOGO_PATH = "~/Images/logo-black.svg";
public const string FAVICON_PATH = "~/Images/favicon.ico";
// Paste Constants
public static Dictionary<string, string> HIGHLIGHTFORMATS = new Dictionary<string, string>()

33
Teknik/Helpers/UrlExtensions.cs

@ -7,6 +7,7 @@ using System.Web; @@ -7,6 +7,7 @@ using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.UI;
using Teknik.Configuration;
namespace Teknik
{
@ -14,7 +15,17 @@ namespace Teknik @@ -14,7 +15,17 @@ namespace Teknik
{
public static string SubRouteUrl(this UrlHelper url, string sub, string routeName)
{
return url.SubRouteUrl(sub, routeName, null);
return url.SubRouteUrl(sub, routeName, null, false);
}
public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, bool useCdn)
{
return url.SubRouteUrl(sub, routeName, null, useCdn);
}
public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues)
{
return url.SubRouteUrl(sub, routeName, routeValues, false);
}
/// <summary>
@ -25,7 +36,7 @@ namespace Teknik @@ -25,7 +36,7 @@ namespace Teknik
/// <param name="routeName"></param>
/// <param name="routeValues"></param>
/// <returns></returns>
public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues)
public static string SubRouteUrl(this UrlHelper url, string sub, string routeName, object routeValues, bool useCdn)
{
string host = url.RequestContext.HttpContext.Request.Url.Authority;
@ -71,7 +82,22 @@ namespace Teknik @@ -71,7 +82,22 @@ namespace Teknik
}
string absoluteAction = string.Format("{0}://{1}{2}", url.RequestContext.HttpContext.Request.Url.Scheme, domain, rightUrl);
string fullHost = string.Format("{0}://{1}", url.RequestContext.HttpContext.Request.Url.Scheme, domain);
if (useCdn)
{
// If we are using a CDN, let's replace it
Config config = Config.Load();
if (config.UseCdn)
{
if (!string.IsNullOrEmpty(config.CdnHost))
{
fullHost = config.CdnHost.TrimEnd('/');
}
}
}
string absoluteAction = string.Format("{0}{1}", fullHost, rightUrl);
if (!string.IsNullOrEmpty(subParam))
{
@ -80,6 +106,7 @@ namespace Teknik @@ -80,6 +106,7 @@ namespace Teknik
return absoluteAction;
}
public static string GetUrlParameters(this string url)
{
Uri uri = new Uri(url);

3
Teknik/Views/Shared/_Navbar.cshtml

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
@model Teknik.ViewModels.ViewModelBase
@Html.Partial("../../Areas/User/Views/User/_LoginModalPartial", Model)
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
@ -9,7 +10,7 @@ @@ -9,7 +10,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="@Url.SubRouteUrl("www", "Home.Index")"><img src="@Url.SubRouteUrl("www", "Default.Logo")" height="20" alt="Teknik"></a>
<a class="navbar-brand" href="@Url.SubRouteUrl("www", "Home.Index")"><img src="@Url.SubRouteUrl("www", "Default.Logo", true)" height="20" alt="Teknik"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">

Loading…
Cancel
Save